From bdf9270f882a526a2475fc9979d06c7da69e5b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Mon, 4 May 2026 07:17:57 +0200 Subject: [PATCH] Update single PR comment across preview deploy + teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deploy job was creating a fresh comment on every push, so PRs accumulated a wall of preview-URL comments. Now we look up the existing comment by an HTML marker (``) and edit it in place โ€” both on push and on teardown. Comment also gains a link to the GitHub Actions run that produced the preview, plus the head SHA. Co-Authored-By: Claude Opus 4.7 --- .github/workflows/cd-staging.yml | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cd-staging.yml b/.github/workflows/cd-staging.yml index 265a0b3..8956ab9 100644 --- a/.github/workflows/cd-staging.yml +++ b/.github/workflows/cd-staging.yml @@ -312,18 +312,34 @@ jobs: docker compose -f docker-compose.staging.yml -p "$PROJECT" --env-file staging.env ps - - name: Comment preview URL on PR - uses: peter-evans/create-or-update-comment@v4 + # Find any prior preview comment so we can update it in place rather + # than spamming a new one each push. The marker line at the bottom of + # the body is what `body-includes` matches on. + - name: Find existing preview comment + uses: peter-evans/find-comment@v3 + id: find-comment with: issue-number: ${{ github.event.number }} + comment-author: "github-actions[bot]" + body-includes: "" + + - name: Upsert preview comment on PR + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.find-comment.outputs.comment-id }} + issue-number: ${{ github.event.number }} + edit-mode: replace body: | ๐Ÿš€ **PR preview deployed** - **Journal:** https://${{ steps.ports.outputs.host }} - **Planner (shared staging):** https://planner.staging.trails.cool - **Database:** `${{ steps.ports.outputs.database }}` (separate from production / persistent staging) + - **Build:** [run ${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) ยท commit `${{ github.event.pull_request.head.sha }}` Updates automatically on push. Tears down when this PR closes. + + # โ”€โ”€ PR preview teardown โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ teardown-preview: @@ -397,7 +413,7 @@ jobs: with: issue-number: ${{ github.event.number }} comment-author: "github-actions[bot]" - body-includes: "PR preview deployed" + body-includes: "" - name: Update preview comment on close if: steps.find-comment.outputs.comment-id @@ -406,4 +422,10 @@ jobs: comment-id: ${{ steps.find-comment.outputs.comment-id }} edit-mode: replace body: | - ๐Ÿงน PR preview torn down (PR ${{ github.event.action == 'closed' && github.event.pull_request.merged && 'merged' || 'closed' }}). + ๐Ÿงน **PR preview torn down** (PR ${{ github.event.pull_request.merged && 'merged' || 'closed' }}). + + Database `trails_pr_${{ steps.ports.outputs.pr }}` dropped, containers removed, Caddyfile snippet cleared. + + [Teardown run ${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) + +