Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Every repository gets the same rulesets, defined in `rulesets/`:
- `branches`: the protected branches only change through a reviewed pull request with signed commits.
- `fork-only`: nobody creates or pushes other branches in the repository, so pull requests come from forks. Renovate is the exception.
- `tags` or `no tags`: only release managers create tags, or nobody does.
- `required-checks` (where `repos.toml` lists checks): the named CI jobs must pass before a merge. Only results reported by GitHub Actions count, so a status with the same name posted by a token or another app is ignored.
- `required-checks` (where `repos.toml` lists checks): the named CI jobs must pass before a merge. Only results reported by GitHub Actions count, so a status with the same name posted by a token or another app is ignored. Repository admins can bypass it when merging a pull request ("Merge without waiting for requirements"), and only then: a security advisory's pull requests come from a temporary private fork where GitHub Actions does not run, so their checks never report.

The `branches` ruleset also asks for the approval of a code owner. This only has an effect in repositories with a `CODEOWNERS` file; a one-line file such as `/.github/ @DIRACGrid/dirac-release-manager` makes every workflow change go through a release manager.

What differs per repository (protected branches, whether it has releases, required checks) is in `rulesets/repos.toml`. The same file names the accounts the templates refer to (`[actors]`: Renovate, the release managers' team, GitHub Actions).
What differs per repository (protected branches, whether it has releases, required checks) is in `rulesets/repos.toml`. The same file names the accounts the templates refer to (`[actors]`: Renovate, the release managers' team, GitHub Actions, the repository admin role). A template lists an actor by name, or as `{"actor": name, "bypass_mode": "pull_request"}` for a bypass that only applies when merging a pull request..

```bash
scripts/rulesets.py # show what differs on GitHub, for every repository
Expand Down
6 changes: 6 additions & 0 deletions rulesets/repos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ dirac-release-manager = { actor_type = "Team", actor_id = 52350 }
# The GitHub Actions app. Required checks are pinned to it, so a status with the
# same name posted by anything else (a token, another app) does not count.
github-actions = { actor_type = "Integration", actor_id = 15368 }
# The built-in admin role of each repository: bypasses `required-checks`, in pull
# requests only. A security advisory's pull requests come from a temporary private
# fork where GitHub Actions does not run, so their required checks never report.
# The admin merges them with "Merge without waiting for requirements"; the bypass
# is logged in the ruleset's insights. Pushes to the protected branches stay blocked.
repository-admin = { actor_type = "RepositoryRole", actor_id = 5 }

[repos.".github"]
required_checks = ["pre-commit"]
Expand Down
4 changes: 3 additions & 1 deletion rulesets/required-checks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
}
}
],
"bypass_actors": []
"bypass_actors": [
{"actor": "repository-admin", "bypass_mode": "pull_request"}
]
}
8 changes: 6 additions & 2 deletions scripts/rulesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ def render(params: dict, default_branch: str, actors: dict) -> dict[str, dict]:
]
rulesets.append(required)

# A template names an actor, or gives {"actor": name, "bypass_mode": mode}
# for a mode other than "always" ("pull_request": only when merging a PR).
for ruleset in rulesets:
ruleset["bypass_actors"] = [
{**actors[name], "bypass_mode": "always"}
for name in ruleset["bypass_actors"]
{**actors[entry], "bypass_mode": "always"}
if isinstance(entry, str)
else {**actors[entry["actor"]], "bypass_mode": entry["bypass_mode"]}
for entry in ruleset["bypass_actors"]
]
return {r["name"]: r for r in rulesets}

Expand Down
16 changes: 16 additions & 0 deletions scripts/test_rulesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"renovate": {"actor_type": "Integration", "actor_id": 2740},
"dirac-release-manager": {"actor_type": "Team", "actor_id": 52350},
"github-actions": {"actor_type": "Integration", "actor_id": 15368},
"repository-admin": {"actor_type": "RepositoryRole", "actor_id": 5},
}


Expand Down Expand Up @@ -81,6 +82,21 @@ def test_required_checks_are_pinned_to_github_actions(self):
self.assertFalse(pull_request["parameters"]["require_code_owner_review"])
self.assertNotIn("required-checks", render({}, "main"))

def test_admins_bypass_required_checks_in_pull_requests_only(self):
# Security advisory PRs come from a private fork where Actions does not run.
wanted = render({"required_checks": ["pre-commit"]}, "main")
self.assertEqual(
wanted["required-checks"]["bypass_actors"],
[
{
"actor_type": "RepositoryRole",
"actor_id": 5,
"bypass_mode": "pull_request",
}
],
)
self.assertEqual(wanted["branches"]["bypass_actors"], [])

def test_equivalent_live_ruleset_is_not_drift(self):
wanted = render({}, "main")["branches"]
live = {
Expand Down