Skip to content

Commit 686eff8

Browse files
authored
feat: show deployment plan only if it has changed (#61)
1 parent 62f4c09 commit 686eff8

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

.github/workflows/deploy.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,23 @@ jobs:
4747
run: terraform plan -no-color -input=false
4848
continue-on-error: true
4949

50-
- name: Update Pull Request
51-
uses: mshick/add-pr-comment@v2
52-
if: github.event_name == 'pull_request'
50+
- name: Find Comment
51+
uses: peter-evans/find-comment@v2
52+
id: fc
53+
with:
54+
issue-number: ${{ github.event.pull_request.number }}
55+
comment-author: 'github-actions[bot]'
56+
body-regex: "^### Snapshot Service Plan"
57+
58+
# If the new deployment plan contains changes, post it in a comment.
59+
- name: Create or update comment
60+
uses: peter-evans/create-or-update-comment@v2
61+
if: github.event_name == 'pull_request' && !contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.')
5362
with:
54-
github-token: ${{ secrets.GITHUB_TOKEN }}
55-
with:
56-
message: |
57-
#### Terraform Plan 📖${{ steps.plan.outcome }}
63+
comment-id: ${{ steps.fc.outputs.comment-id }}
64+
issue-number: ${{ github.event.pull_request.number }}
65+
body: |
66+
### Snapshot Service Plan: ${{ steps.plan.outcome }}
5867
5968
<details><summary>Show Plan</summary>
6069
@@ -63,7 +72,15 @@ jobs:
6372
```
6473
6574
</details>
75+
edit-mode: replace
6676

77+
# If the new deployment plan contains no changes, delete the last posted plan.
78+
- name: Delete comment
79+
uses: detomarco/[email protected]
80+
if: github.event_name == 'pull_request' && contains(steps.plan.outputs.stdout, 'No changes. Your infrastructure matches the configuration.')
81+
with:
82+
comment-id: ${{ steps.fc.outputs.comment-id }}
83+
6784
- name: Terraform Plan Status
6885
if: steps.plan.outcome == 'failure'
6986
run: exit 1

0 commit comments

Comments
 (0)