Sub topic 14
Rolling out safely and reviewing rule insights
This chapter assumes you can create an organisation ruleset, read its JSON, and call the REST API with gh. A new ruleset can block merges in every repository it targets, so you should test it before you enforce it.
Why a staged rollout matters
An organisation ruleset takes effect across many repositories at once. A rule that suits one team can stop another team's release. Common causes are a required status check that only some repositories produce, or a required review that a small team cannot meet. A staged rollout lets you find these problems while nothing is blocked.
The rollout sequence
Use the three enforcement statuses in order:
- Create the ruleset with
enforcementset toevaluate. Nothing is blocked. GitHub records what the rules would have done. - Review the results in rule insights. Fix the ruleset, or talk to affected teams.
- Change
enforcementtoactivewhen the results look right. - Set it to
disabledif you need to switch it off without deleting it.
Reading rule insights
Rule insights is a page under the organisation's Settings, then Rules, then Insights. It lists each time a rule was checked against a push or pull request. You can filter by:
- ruleset
- repository
- branch or tag
- the person or app that acted
- time period
- result: pass, fail, or bypass
In evaluate mode, a failure means the action would have been blocked if the ruleset were active. Check these things before you enforce:
- Repeated failures in one repository. That repository may be missing a required check name or workflow. Fix the repository or exclude it.
- Failures by automation. Bots such as dependency updaters often push in ways that humans do not. Decide whether they need a bypass or a different workflow.
- Bypass entries. Each one shows who skipped the rules. Confirm that these people are the ones you meant to allow. If many bypasses are routine, the rules may be too strict.
Changing the status with the API
You can script the switch. First list the rulesets to find the ID:
gh api /orgs/YOUR_ORG/rulesets --jq '.[] | {id, name, enforcement}'Then update only the enforcement field:
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
/orgs/YOUR_ORG/rulesets/RULESET_ID \
-f enforcement=activeRun the same call with -f enforcement=evaluate to go back to testing. Keeping the JSON file in version control means each change to a ruleset gets reviewed like code.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Going straight to `active` | Teams find blocked merges first | Run `evaluate` and review insights |
| Reviewing insights too soon | Too little traffic to show problems | Wait for a normal working cycle, such as a full week |
| Ignoring other rulesets | Overlapping rules stack, so results differ from what you expect | Check the other rulesets on the same branch |
| Leaving a ruleset in evaluate mode | It looks protected but blocks nothing | Set a date to decide, then move to `active` |
Exercise
You created an organisation ruleset in evaluate mode. Rule insights show 40 failures for the required workflow, all from one repository that has no org-ci.yml setup. What should you do before switching to active, and why?
Show answer
Fix that repository or exclude it from the ruleset's repository targeting before enabling. In active mode the same 40 events would be blocked merges. Then check the insights again to confirm the failures are gone, and switch enforcement to active.