Skip to content

Commit d99a2ad

Browse files
committed
chore: update multifile github actions file
1 parent 13c1c61 commit d99a2ad

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

.github/workflows/pgschema-multifile-apply.yml

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: pgschema Apply - Multi File
22

33
on:
4-
push:
4+
pull_request:
5+
types: [closed]
56
branches:
67
- main
78
paths:
@@ -10,10 +11,12 @@ on:
1011

1112
permissions:
1213
contents: read
14+
pull-requests: write
1315

1416
jobs:
1517
pgschema-apply-multi:
1618
runs-on: ubuntu-latest
19+
if: github.event.pull_request.merged == true
1720

1821
env:
1922
PGPASSWORD: postgres
@@ -108,3 +111,79 @@ jobs:
108111
echo "❌ Failed to apply schema changes!"
109112
echo ""
110113
echo "Please check the logs above for details."
114+
115+
- name: Comment on PR with migration results
116+
if: always()
117+
uses: actions/github-script@v7
118+
with:
119+
script: |
120+
// Get the apply output from the previous step
121+
const applyOutput = `${{ steps.apply.outputs.output }}` || 'No output captured';
122+
123+
// Determine if migration was successful based on job outcome
124+
const wasSuccessful = `${{ job.status }}` === 'success';
125+
126+
let commentBody;
127+
128+
if (wasSuccessful) {
129+
commentBody = `## ✅ Schema Changes Applied Successfully!
130+
131+
<details>
132+
<summary>📋 Applied Changes</summary>
133+
134+
\`\`\`
135+
${applyOutput}
136+
\`\`\`
137+
138+
</details>
139+
140+
**Database:** testdb
141+
142+
---
143+
*This comment was automatically generated by the [pgschema](https://www.pgschema.com) Multi File Apply workflow.*`;
144+
} else {
145+
commentBody = `## ❌ Schema Migration Failed!
146+
147+
The multi-file schema migration failed after merging this PR. Please review the error details below:
148+
149+
<details>
150+
<summary>🔍 Error Details</summary>
151+
152+
\`\`\`
153+
${applyOutput}
154+
\`\`\`
155+
156+
</details>
157+
158+
**Database:** testdb
159+
160+
---
161+
*This comment was automatically generated by the [pgschema](https://www.pgschema.com) Multi File Apply workflow.*`;
162+
}
163+
164+
// Try to find existing comment
165+
const { data: comments } = await github.rest.issues.listComments({
166+
...context.repo,
167+
issue_number: context.issue.number,
168+
});
169+
170+
const botComment = comments.find(comment =>
171+
comment.user.type === 'Bot' &&
172+
comment.body.includes('pgschema Multi File Apply workflow')
173+
);
174+
175+
if (botComment) {
176+
// Update existing comment
177+
await github.rest.issues.updateComment({
178+
...context.repo,
179+
comment_id: botComment.id,
180+
body: commentBody
181+
});
182+
} else {
183+
// Create new comment
184+
await github.rest.issues.createComment({
185+
...context.repo,
186+
issue_number: context.issue.number,
187+
body: commentBody
188+
});
189+
}

.github/workflows/pgschema-multifile-plan.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
6262
# Run pgschema plan
6363
PLAN_OUTPUT=$(pgschema plan \
64+
--debug \
6465
--host localhost \
6566
--port 5432 \
6667
--db testdb \

0 commit comments

Comments
 (0)