From ff1f306c7e2500409651f1d611cf92c22b1015b3 Mon Sep 17 00:00:00 2001 From: Nat Dean-Lewis <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Tue, 31 Mar 2026 17:23:55 +0100 Subject: [PATCH] CLDC-4351: only teardown review apps for prs with review apps (#3293) * CLDC-4351: tear down review apps on label removal OR on pr close for labelled prs * CLDC-4351: add teardown success comment on unlabel * CLDC-4351: update deploy comment with teardown process * CLDC-4351: typo fix * CLDC-4351: typo fix * CLDC-4351: typo fix --- .github/workflows/review_deploy.yml | 2 +- .../workflows/review_teardown_pipeline.yml | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/review_deploy.yml b/.github/workflows/review_deploy.yml index c106b7a3c..948263c58 100644 --- a/.github/workflows/review_deploy.yml +++ b/.github/workflows/review_deploy.yml @@ -55,7 +55,7 @@ jobs: with: script: | const prNumber = context.issue.number; - const msg = `Created review app at https://review.submit-social-housing-data.communities.gov.uk/${prNumber}. Note that the review app will be automatically deprovisioned after 30 days and will need the review app pipeline running again.`; + const msg = `Created review app at https://review.submit-social-housing-data.communities.gov.uk/${prNumber}. Note that the review app will be automatically deprovisioned after 30 days and will need the review app pipeline running again. To tear down the review app entirely, remove the \`review-app\` label or merge/close the PR.`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, diff --git a/.github/workflows/review_teardown_pipeline.yml b/.github/workflows/review_teardown_pipeline.yml index d2a49db4e..78b752ced 100644 --- a/.github/workflows/review_teardown_pipeline.yml +++ b/.github/workflows/review_teardown_pipeline.yml @@ -7,6 +7,7 @@ on: pull_request: types: - closed + - unlabeled env: app_repo_role: arn:aws:iam::815624722760:role/core-application-repo @@ -18,6 +19,9 @@ env: jobs: database: name: Drop database + if: > + (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'review-app')) + || (github.event.action == 'unlabeled' && github.event.label.name == 'review-app') runs-on: ubuntu-latest permissions: id-token: write @@ -54,6 +58,9 @@ jobs: infra: name: Teardown review app + if: > + (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'review-app')) + || (github.event.action == 'unlabeled' && github.event.label.name == 'review-app') needs: [database] uses: communitiesuk/submit-social-housing-lettings-and-sales-data-infrastructure/.github/workflows/destroy_review_app_infra.yml@main with: @@ -61,3 +68,23 @@ jobs: app_repo_role: arn:aws:iam::815624722760:role/core-application-repo permissions: id-token: write + + comment: + name: Comment on PR + if: github.event.action == 'unlabeled' && github.event.label.name == 'review-app' + needs: [infra] + runs-on: ubuntu-latest + permissions: + pull-requests: write + + steps: + - name: Comment on PR + uses: actions/github-script@v7 + with: + script: | + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: 'Review app has been torn down. To redeploy, reapply the `review-app` label.', + });