From b0b21948066f09c5ae50427eb97b0b6dc8f52d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Sun, 21 Jun 2026 09:26:31 +0200 Subject: [PATCH] fix(ci): comment staging URL when the PR is opened, not just on deploy The staging deploy runs on push to a non-main branch and tries to comment the staging URL on the branch's PR. When the branch is pushed before the PR exists (the common case), the comment is skipped and never reappears once the PR is opened. Add a pull_request [opened, reopened] trigger and move the comment into its own job that runs both after a successful push-deploy and on PR open/reopen. The branch is taken from github.head_ref on PR events and github.ref_name on push; the existing dedupe-by-body keeps the two paths from double-posting. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01RF5L4HtbcykTfY9YUYGds3 --- .github/workflows/staging.yml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 2a87188..d8bb37d 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -3,18 +3,18 @@ name: Staging deployment on: push: branches-ignore: [main] + pull_request: + types: [opened, reopened] delete: concurrency: - group: staging-${{ github.event.ref }} + group: staging-${{ github.event.pull_request.head.ref || github.event.ref }} cancel-in-progress: true jobs: deploy: if: github.event_name == 'push' runs-on: ubuntu-latest - permissions: - pull-requests: write env: BRANCH: ${{ github.ref_name }} FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} @@ -60,6 +60,28 @@ jobs: - name: Summary run: echo "Deployed to https://${HOST}" >> "$GITHUB_STEP_SUMMARY" + # Comment the staging URL on the branch's PR. Runs both after a successful + # push-deploy (covers PRs that already exist) and when a PR is opened or + # reopened (covers the common case of pushing the branch before opening the + # PR, where the deploy ran with no PR to comment on). The comment is deduped + # by body, so the two paths never double-post. + comment: + needs: [deploy] + if: | + always() && + (github.event_name == 'pull_request' || + (github.event_name == 'push' && needs.deploy.result == 'success')) + runs-on: ubuntu-latest + permissions: + pull-requests: write + env: + BRANCH: ${{ github.head_ref || github.ref_name }} + steps: + - name: Compute staging host + run: | + SLUG=$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9-]+/-/g; s/-+/-/g; s/^-//; s/-$//' | cut -c1-30 | sed 's/-*$//') + echo "HOST=timetracker-staging-${SLUG}.fly.dev" >> "$GITHUB_ENV" + - name: Comment staging URL on PR uses: actions/github-script@v7 with: