44 pull_request :
55 types : [opened, synchronize, reopened]
66 paths :
7- - ' singlefile/**'
8- - ' .github/workflows/pgschema-plan-single.yml'
7+ - " singlefile/**"
8+ - " .github/workflows/pgschema-plan-single.yml"
99
1010permissions :
1111 contents : read
@@ -14,10 +14,10 @@ permissions:
1414jobs :
1515 pgschema-plan-single :
1616 runs-on : ubuntu-latest
17-
17+
1818 env :
1919 PGPASSWORD : postgres
20-
20+
2121 services :
2222 postgres :
2323 image : postgres:17
@@ -32,46 +32,19 @@ jobs:
3232 --health-retries 5
3333 ports :
3434 - 5432:5432
35-
35+
3636 steps :
3737 - name : Checkout code
3838 uses : actions/checkout@v4
39-
39+
4040 - name : Setup Go
4141 uses : actions/setup-go@v5
4242 with :
43- go-version : ' stable'
44-
43+ go-version : " stable"
44+
4545 - name : Install pgschema
4646 run : go install github.com/pgschema/pgschema@latest
47-
48- - name : Setup baseline schema from main branch
49- run : |
50- # Checkout main branch to get baseline schema
51- git fetch origin main
52- git checkout origin/main -- singlefile/schema.sql || {
53- echo "::error::Could not checkout schema.sql from main branch"
54- exit 1
55- }
56-
57- # Copy main branch schema to temporary location
58- cp singlefile/schema.sql /tmp/main_schema.sql
59-
60- # Restore current branch schema
61- git checkout HEAD -- singlefile/schema.sql
62-
63- # Apply main branch schema to establish baseline database state
64- echo "::group::Applying baseline schema"
65- pgschema apply \
66- --auto-approve \
67- --host localhost \
68- --port 5432 \
69- --db testdb \
70- --user postgres \
71- --file /tmp/main_schema.sql \
72- || echo "::warning::Failed to apply baseline schema"
73- echo "::endgroup::"
74-
47+
7548 - name : Run pgschema plan
7649 id : plan
7750 run : |
@@ -84,47 +57,47 @@ jobs:
8457 --user postgres \
8558 --file "${{ github.workspace }}/singlefile/schema.sql" \
8659 --format human 2>&1)
87-
60+
8861 # Set output
8962 echo "plan<<EOF" >> $GITHUB_OUTPUT
9063 echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
9164 echo "EOF" >> $GITHUB_OUTPUT
92-
65+
9366 - name : Comment PR
9467 uses : actions/github-script@v7
9568 with :
9669 github-token : ${{secrets.GITHUB_TOKEN}}
9770 script : |
9871 const planOutput = `${{ steps.plan.outputs.plan }}`;
99-
72+
10073 // Decode the escaped output
10174 const decodedOutput = decodeURIComponent(planOutput);
102-
75+
10376 const body = `## pgschema Plan Output
104-
77+
10578 <details>
10679 <summary>Click to expand plan details</summary>
107-
80+
10881 \`\`\`
10982 ${decodedOutput}
11083 \`\`\`
111-
84+
11285 </details>
113-
86+
11487 ---
11588 *This comment was automatically generated by the pgschema Single File Plan workflow.*`;
116-
89+
11790 // Try to find existing comment
11891 const { data: comments } = await github.rest.issues.listComments({
11992 ...context.repo,
12093 issue_number: context.issue.number,
12194 });
122-
95+
12396 const botComment = comments.find(comment =>
12497 comment.user.type === 'Bot' &&
12598 comment.body.includes('pgschema Plan Output')
12699 );
127-
100+
128101 if (botComment) {
129102 // Update existing comment
130103 await github.rest.issues.updateComment({
@@ -139,4 +112,4 @@ jobs:
139112 issue_number: context.issue.number,
140113 body: body
141114 });
142- }
115+ }
0 commit comments