Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions .github/VOUCHED.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Authors whose pull requests get a full kernel build on every push.
#
# A pull request from anyone listed here, or from a repository collaborator,
# builds the package and runs KUnit and the boot test on every push once it
# is out of draft, from a fork too, with no ci:build label needed. Everyone
# else gets the checks only, until a maintainer applies ci:build to that
# pull request. A denouncement is absolute: neither collaborator access nor
# the label builds that author's pull requests.
#
# CI reads this file from the target branch, so a pull request cannot vouch
# for its own author. GitHub still holds the first run of a pull request
# from outside collaborators until a maintainer approves it.
#
# Syntax (the mitchellh/vouch format omacom/omarchy-pkgs uses):
# github:username
# -github:username reason for denouncement
#
# Keep entries sorted alphabetically, ignoring case.
github:Acelogic
github:chriskearney
github:dhh
github:DjDeveloperr
github:emirb
github:erykwieliczko
github:kwilczynski
github:LiamRay11
github:malik-na
github:maralcbr
github:outfoxxed
github:ryanrhughes
github:RyanTheTide
github:scottjones
github:themartiano
20 changes: 19 additions & 1 deletion .github/workflows/kernel-ci-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,27 @@ jobs:
persist-credentials: false
filter: blob:none
sparse-checkout: tools/aurora-ci
# From the target branch, never the pull request: a pull request must
# not vouch for its own author. Without the list (the branch does not
# have one yet, or the API fails) only collaborators are trusted.
- name: Read the vouch list from the target branch
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
if ! gh api -H "Accept: application/vnd.github.raw+json" \
"repos/$GITHUB_REPOSITORY/contents/.github/VOUCHED.td?ref=$BASE_SHA" \
> "$RUNNER_TEMP/VOUCHED.td"; then
: > "$RUNNER_TEMP/VOUCHED.td"
echo "::warning title=Vouch list::no .github/VOUCHED.td at $BASE_SHA; trusting collaborators only"
fi
- name: Plan the run
id: plan
run: python3 -I tools/aurora-ci/plan.py --label "$BUILD_LABEL"
run: |
vouched=()
[[ -f $RUNNER_TEMP/VOUCHED.td ]] && vouched=(--vouched "$RUNNER_TEMP/VOUCHED.td")
python3 -I tools/aurora-ci/plan.py --label "$BUILD_LABEL" "${vouched[@]}"
# Only trees are needed: the build key is made of tree hashes.
- name: Fetch the packaging inputs
if: steps.plan.outputs.tier == 'full'
Expand Down
30 changes: 22 additions & 8 deletions tools/aurora-ci/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ What runs when
==============

Builds take time and, on some runners, money. Pull requests get the checks
that run on free GitHub-hosted runners on every push; the kernel is built
once, in the merge queue, from exactly the tree that will land.
that run on free GitHub-hosted runners on every push; the team's pull
requests are also built on every push, and everyone's kernel is built again
in the merge queue, from exactly the tree that will land.

==================== =================================================
Event Jobs
==================== =================================================
pull request push plan, commits, compile, device trees, host tests,
CI self-test
trusted author push all of the above, then package, KUnit and boot
(not on drafts)
``ci:build`` label all of the above, then package, KUnit and boot
merge queue everything
push to the branch package (reused from the queue), attestation
Expand Down Expand Up @@ -124,12 +127,22 @@ Who can start a build
=====================

Light runs execute a pull request's code on GitHub-hosted runners with a
read-only token, as every public repository's CI does. Full runs start only
from a maintainer action: queueing a pull request, pushing to the branch, a
manual run, or applying ``ci:build`` (which needs triage access). On a branch
of this repository the label applies to every later push; on a fork it
applies to the head it was applied to, and has to be applied again after a
new push.
read-only token, as every public repository's CI does. Full runs start from
a trusted author or a maintainer action:

- a push to a pull request, from a fork too, once it is out of draft, by a
trusted author: a repository collaborator, or anyone vouched for in
``.github/VOUCHED.td``;
- queueing a pull request, pushing to the branch, or a manual run;
- applying ``ci:build`` (which needs triage access). On a branch of this
repository the label applies to every later push; on a fork it applies to
the head it was applied to, and has to be applied again after a new push.

``VOUCHED.td`` lists the team: one ``github:<login>`` per line, sorted.
``-github:<login> <reason>`` denounces an author, which neither collaborator
access nor the label overrides. The plan job reads the list from the target
branch through the API, so a pull request that edits it changes nothing until
it merges. To add someone, open a pull request adding their line.

On a ``pull_request`` event GitHub runs the workflow files from the pull
request itself, so these rules decide cost, not security: a fork could edit
Expand Down Expand Up @@ -160,6 +173,7 @@ Repository setup
These need an administrator:

- a ``ci:build`` label;
- ``.github/VOUCHED.td`` kept to the team (a pull request, like any other);
- branch protection for ``integration/aurora`` requiring ``ci / result``;
- the merge queue (merge method: merge commit), so the tree that merges is
the tree that was tested;
Expand Down
67 changes: 60 additions & 7 deletions tools/aurora-ci/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
pull_request, labeled full when the label is the build label. Applying
a label needs triage access, so this is a
maintainer asking for this exact head commit.
pull_request, other full when the build label is already on a branch
of this repository (only writers can push there);
light for forks, where a new push needs the label
pull_request, other full when the author is trusted and the pull
request is not a draft, from a fork too; full when
the build label is already on a branch of this
repository (only writers can push there); light
for forks, where a new push needs the label
re-applied, and light otherwise.

Trusted authors are repository collaborators and those vouched for in
.github/VOUCHED.td, which the workflow reads from the target branch so that a
pull request cannot vouch for itself. An author denounced there gets light
runs only, whatever their access or labels.
"""

import argparse
Expand All @@ -32,9 +39,43 @@
DEFAULT_LABEL = "ci:build"
ZERO_SHA = "0" * 40
PR_REFRESH_ACTIONS = {"opened", "synchronize", "reopened", "ready_for_review"}
# author_association values that mean write access through the organization
# or the repository.
TRUSTED_ASSOCIATIONS = {"OWNER", "MEMBER", "COLLABORATOR"}
TRUSTED_STATUSES = {"vouched", "collaborator"}


def read_vouched(text):
"""Lower-cased GitHub login -> "vouched" or "denounced", from VOUCHED.td.
A denouncement wins over any vouch for the same login."""
entries = {}
for line in text.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
denounced = line.startswith("-")
platform, _, login = line.lstrip("-").split(None, 1)[0].partition(":")
if platform != "github" or not login:
continue
login = login.lower()
if denounced:
entries[login] = "denounced"
else:
entries.setdefault(login, "vouched")
return entries


def author_status(pr, vouched):
"""denounced, vouched, collaborator or unknown."""
listed = vouched.get((pr.get("user") or {}).get("login", "").lower())
if listed:
return listed
if pr.get("author_association") in TRUSTED_ASSOCIATIONS:
return "collaborator"
return "unknown"


def plan(event_name, event, label=DEFAULT_LABEL):
def plan(event_name, event, label=DEFAULT_LABEL, vouched=None):
"""Return the plan as a dict of strings, ready for $GITHUB_OUTPUT."""
out = {"tier": "light", "reason": "", "base_sha": "", "head_sha": "",
"pr_number": "", "fork": "false", "force": "false"}
Expand All @@ -44,15 +85,24 @@ def plan(event_name, event, label=DEFAULT_LABEL):
action = event.get("action", "")
labels = {item["name"] for item in pr.get("labels", [])}
fork = pr["head"]["repo"] is None or pr["head"]["repo"]["full_name"] != pr["base"]["repo"]["full_name"]
author = (pr.get("user") or {}).get("login", "?")
status = author_status(pr, vouched or {})
out.update(base_sha=pr["base"]["sha"], head_sha=pr["head"]["sha"],
pr_number=str(pr["number"]), fork=str(fork).lower())
if action == "labeled" and event.get("label", {}).get("name") == label:
if status == "denounced":
out["reason"] = f"checks only: {author} is denounced in .github/VOUCHED.td"
elif action == "labeled" and event.get("label", {}).get("name") == label:
out.update(tier="full", reason=f"`{label}` applied to {pr['head']['sha'][:12]}")
elif action in PR_REFRESH_ACTIONS and status in TRUSTED_STATUSES and not pr.get("draft"):
out.update(tier="full", reason=f"{author} is trusted ({status})")
elif action in PR_REFRESH_ACTIONS and label in labels and not fork:
out.update(tier="full", reason=f"`{label}` is on this pull request")
elif action in PR_REFRESH_ACTIONS and label in labels:
out["reason"] = (f"fork pull request: re-apply `{label}` to build "
f"{pr['head']['sha'][:12]}")
elif status in TRUSTED_STATUSES:
out["reason"] = (f"draft: {author}'s builds start when it is ready for review, "
f"or add `{label}` for a build now")
else:
out["reason"] = (f"checks only; the merge queue builds the kernel, or add `{label}` "
"for a build now")
Expand Down Expand Up @@ -81,13 +131,16 @@ def main(argv=None):
parser.add_argument("--event-name", default=os.environ.get("GITHUB_EVENT_NAME"))
parser.add_argument("--event-path", type=Path, default=os.environ.get("GITHUB_EVENT_PATH"))
parser.add_argument("--label", default=DEFAULT_LABEL)
parser.add_argument("--vouched", type=Path,
help="the target branch's VOUCHED.td; without it only collaborators are trusted")
args = parser.parse_args(argv)
if not args.event_name or not args.event_path:
parser.error("--event-name and --event-path (or the GitHub environment) are required")

try:
result = plan(args.event_name, json.loads(args.event_path.read_text()), args.label)
except (KeyError, TypeError, ValueError) as error:
vouched = read_vouched(args.vouched.read_text()) if args.vouched else {}
result = plan(args.event_name, json.loads(args.event_path.read_text()), args.label, vouched)
except (KeyError, TypeError, ValueError, OSError) as error:
print(f"::error title=CI plan::cannot plan this {args.event_name} event: {error!r}", file=sys.stderr)
return 1

Expand Down
93 changes: 91 additions & 2 deletions tools/aurora-ci/tests/test_plan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
import json

from support import TempDirTestCase, load, read_outputs
from support import TREE, TempDirTestCase, load, read_outputs

plan_module = load("plan")
plan = plan_module.plan
Expand All @@ -10,11 +10,15 @@
HEAD = "b" * 40


def pull_request(action, labels=(), fork=False, label=None):
def pull_request(action, labels=(), fork=False, label=None, author="someone",
association="CONTRIBUTOR", draft=False):
event = {
"action": action,
"pull_request": {
"number": 42,
"user": {"login": author},
"author_association": association,
"draft": draft,
"labels": [{"name": name} for name in labels],
"base": {"sha": BASE, "repo": {"full_name": "omacom/linux-aurora"}},
"head": {"sha": HEAD, "repo": {"full_name": "someone/linux-aurora" if fork
Expand Down Expand Up @@ -65,6 +69,81 @@ def test_custom_label(self):
self.assertEqual(plan("pull_request", event, label="build-approved")["tier"], "full")


VOUCHED = """\
# comment
github:Acelogic
github:Teammate
-github:Banned spam
github:banned
-github:Revoked
gitlab:other
"""


class TrustedAuthorTest(TempDirTestCase):
def setUp(self):
super().setUp()
self.vouched = plan_module.read_vouched(VOUCHED)

def test_read_vouched(self):
self.assertEqual(self.vouched, {"acelogic": "vouched", "teammate": "vouched",
"banned": "denounced", "revoked": "denounced"})

def test_vouched_author_builds_every_push_from_a_fork(self):
for action in ("opened", "synchronize", "reopened", "ready_for_review"):
with self.subTest(action=action):
result = plan("pull_request", pull_request(action, fork=True, author="acelogic"),
vouched=self.vouched)
self.assertEqual(result["tier"], "full")
self.assertIn("acelogic is trusted (vouched)", result["reason"])

def test_collaborator_builds_without_being_listed(self):
for association in ("OWNER", "MEMBER", "COLLABORATOR"):
with self.subTest(association=association):
event = pull_request("synchronize", fork=True, association=association)
result = plan("pull_request", event, vouched=self.vouched)
self.assertEqual(result["tier"], "full")
self.assertIn("(collaborator)", result["reason"])

def test_unknown_author_runs_checks_only(self):
for association in ("CONTRIBUTOR", "FIRST_TIME_CONTRIBUTOR", "NONE"):
with self.subTest(association=association):
event = pull_request("synchronize", fork=True, association=association)
self.assertEqual(plan("pull_request", event, vouched=self.vouched)["tier"], "light")

def test_draft_waits_until_ready_for_review(self):
draft = plan("pull_request", pull_request("synchronize", author="Teammate", draft=True),
vouched=self.vouched)
self.assertEqual(draft["tier"], "light")
self.assertIn("ready for review", draft["reason"])
labeled = plan("pull_request", pull_request("labeled", author="Teammate", draft=True,
label="ci:build"), vouched=self.vouched)
self.assertEqual(labeled["tier"], "full")

def test_denouncement_overrides_access_and_label(self):
for event in (pull_request("synchronize", author="banned", association="COLLABORATOR"),
pull_request("labeled", labels=["ci:build"], label="ci:build", author="Revoked"),
pull_request("synchronize", labels=["ci:build"], author="BANNED")):
with self.subTest(event=event):
result = plan("pull_request", event, vouched=self.vouched)
self.assertEqual(result["tier"], "light")
self.assertIn("denounced", result["reason"])

def test_without_a_list_only_collaborators_are_trusted(self):
self.assertEqual(plan("pull_request", pull_request("opened", author="Acelogic"))["tier"], "light")
self.assertEqual(plan("pull_request", pull_request("opened", association="MEMBER"))["tier"], "full")

def test_the_repository_list_is_well_formed(self):
path = TREE / ".github" / "VOUCHED.td"
logins = [line.split(":", 1)[1] for line in path.read_text().splitlines()
if line.startswith("github:")]
self.assertTrue(logins)
self.assertEqual(logins, sorted(logins, key=str.lower))
self.assertEqual(len(logins), len({login.lower() for login in logins}))
self.assertTrue(all(status == "vouched" for status in
plan_module.read_vouched(path.read_text()).values()))
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved


class OtherEventsTest(TempDirTestCase):
def test_merge_group_builds_the_queue_commit(self):
result = plan("merge_group", {"merge_group": {"base_sha": BASE, "head_sha": HEAD}})
Expand Down Expand Up @@ -105,6 +184,16 @@ def test_writes_github_outputs(self):
self.assertEqual(values["head_sha"], HEAD)
self.assertIn("full run", summary.read_text())

def test_reads_the_vouch_list(self):
output, _ = self.github_env()
event = self.tmp / "event.json"
event.write_text(json.dumps(pull_request("synchronize", fork=True, author="Teammate")))
vouched = self.tmp / "VOUCHED.td"
vouched.write_text(VOUCHED)
self.assertEqual(plan_module.main(["--event-name", "pull_request", "--event-path", str(event),
"--vouched", str(vouched)]), 0)
self.assertEqual(read_outputs(output)["tier"], "full")

def test_malformed_event_fails_cleanly(self):
self.github_env()
event = self.tmp / "event.json"
Expand Down
Loading