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
35 changes: 35 additions & 0 deletions .github/VOUCHED.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Authors whose pull requests get a full kernel build on every push.
#
# The kernel team. A pull request from anyone listed here 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, as long as whoever pushed
# is listed too. Everyone else, omacom
# organization members and repository collaborators included, gets the
# checks only until a maintainer applies ci:build to that pull request. CI
# never builds a denounced author's pull requests, label or not.
#
# CI reads this file from the target branch, so a pull request cannot vouch
# for its own author. GitHub holds pull request runs from outside
# collaborators; kernel-ci-approve.yml releases them for those listed here.
#
# 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:joshuaswarren
github:kwilczynski
github:LiamRay11
github:malik-na
github:maralcbr
github:outfoxxed
github:ryanrhughes
github:RyanTheTide
github:scottjones
github:themartiano
48 changes: 48 additions & 0 deletions .github/workflows/kernel-ci-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# GitHub holds every pull request run from outside collaborators until a
# maintainer approves it. This releases the kernel CI run of a pull request
# whose author is vouched for in .github/VOUCHED.td, so the team's outside
# collaborators build like everyone else on the team. Anyone else's run stays
# held for a maintainer. tools/aurora-ci/README.rst, "Who can start a build".

name: Kernel CI (approve vouched authors)

on:
# pull_request_target runs the target branch's workflow, and this job only
# fetches the target branch's files: no pull request code ever runs here,
# with or without the write token.
pull_request_target: # zizmor: ignore[dangerous-triggers] no checkout; target-branch code only
branches: [integration/aurora]
types: [opened, synchronize, reopened, ready_for_review]

permissions: {}

concurrency:
group: kernel-ci-approve-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
approve:
name: approve
# Organization members' and collaborators' runs are never held.
if: ${{ !contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) }}
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
actions: write # approve the held kernel CI run
contents: read # read the target branch's tools and vouch list
pull-requests: read # recheck the pull request's head before approving
steps:
# github.sha is the target branch's tip on pull_request_target.
- name: Fetch the target branch's tools and vouch list
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir -p "$RUNNER_TEMP/tools"
for file in tools/aurora-ci/plan.py tools/aurora-ci/approve-runs.py .github/VOUCHED.td; do
gh api -H "Accept: application/vnd.github.raw+json" \
"repos/$GITHUB_REPOSITORY/contents/$file?ref=$GITHUB_SHA" > "$RUNNER_TEMP/tools/${file##*/}"
done
- name: Approve the run of a vouched author
env:
GITHUB_TOKEN: ${{ github.token }}
run: python3 -I "$RUNNER_TEMP/tools/approve-runs.py" --vouched "$RUNNER_TEMP/tools/VOUCHED.td"
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) no author is 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; no author is trusted"
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
5 changes: 3 additions & 2 deletions .github/workflows/kernel-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# locally: tools/aurora-ci/README.rst.
#
# pull request checks only (commit hygiene, host test suites, the CI's
# own tests), on every push; add the ci:build label for a
# build now (kernel-ci-label.yml)
# own tests), on every push; everything for the team
# (.github/VOUCHED.td) once out of draft; add the ci:build
# label for a build now (kernel-ci-label.yml)
# merge queue everything: the kernel package built with omarchy-pkgs'
# own recipe, KUnit, a QEMU boot that loads every module,
# and a comparison with the target branch's package
Expand Down
43 changes: 34 additions & 9 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,32 @@ 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
anyone vouched for in ``.github/VOUCHED.td`` (the kernel team), when the
pusher is vouched for too. Access to the repository or the omacom
organization alone does not count;
- 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 the label does not
override. 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.

GitHub holds every run of a pull request from an outside collaborator until
a maintainer approves it. ``kernel-ci-approve.yml`` (``approve-runs.py``)
releases the held ``kernel-ci.yml`` run of the current head when the author
is vouched for, so they need no clicks either. It runs on
``pull_request_target`` and fetches only the target branch's files; no pull
request code runs with its write token. Anyone else's runs stay held, and
once approved they run the checks only unless a maintainer applies
``ci:build``.

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,10 +183,12 @@ 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;
- workflow approval for outside collaborators (Settings, Actions, General);
- workflow approval for all outside collaborators (Settings, Actions,
General), which ``kernel-ci-approve.yml`` relies on;
- optionally ``KERNEL_CI_RUNNER`` for faster builds.

Running the tools locally
Expand Down
118 changes: 118 additions & 0 deletions tools/aurora-ci/approve-runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
"""Release the held kernel CI run of a pull request by a vouched-for author.

GitHub holds every pull_request run from outside collaborators until a
maintainer approves it. kernel-ci-approve.yml runs this on
pull_request_target, from the target branch's code, never the pull
request's: when the author and the pusher are vouched for in
.github/VOUCHED.td it approves the held kernel-ci.yml run of the pull request's current head, and plan.py then
decides what that run does. Organization members' and collaborators' runs
are never held; anyone else's stay held for a maintainer.
"""

import argparse
import importlib.util
import json
import os
import sys
import time
import urllib.parse
import urllib.request
from pathlib import Path

WORKFLOW = ".github/workflows/kernel-ci.yml"
HELD = "action_required"


def load_plan():
path = Path(__file__).resolve().parent / "plan.py"
spec = importlib.util.spec_from_file_location("plan", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


class Api:
def __init__(self, url, repository, token):
self.url, self.repository, self.token = url.rstrip("/"), repository, token

def request(self, method, path, **query):
address = f"{self.url}/repos/{self.repository}/{path}"
if query:
address += "?" + urllib.parse.urlencode(query)
request = urllib.request.Request(address, method=method, headers={
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {self.token}",
"X-GitHub-Api-Version": "2022-11-28",
})
with urllib.request.urlopen(request, timeout=60) as response:
body = response.read()
return json.loads(body) if body else {}

def get(self, path, **query):
return self.request("GET", path, **query)

def post(self, path):
return self.request("POST", path)


def held(run):
return HELD in (run.get("status"), run.get("conclusion"))


def approve(api, event, vouched, plan, attempts=36, sleep=time.sleep):
"""Approve the newest held kernel-ci.yml run of the pull request's head.
Returns a sentence saying what happened."""
pr = event["pull_request"]
status, author = plan.trust(event, vouched)
if status != "vouched":
return f"{author} is {status}: nothing to approve"
number, head_sha = pr["number"], pr["head"]["sha"]
head_repo = (pr["head"].get("repo") or {}).get("id")

for attempt in range(attempts):
if attempt:
sleep(5)
current = api.get(f"pulls/{number}")
if current.get("state") != "open" or current["head"]["sha"] != head_sha:
return f"#{number} closed or moved past {head_sha[:12]}: nothing to approve"
data = api.get("actions/runs", event="pull_request", head_sha=head_sha, per_page=100)
runs = sorted((run for run in data.get("workflow_runs", [])
if run.get("path") == WORKFLOW and run.get("head_sha") == head_sha
and (run.get("head_repository") or {}).get("id") == head_repo),
key=lambda run: run["id"])
if not runs:
continue # GitHub creates the pull_request run alongside this one
newest = runs[-1]
if not held(newest):
return f"run {newest['id']} for {head_sha[:12]} is not held"
api.post(f"actions/runs/{newest['id']}/approve")
return f"approved run {newest['id']} for {author} ({status}) at {head_sha[:12]}"
raise TimeoutError(f"no {WORKFLOW} run for {head_sha[:12]} appeared")


def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--event-path", type=Path, default=os.environ.get("GITHUB_EVENT_PATH"))
parser.add_argument("--vouched", type=Path, required=True, help="the target branch's VOUCHED.td")
args = parser.parse_args(argv)

plan = load_plan()
api = Api(os.environ.get("GITHUB_API_URL", "https://api.github.com"),
os.environ["GITHUB_REPOSITORY"], os.environ["GITHUB_TOKEN"])
try:
result = approve(api, json.loads(args.event_path.read_text()),
plan.read_vouched(args.vouched.read_text()), plan)
except (OSError, KeyError, TypeError, ValueError) as error:
print(f"::error title=Approve kernel CI::{error!r}", file=sys.stderr)
return 1
print(result)
if os.environ.get("GITHUB_STEP_SUMMARY"):
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as out:
out.write(f"{result}.\n")
return 0


if __name__ == "__main__":
sys.exit(main())
Loading
Loading