Description

This control ensures that the repository’s continuous integration (CI) pipeline, such as a GitHub Actions workflow, runs on every pull request and must complete successfully before the pull request can be merged into the default branch. The CI jobs are enforced as required status checks.

Rationale

A CI pipeline automatically builds and tests code changes, catching defects, failing tests, and security issues before they reach the default branch. Making the pipeline a required check ensures that no change can be merged while the build or tests are failing, protecting the stability and security of production code.

Impact

  • Pull requests cannot be merged until the CI pipeline completes successfully.

  • A CI workflow must exist and run on pull requests targeting the default branch.

  • Failing, slow, or misconfigured pipelines can delay or block merges until they are fixed.

  • Improves code quality and reduces the risk of broken or insecure releases.

Default Value

  • Disabled by default. Repositories have no CI pipeline or required checks unless a workflow is created and its jobs are configured as required status checks in a ruleset or classic branch protection rule.

Remediation

Branch protection can be configured using rulesets, classic branch protection rules, or both. Complete the section that matches the repository’s configuration. The control is met if either configuration enforces the requirement.


Organization Rulesets
Test Plan
  1. Sign in to GitHub as an organization owner or a user with the Manage organization ref update rules and rulesets permission.
  2. Click your profile picture in the upper-right corner, select Organizations, and select the target organization.
  3. Select Settings.
  4. Under Code, planning, and automation, select Repository → Rulesets.
  5. Verify that an active branch ruleset targets the in-scope repositories (Target repositories) and the default branch (Target branches).
  6. Verify that Require status checks to pass is enabled and that the CI workflow’s jobs are listed as required checks.

  1. If no active organization ruleset exists, or the CI jobs are not required checks, follow the Implementation Steps below to remediate the issue and repeat the test.
Implementation Steps
  1. Sign in to GitHub as an organization owner or a user with the Manage organization ref update rules and rulesets permission.
  2. Click your profile picture in the upper-right corner, select Organizations, and select the target organization.
  3. Select Settings.
  4. Under Code, planning, and automation, select Repository → Rulesets.

                                    

  1. Click New ruleset and select New branch ruleset, or edit an existing branch ruleset.
  2. Enter a name for the ruleset.
  3. Under Enforcement status, select Active.
  4. Under Target repositories, select the repositories to protect (all repositories, repositories matching a name pattern, repositories with a custom property, or a selected list).
  5. Under Target branches, click Add target and select Include default branch.
  6. In the Rules section, enable Require status checks to pass.
  7. Click Add checks and enter the CI workflow’s job names exactly as they appear on pull requests (e.g., build, test).

  1. Ensure every targeted repository has a CI workflow that reports these check names; otherwise, pull requests in those repositories will be blocked from merging.
  2. Click Create (or Save changes for an existing ruleset) to apply the ruleset.
Backout Plan
  1. Sign in to GitHub as an organization owner or a user with the Manage organization ref update rules and rulesets permission.
  2. Click your profile picture in the upper-right corner, select Organizations, and select the target organization.
  3. Select Settings.
  4. Under Code, planning, and automation, select Repository → Rulesets.
  5. Edit the applicable branch ruleset.
  6. Remove the CI checks from the required status checks, disable Require status checks to pass, or remove the affected repositories from Target repositories.
  7. Click Save changes.
  8. Verify that pull requests in the targeted repositories can be merged without a passing CI pipeline according to the updated configuration.
Repository Rulesets

Test Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository and select the Actions tab. Verify that a CI workflow exists and runs on pull requests targeting the default branch.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Verify that an active branch ruleset targets the default branch, that Require status checks to pass is enabled, and that the CI workflow’s jobs are listed as required checks.

  1. If no CI workflow exists, no active ruleset targets the default branch, or the CI jobs are not required checks, follow the Implementation Steps below to remediate the issue and repeat the test.

Implementation Steps

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. If no CI workflow exists, create one in the .github/workflows directory that builds and tests the code and is triggered on pull_request events for the default branch.

  4. Open a pull request so the CI workflow runs at least once and its check names are available.

  5. Select Settings.

  6. Under Code and automation, select Rules → Rulesets.

  1. Click New ruleset and select New branch ruleset, or edit an existing branch ruleset.

  2. Enter a name for the ruleset.

  3. Under Enforcement status, select Active.

  4. Under Target branches, click Add target and select Include default branch.

  5. In the Rules section, enable Require status checks to pass.

  6. Click Add checks and select the CI workflow’s jobs (e.g., build, test).

  1. Click Create (or Save changes for an existing ruleset) to apply the ruleset.

Backout Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Edit the applicable branch ruleset.

  6. Remove the CI checks from the required status checks, or disable Require status checks to pass.

  7. Click Save changes.

  8. Verify that pull requests can be merged without a passing CI pipeline according to the updated configuration.

Classic Branch Protection Rule

Test Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository and select the Actions tab. Verify that a CI workflow exists and runs on pull requests targeting the default branch.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Under Branch protection rules, verify that a rule matches the default branch (e.g., main).

  6. Click Edit next to the rule and verify that Require status checks to pass before merging is selected and that the CI workflow’s jobs are listed as required checks.

  1. If no CI workflow exists, no matching rule exists, or the CI jobs are not required checks, follow the Implementation Steps below to remediate the issue and repeat the test.

Implementation Steps

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. If no CI workflow exists, create one in the .github/workflows directory that builds and tests the code and is triggered on pull_request events for the default branch.

  4. Open a pull request so the CI workflow runs at least once and its check names are available.

  5. Select Settings.

  6. Under Code, planning and automation, select Branches.

  7. Next to Branch protection rules, click Add classic branch protection rule, or click Edit next to an existing rule.

  1. In Branch name pattern, enter the name of the default branch (e.g., main).

  2. Select Require status checks to pass before merging.

  3. In the search field, search for and select the CI workflow’s jobs (e.g., build, test).

  1. Click Create (or Save changes for an existing rule) to apply the rule.

Backout Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Click Edit next to the applicable branch protection rule.

  6. Remove the CI checks from the required status checks, or clear Require status checks to pass before merging.

  7. Click Save changes.

  8. Verify that pull requests can be merged without a passing CI pipeline according to the updated configuration.

References