Sub topic 9
Active, evaluate and disabled enforcement
This chapter assumes you can read a ruleset JSON body, know what a branch ruleset targets, and have seen the enforcement field in the earlier examples. It covers the three enforcement statuses, how to move between them, and the mistakes that cause surprises.
The three statuses
Every ruleset has an enforcement value. It controls whether the rules are applied, not what they say. The targets, rules and bypass actors stay the same in every status.
| Status | API value | Effect on pushes and merges | Recorded in rule insights |
|---|---|---|---|
| Active | `active` | Rules are enforced. Violating changes are blocked. | Yes |
| Evaluate | `evaluate` | Rules are not enforced. Changes that would have been blocked still go through. | Yes, marked as would-fail |
| Disabled | `disabled` | Rules are not enforced and not checked. | No |
Evaluate mode is a dry run. It lets you see what a ruleset would block before it blocks anything. Disabled keeps the ruleset's configuration but switches it off completely.
How a ruleset moves between statuses
A typical new ruleset follows this path.
Moving between statuses is a single field change. You do not need to recreate the ruleset or lose its history.
Setting the status in JSON
The enforcement field sits at the top level of the body. This is the ruleset from earlier in the tutorial, set to evaluate:
{
"name": "protect-default-branch",
"target": "branch",
"enforcement": "evaluate",
"conditions": {
"ref_name": {
"include": ["~DEFAULT_BRANCH"],
"exclude": []
},
"repository_name": {
"include": ["~ALL"],
"exclude": ["sandbox-*"]
}
},
"rules": [
{ "type": "deletion" },
{ "type": "non_fast_forward" }
]
}To change the status of an existing ruleset, send only the field you want to change. Replace RULESET_ID with the ID returned when you created it:
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
/orgs/YOUR_ORG/rulesets/RULESET_ID \
-f enforcement=activeA safe rollout with evaluate
- Create the ruleset with
enforcementset toevaluate. - Wait while normal work continues. A few days to a full release cycle is common.
- Open the rule insights page and filter by the ruleset. Look for repositories and actors that would have been blocked.
- Fix the causes. Add missing status checks, adjust the repository exclusions, or narrow the bypass actors.
- Switch to
active.
Evaluate shows you the effect of the rules on real traffic. It does not show you how people will react to being blocked, so tell teams before step 5.
Common errors
- Assuming evaluate protects anything. Nothing is blocked in this mode. A ruleset left in evaluate by mistake is a ruleset that does not protect the branch.
- Using disabled to test. Disabled produces no insight data. Use evaluate if you want to learn something.
- Expecting a missing required check to appear in evaluate. Evaluate records rule outcomes, but a required workflow or status check that never runs on a repository still needs to be verified there directly.
- Forgetting the status after an incident. Teams often switch a ruleset to disabled during an emergency and never switch it back. Record the change in your incident notes and set a reminder.
- Confusing status with bypass. A bypass actor skips the rules for chosen users. Enforcement applies to everyone. If the problem affects one team, change the bypass list, not the status.
Exercise
Your organisation wants to require one approving review on every default branch. You are worried that some repositories have no reviewers and will be unable to merge. Which enforcement status do you create the ruleset with first, and what do you check before changing it to active?
Show answer
Create it with evaluate. Open the rule insights, filter by the ruleset, and check which repositories and actors would have been blocked by the pull request rule. Fix those cases, for example by adding reviewers or excluding repositories, then change the status to active. Disabled would not work because it records no insight data.