Post

Restricted pull request workflows to target main only

Restricted pull request workflows to target main only

I tightened the homelab’s pull request workflow triggers so CI only runs when a PR targets main. The change spans multiple GitHub Actions workflows, adds static validation, and updates documentation to reflect the new targeting rule.

Restricted pull request triggers across workflows

Seven workflow files now include branches: [main] on their pull_request trigger. Most also list types: [opened, synchronize, reopened, edited], while terragrunt-plan.yml adds edited to its existing types. As a result, workflows no longer run on PRs targeting other branches, and editing a PR retargeted to main still triggers eligible checks. Push, scheduled, and manual triggers keep their own conditions.

Static checks and policy enforce the rule

The offline static checks script now validates that each pull-request workflow targets main and includes edited in its types. It parses each workflow with yq and jq, then fails if the conditions are not met. The policy/workflows.rego file was also updated to align with the new expectation.

Documentation reflects the targeting rule

docs/ci-cd.md now states that Terragrunt Plan runs on pull requests targeting main, and that editing a PR triggers checks on main, including when a stacked PR is retargeted. openwiki/operations/validation-gates.md adds the same note about repository PR workflows running when the PR targets main, including after retargeting.

Where this pattern applies next

A platform team can reuse this technique when they want to scope expensive CI jobs to a single integration branch and avoid running checks on feature-branch PRs. The static check script provides a reusable guardrail for enforcing the rule across many workflow files.

This post is licensed under CC BY 4.0 by the author.