1515 pgschema-plan-single :
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,63 +45,50 @@ jobs:
2745 - name : Install pgschema
2846 run : go install github.com/pgschema/pgschema@latest
2947
30- - name : Run pgschema plan
31- id : plan
48+ - name : Setup baseline schema from main branch
3249 run : |
33- # Debug: Print environment info
34- echo "::group::Environment Info"
35- echo "Current directory: $(pwd)"
36- echo "Schema file path: ${{ github.workspace }}/singlefile/schema.sql"
37- echo "Checking if schema file exists:"
38- ls -la "${{ github.workspace }}/singlefile/schema.sql" || echo "Schema file not found!"
39- echo "Go version: $(go version)"
40- echo "pgschema location: $(which pgschema)"
41- echo "::endgroup::"
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+ }
4256
43- # Debug: Test pgschema is installed
44- echo "::group::Testing pgschema installation"
45- pgschema --version || echo "Failed to run pgschema --version"
46- echo "::endgroup::"
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
4762
48- # Run pgschema plan with timeout and capture output
49- echo "::group::Running pgschema plan"
50- set +e # Don't exit on error
51- PLAN_OUTPUT=$(timeout 60s pgschema plan \
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+
75+ - name : Run pgschema plan
76+ id : plan
77+ run : |
78+ # Run pgschema plan
79+ PLAN_OUTPUT=$(pgschema plan \
5280 --debug \
53- --host "${{ secrets.DB_HOST }}" \
54- --port "${{ secrets.DB_PORT }}" \
55- --db "${{ secrets.DB_NAME }}" \
56- --user "${{ secrets.DB_USER }}" \
81+ --host localhost \
82+ --port 5432 \
83+ --db testdb \
84+ --user postgres \
5785 --file "${{ github.workspace }}/singlefile/schema.sql" \
5886 --format human 2>&1)
59- EXIT_CODE=$?
60- set -e # Re-enable exit on error
61- echo "::endgroup::"
62-
63- # Check exit code
64- if [ $EXIT_CODE -eq 124 ]; then
65- echo "::error::pgschema plan timed out after 60 seconds"
66- PLAN_OUTPUT="Error: pgschema plan timed out after 60 seconds. This might indicate a connection issue to the database."
67- elif [ $EXIT_CODE -ne 0 ]; then
68- echo "::error::pgschema plan failed with exit code $EXIT_CODE"
69- fi
70-
71- # Debug: Show raw output
72- echo "::group::Raw pgschema output"
73- echo "$PLAN_OUTPUT"
74- echo "::endgroup::"
75-
76- # Escape special characters for GitHub Actions
77- PLAN_OUTPUT="${PLAN_OUTPUT//'%'/'%25'}"
78- PLAN_OUTPUT="${PLAN_OUTPUT//$'\n'/'%0A'}"
79- PLAN_OUTPUT="${PLAN_OUTPUT//$'\r'/'%0D'}"
8087
8188 # Set output
8289 echo "plan<<EOF" >> $GITHUB_OUTPUT
8390 echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
8491 echo "EOF" >> $GITHUB_OUTPUT
85- env :
86- PGPASSWORD : ${{ secrets.DB_PASSWORD }}
8792
8893 - name : Comment PR
8994 uses : actions/github-script@v7
0 commit comments