---
title: "Require a staging deployment before a pull request merges | Proofline"
description: "Require a staging deployment before merge when a change can pass CI and still fail on its first real deploy, as migrations do."
url: https://proofline.sh/learn/require-deployments-before-merge/
---

[Learning center](/learn/)

# Require a staging deployment before a pull request merges

Require a staging deployment before merge when a change can pass CI and still fail on its first real deploy, as migrations do. Expect it to serialize pull requests through one shared environment, and make "succeeded" mean the deploy was checked, not just that the script exited.

Code review The Proofline team November 23, 2026 4 min read

## What the rule checks

Branch protection and rulesets share one rule: "You can require that changes are successfully deployed to specific environments before a branch can be merged. For example, you can use this rule to ensure that changes are successfully deployed to a staging environment before the changes merge to your default branch." [Available rules for rulesets](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#require-deployments-to-succeed-before-merging) In a branch protection rule you select **Require deployments to succeed before merging** and then the environments ([managing a branch protection rule](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule)). In the REST API it is a `required_deployments` rule listing "The environments that must be successfully deployed to before branches can be merged" ([repository rulesets API](https://docs.github.com/en/rest/repos/rules#create-a-repository-ruleset)).

With GitHub Actions, the deployment comes from a job that references the environment. "When a workflow job that references an environment runs, it creates a deployment object with the `environment` property set to the name of your environment," and its deployment statuses carry a `state` "set to the status of the job." [Deploying with GitHub Actions](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/control-deployments#tracking-deployments-through-apps) So the deployment succeeds when the job does. A job that sets `deployment: false` creates no deployment object at all, and "the deployment history for the environment is not updated" ([using environments without deployments](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/control-deployments#using-environments-without-deployments)).

The docs do not say in detail which commit's deployment the rule accepts. Before relying on it, test in your repository whether a deployment of an earlier commit on the same pull request still satisfies the rule after a new push.

## What a deploy catches that CI misses

CI usually runs against an empty or synthetic environment. A deploy runs against one that has history: existing rows, existing resources, real configuration, real permissions. Some changes pass every test and fail only there.

Suppose `acme/billing`, a fictional repository, has a pull request that adds a column to the `invoices` table with `NOT NULL` and no default. The migration runs cleanly in CI, because the test database starts empty. On staging, where `invoices` has rows, PostgreSQL rejects the migration, because the existing rows would hold nulls in the new column. Without the rule, the pull request merges, and the first deploy that runs the migration fails on whichever environment it reaches first. With the rule, the staging deploy fails on the pull request, the required deployment is missing, and the author adds a default or a backfill before anyone merges.

A workflow that deploys each pull request to staging:

```
name: staging
on:
  pull_request:
    branches: [main]

concurrency:
  group: staging
  cancel-in-progress: false
  queue: max

jobs:
  deploy-staging:
    runs-on: ubuntu-latest
    environment:
      name: staging
      url: https://staging.billing.acme.example
    steps:
      - uses: actions/checkout@v6
      - run: ./scripts/migrate.sh staging
      - run: ./scripts/deploy.sh staging
      - run: ./scripts/smoke-test.sh https://staging.billing.acme.example
```

The smoke test runs inside the deploy job on purpose. Because the deployment's state follows the job, a failing smoke test makes the deployment fail, and the rule then means the service answered after the deploy, not only that the deploy script exited.

If the environment restricts which branches can deploy, allow pull request runs explicitly. GitHub's environment reference notes that "Adding another branch rule for `refs/pull/*/merge` would also allow workflows triggered by `pull_request` events to deploy to the environment." [Deployments and environments](https://docs.github.com/en/actions/reference/workflows-and-actions/deployments-and-environments#deployment-branches-and-tags)

The ruleset rule itself:

```
{
  "type": "required_deployments",
  "parameters": {
    "required_deployment_environments": ["staging"]
  }
}
```

## What it does not catch

Staging is not production. A migration that succeeds on staging's row count can still lock a production table for longer than your traffic tolerates, and production-only configuration is invisible to a staging deploy. The rule proves the change deployed somewhere once.

A shared staging environment also holds only one version at a time. The `concurrency` group above allows "at most one running job or workflow in a concurrency group at any time," so pull requests take turns, and each deploy replaces the last. The `queue: max` line matters: by default "any existing `pending` job or workflow run in the same group is canceled and replaced," which would leave a waiting pull request with no deployment and a blocked merge ([workflow syntax: concurrency](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#concurrency)). Two pull requests can each deploy successfully and never be deployed together. Combined effects need the base branch tested with both changes, which is what [up-to-date branches or a merge queue](/learn/require-branches-up-to-date-before-merge/) provide for CI.

Fork pull requests usually cannot deploy at all. They run without repository secrets, so a deploy job that needs credentials fails, and the rule blocks every outside contributor ([required checks on fork pull requests](/learn/required-checks-on-fork-pull-requests/)).

## What it costs

Every push to a pull request redeploys staging, and pull requests wait in line for it. On a busy repository the wait can dominate review time. Staging also stops being a stable place to demo or test anything else, because it holds whichever pull request deployed last.

Plan limits apply too. GitHub says that "Users with GitHub Free plans can only configure environments for public repositories," while "Organizations with GitHub Team and users with GitHub Pro can configure environments for private repositories" ([managing environments for deployment](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments)). Required reviewers and wait timers on an environment are available only in public repositories on Free, Pro and Team plans.

## The decision

Turn the rule on for repositories whose failures cluster at deploy time: schema migrations, infrastructure as code, configuration that differs by environment. Put a smoke test in the deploy job so success means something. Leave it off for repositories where CI already exercises what a deploy would, and where serializing every pull request through one environment would cost more than the failures it catches. The rule names fixed environments, so if several teams' pull requests queue for one staging environment, scope the rule to the repositories whose changes most often fail at deploy time.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Required checks that need secrets on fork pull requests](/learn/required-checks-on-fork-pull-requests/)
    
    Code review The Proofline team November 23, 2026 4 min read
    
-   ### [Should pull requests be up to date with the base before merging?](/learn/require-branches-up-to-date-before-merge/)
    
    Code review The Proofline team November 23, 2026 5 min read
