Pull request deployments

Link pull requests to a deployment so it follows their head, shows its status on the pull request, and is removed after they close.

A deployment can link one or more pull requests. The app whose repository has a linked pull request follows that pull request's head and syncs on every push, and the pull request shows the deployment. When every linked pull request is closed or merged, Wardn removes the deployment after a grace period.

This is a different way to give a pull request a deployment from previews. A preview is a copy of a parent deployment that Wardn makes for every open pull request on the repository. A linked pull request belongs to one deployment you choose, which is usually made from a template with the name pattern <template>-pr-<n>. Previews keep working as they did, and a repository can use both.

Wardn looks a pull request up by number on the host the repository is read through: GitHub through the Wardn GitHub App, and GitLab (merge requests), Bitbucket Cloud, Azure DevOps, GitHub Enterprise Server and Gitea or Forgejo through a git host connection. The access token needs permission to read pull requests. A repository connected as plain git has no host to ask and cannot be linked by number.

Let an app get a deployment for a pull request

On the app's settings, Previews has one switch, Can get a deployment for a pull request, and two fields: Public port (the port the app serves web traffic on) and Path (where the deployment opens). A pull request is linked only to a deployment that has an enabled app on its repository. Where a deployment is reached and how it is secured is the cluster's and the environment's business, not the app's.

api -X PUT "$WARDN_API_URL/api/v1/apps/$APP_ID/pull-request-settings" \
  -d '{"enabled": true, "publicPort": 8080, "publicPath": "/"}'

Setting it needs app:manage.

On New deployment, Linked pull requests has Add pull request: choose the repository and the number. Wardn asks the git host, shows the title, author, branch and state, and refuses a pull request that does not exist. The same list is on an existing deployment's settings.

The deployment's page shows the link: Open or Merged, the pull request it follows, and when it will be removed.

What the deployment follows

  • The app whose repository has a linked, open pull request renders that pull request's head commit. Each push to the pull request renders the new head, in the same way a push to a tracked branch does. The app follows the pull request whatever branch it is set to, so a push to main does not move it back.
  • The deployment's other apps stay as they are set: they run the commits of the snapshot the deployment runs now, or follow their branch or pinned version.
  • A pull request from a fork is not followed until someone who manages the deployment approves the link, because following it runs its author's manifests in the cluster. Until then the link shows Needs approval.
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/pull-requests/$LINK_ID/approve"

What the pull request shows

Through the same git host connection previews use, the pull request gets:

OptionWhat it shows
StatusThe wardn/preview commit status: building, live, or why it failed, linking to the deployment in Wardn.
View deployment buttonA GitHub deployment whose button opens the deployment's page in Wardn.
CommentOne comment, edited in place, with the status, the commit and a link.

Each is on by default and has a switch in the deployment's settings, with the template's choice as the default.

Removal

When every linked pull request is closed or merged:

  1. Notice. Wardn records that the removal is scheduled and updates the comment on each pull request with the time. The event deployment.removal_scheduled goes out with it.
  2. Grace period. The deployment is removed once the grace period has passed since the last pull request closed: 1 hour by default, from 0 minutes to 30 days, set in the deployment's Cleanup settings or by the template. A pull request that reopens before then calls the removal off.
  3. Removal. Wardn applies an empty snapshot with pruning. The operator makes the namespace of a deployment that links pull requests, so it removes it too: the namespace, the deployment's own copies of services (with their volumes), and the Ingress, DNS check and certificates the deployment made. A deployment that never applied anything has nothing to clear and goes at once.

Shared services are never touched: their instance is in another namespace, and only the copy of the connection Secret and the alias in this namespace go.

The deployment's history stays. Its snapshots, timeline and audit entries remain, and a deployment that has snapshots stays in the list as a record. The deployment.removed event marks the end.

api -X PUT "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/pull-request-settings" \
  -d '{"graceMinutes": 180, "keep": false, "status": true, "button": true, "comment": true}'

Keep a deployment

Keep this deployment (keep) stops the removal for good and unlinks the pull requests: the deployment becomes an ordinary one. Use it when a pull request's deployment turns out to be worth keeping.

Reopened pull requests

When a pull request of a removed deployment is opened again, the deployment shows Recreate from payments-stack v3. It brings the removal back out: the deployment is rendered at the pull request's head again, with the template version it came from. Nothing is recreated without someone choosing it.

api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/recreate"

Events and audit

Linking and unlinking, approving a fork, changing the settings, scheduling, calling off, starting and finishing a removal are all recorded in Activity. The events are deployment.pull_request_linked, deployment.pull_request_unlinked, deployment.removal_scheduled, deployment.removal_cancelled and deployment.removed.

On this page