From 15d4c0e956cebac3f38a650698758c33ce08a7d1 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 09:54:31 +0200 Subject: [PATCH 1/8] show deployment plan only if it has changed --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c7ee1579c..7069c0cf3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,7 +54,7 @@ jobs: - name: Update Pull Request uses: mshick/add-pr-comment@v2 - if: github.event_name == 'pull_request' + 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: From 5fe94c652730246b9238bee516284ec3af10ba72 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 13:31:46 +0200 Subject: [PATCH 2/8] remove deployment plan comment if deployment is null --- .github/workflows/deploy.yml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7069c0cf3..fd1648593 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,14 +52,22 @@ jobs: run: terraform plan -no-color -input=false continue-on-error: true - - name: Update Pull Request - uses: mshick/add-pr-comment@v2 + - 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" + + - 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 @@ -68,6 +76,13 @@ jobs: ```
+ edit-mode: replace + + - name: Delete comment + uses: detomarco/delete-comment@v1 + 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' From cdd302f1019808159dfceda8e18614b592196029 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 15:02:31 +0200 Subject: [PATCH 3/8] dummy patch to test pr delete --- daily_snapshot_terraform/modules/daily_snapshot/service/init.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh b/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh index a8f8684ad..7dcb3fd51 100644 --- a/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh +++ b/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh @@ -1,4 +1,5 @@ #!/bin/bash +# blah dnf install -y docker docker-compose ruby ruby-devel make gcc s3fs-fuse gem install docker-api slack-ruby-client activesupport From f18f32873010ea952fc298a456732b679699b4d7 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 15:16:39 +0200 Subject: [PATCH 4/8] fix workflow indentation --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9f3272063..7ede9e7cb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -71,7 +71,7 @@ jobs: ``` - edit-mode: replace + edit-mode: replace - name: Delete comment uses: detomarco/delete-comment@v1 From ad4477035cb735cf1c50a597c95e7cd57df1f545 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 15:18:03 +0200 Subject: [PATCH 5/8] fix action name --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7ede9e7cb..7068b61af 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -74,7 +74,7 @@ jobs: edit-mode: replace - name: Delete comment - uses: detomarco/delete-comment@v1 + 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 }} From f6f69bfe3f1c955bec41de508b5014198cab72ed Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 15:19:22 +0200 Subject: [PATCH 6/8] remove typo --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7068b61af..2065ae5e5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -62,7 +62,7 @@ jobs: comment-id: ${{ steps.fc.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body: | - ### Snapshot Service Plan: ${{ steps.plan.outcome }}* + ### Snapshot Service Plan: ${{ steps.plan.outcome }}
Show Plan From b43fe8723af0b5f52adace9d71c013bf97cf58e7 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 15:20:36 +0200 Subject: [PATCH 7/8] revert service script --- daily_snapshot_terraform/modules/daily_snapshot/service/init.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh b/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh index 7dcb3fd51..a8f8684ad 100644 --- a/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh +++ b/daily_snapshot_terraform/modules/daily_snapshot/service/init.sh @@ -1,5 +1,4 @@ #!/bin/bash -# blah dnf install -y docker docker-compose ruby ruby-devel make gcc s3fs-fuse gem install docker-api slack-ruby-client activesupport From ede8eebf637d99d21e0a0879eddd3f7600a0fd74 Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Tue, 28 Mar 2023 15:24:39 +0200 Subject: [PATCH 8/8] Document the deployment workflow --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2065ae5e5..75af6ba9b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -55,6 +55,7 @@ jobs: 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.') @@ -73,6 +74,7 @@ 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.')