1515 pgschema-plan-multi :
1616 runs-on : ubuntu-latest
1717
18+ env :
19+ PGPASSWORD : postgres
20+
21+ services :
22+ postgres :
23+ image : postgres:17
24+ env :
25+ POSTGRES_PASSWORD : postgres
26+ POSTGRES_USER : postgres
27+ POSTGRES_DB : testdb
28+ options : >-
29+ --health-cmd pg_isready
30+ --health-interval 10s
31+ --health-timeout 5s
32+ --health-retries 5
33+ ports :
34+ - 5432:5432
35+
1836 steps :
1937 - name : Checkout code
2038 uses : actions/checkout@v4
@@ -27,29 +45,49 @@ jobs:
2745 - name : Install pgschema
2846 run : go install github.com/pgschema/pgschema@latest
2947
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 -- multifile/ || {
53+ echo "::error::Could not checkout multifile/ from main branch"
54+ exit 1
55+ }
56+
57+ # Copy main branch schema to temporary location
58+ cp -r multifile /tmp/main_multifile
59+
60+ # Restore current branch schema
61+ git checkout HEAD -- multifile/
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_multifile/main.sql \
72+ || echo "::warning::Failed to apply baseline schema"
73+ echo "::endgroup::"
74+
3075 - name : Run pgschema plan
3176 id : plan
3277 run : |
33- # Run pgschema plan with directory of SQL files
78+ # Run pgschema plan
3479 PLAN_OUTPUT=$(pgschema plan \
35- --host "${{ secrets.DB_HOST }}" \
36- --port "${{ secrets.DB_PORT }}" \
37- --db "${{ secrets.DB_NAME }}" \
38- --user "${{ secrets.DB_USER }}" \
80+ --host localhost \
81+ --port 5432 \
82+ --db testdb \
83+ --user postgres \
3984 --file "${{ github.workspace }}/multifile/main.sql" \
4085 --format human 2>&1)
4186
42- # Escape special characters for GitHub Actions
43- PLAN_OUTPUT="${PLAN_OUTPUT//'%'/'%25'}"
44- PLAN_OUTPUT="${PLAN_OUTPUT//$'\n'/'%0A'}"
45- PLAN_OUTPUT="${PLAN_OUTPUT//$'\r'/'%0D'}"
46-
4787 # Set output
4888 echo "plan<<EOF" >> $GITHUB_OUTPUT
4989 echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
5090 echo "EOF" >> $GITHUB_OUTPUT
51- env :
52- PGPASSWORD : ${{ secrets.DB_PASSWORD }}
5391
5492 - name : Comment PR
5593 uses : actions/github-script@v7
6199 // Decode the escaped output
62100 const decodedOutput = decodeURIComponent(planOutput);
63101
64- const body = `## pgschema Plan Output (Multi File)
102+ const body = `## pgschema Plan Output
65103
66104 <details>
67105 <summary>Click to expand plan details</summary>
83121
84122 const botComment = comments.find(comment =>
85123 comment.user.type === 'Bot' &&
86- comment.body.includes('pgschema Plan Output (Multi File) ')
124+ comment.body.includes('pgschema Plan Output')
87125 );
88126
89127 if (botComment) {
0 commit comments