|
1 | 1 | name: pgschema Apply - Multi File |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
5 | 6 | branches: |
6 | 7 | - main |
7 | 8 | paths: |
|
10 | 11 |
|
11 | 12 | permissions: |
12 | 13 | contents: read |
| 14 | + pull-requests: write |
13 | 15 |
|
14 | 16 | jobs: |
15 | 17 | pgschema-apply-multi: |
16 | 18 | runs-on: ubuntu-latest |
| 19 | + if: github.event.pull_request.merged == true |
17 | 20 |
|
18 | 21 | env: |
19 | 22 | PGPASSWORD: postgres |
@@ -108,3 +111,79 @@ jobs: |
108 | 111 | echo "❌ Failed to apply schema changes!" |
109 | 112 | echo "" |
110 | 113 | echo "Please check the logs above for details." |
| 114 | +
|
| 115 | + - name: Comment on PR with migration results |
| 116 | + if: always() |
| 117 | + uses: actions/github-script@v7 |
| 118 | + with: |
| 119 | + script: | |
| 120 | + // Get the apply output from the previous step |
| 121 | + const applyOutput = `${{ steps.apply.outputs.output }}` || 'No output captured'; |
| 122 | +
|
| 123 | + // Determine if migration was successful based on job outcome |
| 124 | + const wasSuccessful = `${{ job.status }}` === 'success'; |
| 125 | +
|
| 126 | + let commentBody; |
| 127 | +
|
| 128 | + if (wasSuccessful) { |
| 129 | + commentBody = `## ✅ Schema Changes Applied Successfully! |
| 130 | +
|
| 131 | + <details> |
| 132 | + <summary>📋 Applied Changes</summary> |
| 133 | +
|
| 134 | + \`\`\` |
| 135 | + ${applyOutput} |
| 136 | + \`\`\` |
| 137 | +
|
| 138 | + </details> |
| 139 | +
|
| 140 | + **Database:** testdb |
| 141 | +
|
| 142 | + --- |
| 143 | + *This comment was automatically generated by the [pgschema](https://www.pgschema.com) Multi File Apply workflow.*`; |
| 144 | + } else { |
| 145 | + commentBody = `## ❌ Schema Migration Failed! |
| 146 | +
|
| 147 | + The multi-file schema migration failed after merging this PR. Please review the error details below: |
| 148 | +
|
| 149 | + <details> |
| 150 | + <summary>🔍 Error Details</summary> |
| 151 | +
|
| 152 | + \`\`\` |
| 153 | + ${applyOutput} |
| 154 | + \`\`\` |
| 155 | +
|
| 156 | + </details> |
| 157 | +
|
| 158 | + **Database:** testdb |
| 159 | +
|
| 160 | + --- |
| 161 | + *This comment was automatically generated by the [pgschema](https://www.pgschema.com) Multi File Apply workflow.*`; |
| 162 | + } |
| 163 | +
|
| 164 | + // Try to find existing comment |
| 165 | + const { data: comments } = await github.rest.issues.listComments({ |
| 166 | + ...context.repo, |
| 167 | + issue_number: context.issue.number, |
| 168 | + }); |
| 169 | +
|
| 170 | + const botComment = comments.find(comment => |
| 171 | + comment.user.type === 'Bot' && |
| 172 | + comment.body.includes('pgschema Multi File Apply workflow') |
| 173 | + ); |
| 174 | +
|
| 175 | + if (botComment) { |
| 176 | + // Update existing comment |
| 177 | + await github.rest.issues.updateComment({ |
| 178 | + ...context.repo, |
| 179 | + comment_id: botComment.id, |
| 180 | + body: commentBody |
| 181 | + }); |
| 182 | + } else { |
| 183 | + // Create new comment |
| 184 | + await github.rest.issues.createComment({ |
| 185 | + ...context.repo, |
| 186 | + issue_number: context.issue.number, |
| 187 | + body: commentBody |
| 188 | + }); |
| 189 | + } |
0 commit comments