Skip to content

Commit 13c1c61

Browse files
committed
chore: debug apply
1 parent 6499d74 commit 13c1c61

File tree

4 files changed

+116
-8
lines changed

4 files changed

+116
-8
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ jobs:
5555
id: apply
5656
run: |
5757
echo "::group::Applying schema changes"
58-
58+
echo "Running pgschema apply with detailed logging..."
59+
60+
# Enable detailed error reporting
61+
set -x # Show commands as they execute
62+
5963
# Run pgschema apply with auto-approve
6064
APPLY_OUTPUT=$(pgschema apply \
6165
--auto-approve \
@@ -67,11 +71,14 @@ jobs:
6771
--file "${{ github.workspace }}/multifile/main.sql" \
6872
--lock-timeout "30s" \
6973
--application-name "pgschema-github-action-apply" \
70-
--format human 2>&1)
74+
2>&1)
7175
7276
APPLY_EXIT_CODE=$?
77+
78+
set +x # Disable command tracing
7379
74-
# Output the results
80+
echo "Apply exit code: $APPLY_EXIT_CODE"
81+
echo "Apply output:"
7582
echo "$APPLY_OUTPUT"
7683
7784
echo "::endgroup::"

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,21 @@ jobs:
5454
- name: Run pgschema plan
5555
id: plan
5656
run: |
57+
echo "Running pgschema plan with detailed logging..."
58+
59+
# Enable detailed error reporting
60+
set -x # Show commands as they execute
61+
5762
# Run pgschema plan
5863
PLAN_OUTPUT=$(pgschema plan \
5964
--host localhost \
6065
--port 5432 \
6166
--db testdb \
6267
--user postgres \
6368
--file "${{ github.workspace }}/multifile/main.sql" \
64-
--format human 2>&1)
69+
2>&1)
70+
71+
set +x # Disable command tracing
6572
6673
# Set output
6774
echo "plan<<EOF" >> $GITHUB_OUTPUT

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

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: pgschema Apply - Single 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-single:
1618
runs-on: ubuntu-latest
19+
if: github.event.pull_request.merged == true
1720

1821
env:
1922
PGPASSWORD: postgres
@@ -55,6 +58,10 @@ jobs:
5558
id: apply
5659
run: |
5760
echo "::group::Applying schema changes"
61+
echo "Running pgschema apply with detailed logging..."
62+
63+
# Enable detailed error reporting
64+
set -x # Show commands as they execute
5865
5966
# Run pgschema apply with auto-approve
6067
APPLY_OUTPUT=$(pgschema apply \
@@ -67,11 +74,14 @@ jobs:
6774
--file "${{ github.workspace }}/singlefile/schema.sql" \
6875
--lock-timeout "30s" \
6976
--application-name "pgschema-github-action-apply" \
70-
--format human 2>&1)
77+
2>&1)
7178
7279
APPLY_EXIT_CODE=$?
7380
74-
# Output the results
81+
set +x # Disable command tracing
82+
83+
echo "Apply exit code: $APPLY_EXIT_CODE"
84+
echo "Apply output:"
7585
echo "$APPLY_OUTPUT"
7686
7787
echo "::endgroup::"
@@ -83,6 +93,7 @@ jobs:
8393
8494
echo "exit_code=$APPLY_EXIT_CODE" >> $GITHUB_OUTPUT
8595
96+
8697
# Exit with the same code as pgschema
8798
exit $APPLY_EXIT_CODE
8899
@@ -101,3 +112,79 @@ jobs:
101112
echo "❌ Failed to apply schema changes!"
102113
echo ""
103114
echo "Please check the logs above for details."
115+
116+
- name: Comment on PR with migration results
117+
if: always()
118+
uses: actions/github-script@v7
119+
with:
120+
script: |
121+
// Get the apply output from the previous step
122+
const applyOutput = `${{ steps.apply.outputs.output }}` || 'No output captured';
123+
124+
// Determine if migration was successful based on job outcome
125+
const wasSuccessful = `${{ job.status }}` === 'success';
126+
127+
let commentBody;
128+
129+
if (wasSuccessful) {
130+
commentBody = `## ✅ Schema Changes Applied Successfully!
131+
132+
<details>
133+
<summary>📋 Applied Changes</summary>
134+
135+
\`\`\`
136+
${applyOutput}
137+
\`\`\`
138+
139+
</details>
140+
141+
**Database:** testdb
142+
143+
---
144+
*This comment was automatically generated by the [pgschema](https://www.pgschema.com) Single File Apply workflow.*`;
145+
} else {
146+
commentBody = `## ❌ Schema Migration Failed!
147+
148+
The single-file schema migration failed after merging this PR. Please review the error details below:
149+
150+
<details>
151+
<summary>🔍 Error Details</summary>
152+
153+
\`\`\`
154+
${applyOutput}
155+
\`\`\`
156+
157+
</details>
158+
159+
**Database:** testdb
160+
161+
---
162+
*This comment was automatically generated by the [pgschema](https://www.pgschema.com) Single File Apply workflow.*`;
163+
}
164+
165+
// Try to find existing comment
166+
const { data: comments } = await github.rest.issues.listComments({
167+
...context.repo,
168+
issue_number: context.issue.number,
169+
});
170+
171+
const botComment = comments.find(comment =>
172+
comment.user.type === 'Bot' &&
173+
comment.body.includes('pgschema Single File Apply workflow')
174+
);
175+
176+
if (botComment) {
177+
// Update existing comment
178+
await github.rest.issues.updateComment({
179+
...context.repo,
180+
comment_id: botComment.id,
181+
body: commentBody
182+
});
183+
} else {
184+
// Create new comment
185+
await github.rest.issues.createComment({
186+
...context.repo,
187+
issue_number: context.issue.number,
188+
body: commentBody
189+
});
190+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ jobs:
5454
- name: Run pgschema plan
5555
id: plan
5656
run: |
57+
echo "Running pgschema plan with detailed logging..."
58+
59+
# Enable detailed error reporting
60+
set -x # Show commands as they execute
61+
5762
# Run pgschema plan
5863
PLAN_OUTPUT=$(pgschema plan \
5964
--debug \
@@ -62,7 +67,9 @@ jobs:
6267
--db testdb \
6368
--user postgres \
6469
--file "${{ github.workspace }}/singlefile/schema.sql" \
65-
--format human 2>&1)
70+
2>&1)
71+
72+
set +x # Disable command tracing
6673
6774
# Set output
6875
echo "plan<<EOF" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)