Free — no signup required

Posting the Preview URL Back to the PR

2 min read

Closing the Developer Experience Loop

A preview environment that exists but is not discoverable is nearly useless. The final piece of the developer experience is automatically posting the preview URL as a comment or status check on the Pull Request itself.

GitHub Actions provides two mechanisms for this:

Option 1: PR Comment

A workflow step uses the GitHub API to post a comment on the PR containing the constructed preview URL and a note that the environment will be destroyed when the PR closes.

Option 2: GitHub Deployment Status

GitHub has a first-class concept of "Deployments" with status checks. This integrates with branch protection rules and shows a deployment status badge directly on the PR — a step creates a Deployment object for the preview environment at the current commit, then reports a success status on it with the preview URL attached.

Option 2 is preferred for teams using branch protection rules, because the deployment status can be required to pass before merging. It also provides a history of all deployments for a given PR.

Key Point: The preview URL comment or deployment status is what transforms ephemeral environments from an infrastructure feature into a developer productivity feature. Without it, developers must know to look for the environment. With it, reviewers get a one-click path to the live preview directly from the PR review interface.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free