feat: update single file / multi file github actions #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: pgschema Plan - Single File | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| paths: | |
| - 'singlefile/**' | |
| - '.github/workflows/pgschema-plan-single.yml' | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| pgschema-plan-single: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 'stable' | |
| - name: Install pgschema | |
| run: go install github.com/pgschema/pgschema@latest | |
| - name: Run pgschema plan | |
| id: plan | |
| run: | | |
| # Debug: Print environment info | |
| echo "::group::Environment Info" | |
| echo "Current directory: $(pwd)" | |
| echo "Schema file path: ${{ github.workspace }}/singlefile/schema.sql" | |
| echo "Checking if schema file exists:" | |
| ls -la "${{ github.workspace }}/singlefile/schema.sql" || echo "Schema file not found!" | |
| echo "Go version: $(go version)" | |
| echo "pgschema location: $(which pgschema)" | |
| echo "::endgroup::" | |
| # Debug: Test pgschema is installed | |
| echo "::group::Testing pgschema installation" | |
| pgschema --version || echo "Failed to run pgschema --version" | |
| echo "::endgroup::" | |
| # Run pgschema plan with timeout and capture output | |
| echo "::group::Running pgschema plan" | |
| set +e # Don't exit on error | |
| PLAN_OUTPUT=$(timeout 60s pgschema plan \ | |
| --debug \ | |
| --host "${{ secrets.DB_HOST }}" \ | |
| --port "${{ secrets.DB_PORT }}" \ | |
| --db "${{ secrets.DB_NAME }}" \ | |
| --user "${{ secrets.DB_USER }}" \ | |
| --file "${{ github.workspace }}/singlefile/schema.sql" \ | |
| --format human 2>&1) | |
| EXIT_CODE=$? | |
| set -e # Re-enable exit on error | |
| echo "::endgroup::" | |
| # Check exit code | |
| if [ $EXIT_CODE -eq 124 ]; then | |
| echo "::error::pgschema plan timed out after 60 seconds" | |
| PLAN_OUTPUT="Error: pgschema plan timed out after 60 seconds. This might indicate a connection issue to the database." | |
| elif [ $EXIT_CODE -ne 0 ]; then | |
| echo "::error::pgschema plan failed with exit code $EXIT_CODE" | |
| fi | |
| # Debug: Show raw output | |
| echo "::group::Raw pgschema output" | |
| echo "$PLAN_OUTPUT" | |
| echo "::endgroup::" | |
| # Escape special characters for GitHub Actions | |
| PLAN_OUTPUT="${PLAN_OUTPUT//'%'/'%25'}" | |
| PLAN_OUTPUT="${PLAN_OUTPUT//$'\n'/'%0A'}" | |
| PLAN_OUTPUT="${PLAN_OUTPUT//$'\r'/'%0D'}" | |
| # Set output | |
| echo "plan<<EOF" >> $GITHUB_OUTPUT | |
| echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| env: | |
| PGPASSWORD: ${{ secrets.DB_PASSWORD }} | |
| - name: Comment PR | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| const planOutput = `${{ steps.plan.outputs.plan }}`; | |
| // Decode the escaped output | |
| const decodedOutput = decodeURIComponent(planOutput); | |
| const body = `## pgschema Plan Output (Single File) | |
| <details> | |
| <summary>Click to expand plan details</summary> | |
| \`\`\` | |
| ${decodedOutput} | |
| \`\`\` | |
| </details> | |
| --- | |
| *This comment was automatically generated by the pgschema Single File Plan workflow.*`; | |
| // Try to find existing comment | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| ...context.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('pgschema Plan Output (Single File)') | |
| ); | |
| if (botComment) { | |
| // Update existing comment | |
| await github.rest.issues.updateComment({ | |
| ...context.repo, | |
| comment_id: botComment.id, | |
| body: body | |
| }); | |
| } else { | |
| // Create new comment | |
| await github.rest.issues.createComment({ | |
| ...context.repo, | |
| issue_number: context.issue.number, | |
| body: body | |
| }); | |
| } |