From 7d906411855d75848a69b58aed6f767d89e20a63 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Tue, 25 Feb 2025 15:42:46 +0200 Subject: [PATCH] Change review apps PR workflow to leave only one comment --- .github/workflows/review_apps_on_pr_change.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/review_apps_on_pr_change.yml b/.github/workflows/review_apps_on_pr_change.yml index adad43d7d..f355772db 100644 --- a/.github/workflows/review_apps_on_pr_change.yml +++ b/.github/workflows/review_apps_on_pr_change.yml @@ -76,10 +76,12 @@ jobs: - name: Comment on PR env: + COMMENT_MARKER: GH_TOKEN: ${{ github.token }} run: | - cat < "${{runner.temp}}/pr-comment.md" + $COMMENT_MARKER + :tada: A review copy of this PR has been deployed! You can reach it at ${{steps.deploy.outputs.REVIEW_APP_URL}}. It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready @@ -89,4 +91,9 @@ jobs: For more details please see the [review app wiki page](https://github.com/alphagov/forms-team/wiki/Review-apps) EOF + old_comment_ids=$(gh api "repos/{owner}/{repo}/issues/${{github.event.pull_request.number}}/comments" --jq 'map(select((.user.login == "github-actions[bot]") and (.body | startswith($ENV.COMMENT_MARKER)))) | .[].id') + for comment_id in $old_comment_ids; do + gh api -X DELETE "repos/{owner}/{repo}/issues/comments/${comment_id}" + done + gh pr comment "${{github.event.pull_request.html_url}}" --body-file "${{runner.temp}}/pr-comment.md"