diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 19b4c84bd..75af6ba9b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,14 +47,23 @@ jobs: run: terraform plan -no-color -input=false continue-on-error: true - - name: Update Pull Request - uses: mshick/add-pr-comment@v2 - if: github.event_name == 'pull_request' + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-regex: "^### Snapshot Service Plan" + + # If the new deployment plan contains changes, post it in a comment. + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v2 + if: github.event_name == 'pull_request' && !contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.') with: - github-token: ${{ secrets.GITHUB_TOKEN }} - with: - message: | - #### Terraform Plan 📖${{ steps.plan.outcome }} + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ### Snapshot Service Plan: ${{ steps.plan.outcome }}
Show Plan @@ -63,7 +72,15 @@ jobs: ```
+ edit-mode: replace + # If the new deployment plan contains no changes, delete the last posted plan. + - name: Delete comment + uses: detomarco/delete-comments@v1.0.4 + if: github.event_name == 'pull_request' && contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.') + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + - name: Terraform Plan Status if: steps.plan.outcome == 'failure' run: exit 1