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) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RF5L4HtbcykTfY9YUYGds3
This commit is contained in:
@@ -3,18 +3,18 @@ name: Staging deployment
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches-ignore: [main]
|
branches-ignore: [main]
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened]
|
||||||
delete:
|
delete:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: staging-${{ github.event.ref }}
|
group: staging-${{ github.event.pull_request.head.ref || github.event.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
|
||||||
pull-requests: write
|
|
||||||
env:
|
env:
|
||||||
BRANCH: ${{ github.ref_name }}
|
BRANCH: ${{ github.ref_name }}
|
||||||
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
|
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
|
||||||
@@ -60,6 +60,28 @@ jobs:
|
|||||||
- name: Summary
|
- name: Summary
|
||||||
run: echo "Deployed to https://${HOST}" >> "$GITHUB_STEP_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
|
- name: Comment staging URL on PR
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
|
|||||||
Reference in New Issue
Block a user