How to Comment a Preview URL on a PR in GitHub Actions
A sticky comment posts the preview URL once and edits it in place on each push.
Deploy a preview, capture its URL, then post or update a single PR comment with marocchino/sticky-pull-request-comment.
Steps
- Deploy a preview and capture the URL as a step output.
- Grant
pull-requests: write. - Use a sticky comment action with a fixed header so it updates in place.
Workflow
.github/workflows/preview.yml
on: pull_request
permissions:
pull-requests: write
jobs:
preview:
runs-on: ubuntu-latest
steps:
- id: deploy
run: echo "url=https://pr-${{ github.event.number }}.preview.example.com" >> "${GITHUB_OUTPUT}"
- uses: marocchino/sticky-pull-request-comment@v2
with:
header: preview
message: 'Preview ready: ${{ steps.deploy.outputs.url }}'Gotchas
- A unique
headeris what makes the comment update instead of duplicating. - Comments on fork PRs need elevated permissions; prefer
pull_request_targetcarefully.
Related guides
How to Comment on a Pull Request From a Workflow in GitHub ActionsPost a comment on a pull request from a GitHub Actions workflow using actions/github-script and the GITHUB_TO…
How to Deploy to Vercel from GitHub ActionsDeploy a project to Vercel from GitHub Actions using the Vercel CLI and a scoped token so production deploys…