Skip to content
Latchkey

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 header is what makes the comment update instead of duplicating.
  • Comments on fork PRs need elevated permissions; prefer pull_request_target carefully.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →