Skip to content

Commit 08927ea

Browse files
committed
chore: update github actions
1 parent 8badacb commit 08927ea

File tree

4 files changed

+104
-17
lines changed

4 files changed

+104
-17
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ jobs:
4848
- name: Install pgschema
4949
run: go install github.com/pgschema/pgschema@latest
5050

51+
- name: Download plan.json artifact
52+
uses: actions/download-artifact@v4
53+
with:
54+
name: pgschema-plan-${{ github.event.pull_request.number }}
55+
path: .
56+
57+
- name: Validate plan.json
58+
run: |
59+
if [ ! -f "plan.json" ]; then
60+
echo "❌ Error: plan.json not found. Make sure the plan workflow completed successfully."
61+
exit 1
62+
fi
63+
64+
echo "✅ plan.json found and ready for apply"
65+
echo "Plan file size: $(stat -f%z plan.json 2>/dev/null || stat -c%s plan.json) bytes"
66+
5167
- name: Load baseline schema
5268
run: |
5369
echo "::group::Loading baseline schema to emulate remote database"
@@ -57,21 +73,20 @@ jobs:
5773
- name: Run pgschema apply
5874
id: apply
5975
run: |
60-
echo "::group::Applying schema changes"
61-
echo "Running pgschema apply with detailed logging..."
76+
echo "::group::Applying schema changes using plan.json"
77+
echo "Running pgschema apply with pre-generated plan..."
6278
6379
# Enable detailed error reporting
6480
set -x # Show commands as they execute
6581
66-
# Run pgschema apply with auto-approve
82+
# Run pgschema apply using the plan.json file
6783
APPLY_OUTPUT=$(pgschema apply \
68-
--auto-approve \
6984
--debug \
7085
--host localhost \
7186
--port 5432 \
7287
--db testdb \
7388
--user postgres \
74-
--file "${{ github.workspace }}/multifile/main.sql" \
89+
--plan plan.json \
7590
--lock-timeout "30s" \
7691
--application-name "pgschema-github-action-apply" \
7792
2>&1)
@@ -128,6 +143,8 @@ jobs:
128143
if (wasSuccessful) {
129144
commentBody = `## ✅ Schema Changes Applied Successfully!
130145
146+
📋 **Applied using plan:** \`pgschema-plan-${{ github.event.pull_request.number }}\`
147+
131148
<details>
132149
<summary>📋 Applied Changes</summary>
133150
@@ -144,7 +161,14 @@ jobs:
144161
} else {
145162
commentBody = `## ❌ Schema Migration Failed!
146163
147-
The multi-file schema migration failed after merging this PR. Please review the error details below:
164+
The multi-file schema migration failed after merging this PR using plan \`pgschema-plan-${{ github.event.pull_request.number }}\`.
165+
166+
This could indicate:
167+
- Database schema changed between plan and apply (fingerprint mismatch)
168+
- Invalid plan.json file
169+
- Database connectivity issues
170+
171+
Please review the error details below:
148172
149173
<details>
150174
<summary>🔍 Error Details</summary>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,39 @@ jobs:
5959
# Enable detailed error reporting
6060
set -x # Show commands as they execute
6161
62-
# Run pgschema plan
62+
# Run pgschema plan and generate both text and JSON output
6363
PLAN_OUTPUT=$(pgschema plan \
6464
--debug \
6565
--host localhost \
6666
--port 5432 \
6767
--db testdb \
6868
--user postgres \
6969
--file "${{ github.workspace }}/multifile/main.sql" \
70+
--output-json plan.json \
7071
2>&1)
7172
7273
set +x # Disable command tracing
7374
74-
# Set output
75+
# Verify plan.json was created
76+
if [ ! -f "plan.json" ]; then
77+
echo "❌ Error: plan.json was not generated"
78+
exit 1
79+
fi
80+
81+
echo "✅ plan.json generated successfully"
82+
83+
# Set output for PR comment
7584
echo "plan<<EOF" >> $GITHUB_OUTPUT
7685
echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
7786
echo "EOF" >> $GITHUB_OUTPUT
7887
88+
- name: Upload plan.json artifact
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: pgschema-plan-${{ github.event.pull_request.number }}
92+
path: plan.json
93+
retention-days: 30
94+
7995
- name: Comment PR
8096
uses: actions/github-script@v7
8197
with:
@@ -87,6 +103,10 @@ jobs:
87103
88104
const body = `## pgschema Plan Output
89105
106+
📋 **Plan artifact created:** \`pgschema-plan-${{ github.event.pull_request.number }}\`
107+
108+
This plan will be used automatically when the PR is merged.
109+
90110
<details>
91111
<summary>Click to expand plan details</summary>
92112

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ jobs:
4848
- name: Install pgschema
4949
run: go install github.com/pgschema/pgschema@latest
5050

51+
- name: Download plan.json artifact
52+
uses: actions/download-artifact@v4
53+
with:
54+
name: pgschema-singlefile-plan-${{ github.event.pull_request.number }}
55+
path: .
56+
57+
- name: Validate plan.json
58+
run: |
59+
if [ ! -f "plan.json" ]; then
60+
echo "❌ Error: plan.json not found. Make sure the plan workflow completed successfully."
61+
exit 1
62+
fi
63+
64+
echo "✅ plan.json found and ready for apply"
65+
echo "Plan file size: $(stat -f%z plan.json 2>/dev/null || stat -c%s plan.json) bytes"
66+
5167
- name: Load baseline schema
5268
run: |
5369
echo "::group::Loading baseline schema to emulate remote database"
@@ -57,21 +73,20 @@ jobs:
5773
- name: Run pgschema apply
5874
id: apply
5975
run: |
60-
echo "::group::Applying schema changes"
61-
echo "Running pgschema apply with detailed logging..."
76+
echo "::group::Applying schema changes using plan.json"
77+
echo "Running pgschema apply with pre-generated plan..."
6278
6379
# Enable detailed error reporting
6480
set -x # Show commands as they execute
6581
66-
# Run pgschema apply with auto-approve
82+
# Run pgschema apply using the plan.json file
6783
APPLY_OUTPUT=$(pgschema apply \
68-
--auto-approve \
6984
--debug \
7085
--host localhost \
7186
--port 5432 \
7287
--db testdb \
7388
--user postgres \
74-
--file "${{ github.workspace }}/singlefile/schema.sql" \
89+
--plan plan.json \
7590
--lock-timeout "30s" \
7691
--application-name "pgschema-github-action-apply" \
7792
2>&1)
@@ -93,7 +108,6 @@ jobs:
93108
94109
echo "exit_code=$APPLY_EXIT_CODE" >> $GITHUB_OUTPUT
95110
96-
97111
# Exit with the same code as pgschema
98112
exit $APPLY_EXIT_CODE
99113
@@ -129,6 +143,8 @@ jobs:
129143
if (wasSuccessful) {
130144
commentBody = `## ✅ Schema Changes Applied Successfully!
131145
146+
📋 **Applied using plan:** \`pgschema-singlefile-plan-${{ github.event.pull_request.number }}\`
147+
132148
<details>
133149
<summary>📋 Applied Changes</summary>
134150
@@ -145,7 +161,14 @@ jobs:
145161
} else {
146162
commentBody = `## ❌ Schema Migration Failed!
147163
148-
The single-file schema migration failed after merging this PR. Please review the error details below:
164+
The single-file schema migration failed after merging this PR using plan \`pgschema-singlefile-plan-${{ github.event.pull_request.number }}\`.
165+
166+
This could indicate:
167+
- Database schema changed between plan and apply (fingerprint mismatch)
168+
- Invalid plan.json file
169+
- Database connectivity issues
170+
171+
Please review the error details below:
149172
150173
<details>
151174
<summary>🔍 Error Details</summary>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,39 @@ jobs:
5959
# Enable detailed error reporting
6060
set -x # Show commands as they execute
6161
62-
# Run pgschema plan
62+
# Run pgschema plan and generate both text and JSON output
6363
PLAN_OUTPUT=$(pgschema plan \
6464
--debug \
6565
--host localhost \
6666
--port 5432 \
6767
--db testdb \
6868
--user postgres \
6969
--file "${{ github.workspace }}/singlefile/schema.sql" \
70+
--output-json plan.json \
7071
2>&1)
7172
7273
set +x # Disable command tracing
7374
74-
# Set output
75+
# Verify plan.json was created
76+
if [ ! -f "plan.json" ]; then
77+
echo "❌ Error: plan.json was not generated"
78+
exit 1
79+
fi
80+
81+
echo "✅ plan.json generated successfully"
82+
83+
# Set output for PR comment
7584
echo "plan<<EOF" >> $GITHUB_OUTPUT
7685
echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
7786
echo "EOF" >> $GITHUB_OUTPUT
7887
88+
- name: Upload plan.json artifact
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: pgschema-singlefile-plan-${{ github.event.pull_request.number }}
92+
path: plan.json
93+
retention-days: 30
94+
7995
- name: Comment PR
8096
uses: actions/github-script@v7
8197
with:
@@ -87,6 +103,10 @@ jobs:
87103
88104
const body = `## pgschema Plan Output
89105
106+
📋 **Plan artifact created:** \`pgschema-singlefile-plan-${{ github.event.pull_request.number }}\`
107+
108+
This plan will be used automatically when the PR is merged.
109+
90110
<details>
91111
<summary>Click to expand plan details</summary>
92112

0 commit comments

Comments
 (0)