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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ GitHub-hosted minutes cost nothing for public repositories, and a self-hosted ru
1. **Public repositories run on GitHub-hosted runners only.** They never name a self-hosted label, a Blacksmith label, or the runner picker.
2. **Private and internal repositories ask the runner picker for every job that builds, tests or deploys.** The picker job runs on `ubuntu-slim` and the consuming job reads its `runs-on` output, with a fallback for when the picker gives no answer.
3. **One action, one pin.** The picker is `barretotech/runner-picker`, pinned to a full commit SHA with its release tag as a comment, and called with `source: service`, `capacity-url: ${{ vars.RUNNER_CAPACITY_URL }}` and `tailnet-client-id: ${{ vars.TAILNET_CLIENT_ID_PICKER }}`.
4. **Overflow order per platform.** Linux offers `"blacksmith-2vcpu-ubuntu-2404"` as `overflow` and `"ubuntu-latest"` as `hosted`. Windows offers `"windows-latest"` with `weight: 2` and no Blacksmith runner. macOS offers `"macos-latest"` with `weight: 10`.
4. **Overflow order per platform.** Linux offers `"blacksmith-2vcpu-ubuntu-2404"` as `overflow`. Its GitHub-hosted offer and billing weight come from organization variables, with standard-runner defaults:

```yaml
hosted: ${{ vars.HOSTED_LINUX_RUNNER || '"ubuntu-latest"' }}
weight: ${{ vars.HOSTED_LINUX_WEIGHT || 1 }}
```

`HOSTED_LINUX_RUNNER` is a JSON string or array, as required by runner-picker v1.0.0; `HOSTED_LINUX_WEIGHT` is a positive integer. An organization with a 4-core Ubuntu larger runner named `ubuntu-4core` sets them to `"ubuntu-4core"` (including the JSON quotes) and `2`. The runner must be accessible to the consuming repositories. Values must match the picker's input validation: a JSON string or nonempty label array for the runner, and an integer from 1 to 999999 for the weight. A bare `ubuntu-4core` without JSON quotes, or a weight such as `0`, `2.0` or `2`, produces an error annotation but a successful picker step with self-hosted fallback: hosted overflow is lost and the job waits for the pool. Keep the JSON form to support both string and array targets. Organizations without that runner leave both unset. This applies to the picker's `hosted` offer; the consuming job's no-answer fallback is a separate choice.

The picker sends `weight` to ci-capacity, which allows GitHub-hosted only when `remaining - weight × JOB_MINUTES >= RESERVE_MINUTES`: with the defaults of 30 estimated job minutes and a 5,000-minute reserve, weight 2 requires at least 5,060 remaining minutes. This is an admission estimate, not a minute reservation; billing ingestion counts usage separately. **A Linux weight other than 1 requires ci-capacity's usage ledger to apply the same price ratio to the corresponding hosted SKU before routing jobs to it.** For `ubuntu-4core`, ingestion must count each `linux_4_core` minute as 2 standard Linux minutes. Until that accounting is deployed and verified, keep the standard Linux hosted offer and weight 1. Setting the organization variables alone does not satisfy this prerequisite. A ledger that counts 4-core minutes at 1 overstates the enterprise-wide remaining allowance, so the admission arithmetic cannot protect the 5,000-minute reserve for any organization. Blacksmith checks its own label-derived rate independently.

Windows offers `"windows-latest"` with `weight: 2` and no Blacksmith runner. macOS offers `"macos-latest"` with `weight: 10`.

5. **Jobs that take seconds run on `ubuntu-slim` directly.** Examples are commit lint, an Archgate check on its own, notifications and the picker job itself.
6. **A job whose purpose is the self-hosted machine itself targets its label directly**, such as warming or probing a self-hosted cache, or a deploy that only the private network can reach. The line before its `runs-on` carries `# runner-picker: exempt - <reason>`.
7. **A routed job behaves the same on every runner it can land on.** A routed job that can run on Linux lifts the hosted images' user-namespace restriction in its first step, on GitHub-hosted Linux only:
Expand Down Expand Up @@ -90,6 +102,7 @@ The companion rules read every workflow and every composite action (`action.yml`
- `picker-pin`: any `runner-picker` action, with or without a subpath, is `barretotech/runner-picker@<40-hex SHA>`.
- `picker-service`: each picker step's `with:` sets `source: service`, `capacity-url: ${{ vars.RUNNER_CAPACITY_URL }}` and `tailnet-client-id: ${{ vars.TAILNET_CLIENT_ID_PICKER }}`.
- `routed-runs-on`: each unit of a job's `runs-on` (the string, each list label, each `group`/`labels` field), each input of a reusable-workflow call, and each matrix value it reads is checked on its own; a unit that names a self-hosted, `tatuicloud*` or `blacksmith-*` label or a `vars.*RUNNER` or `vars.*RUNNER_*` variable (dotted or `vars['...']`) takes its runner from picker jobs: it reads at least one `needs.<job>.outputs.runs-on`, each such `<job>` is in the job's `needs`, forwards its picker step's output as `outputs.runs-on: ${{ steps.<id>.outputs.runs-on }}`, and has an `if:` that is absent or reads context (a constant one such as `true`, `false` or `${{ 1 > 2 }}` either never runs or guards nothing, so it does not count), no pool label or runner variable comes before the first of them, and each is followed by a `||` fallback and is neither combined with `&&` nor compared, in or out of parentheses. Only the output named exactly `runs-on` counts. Matrix values read by `matrix.<key>` or `matrix['<key>']`, and a matrix built by an expression, are checked too. Any job reading a picker output needs that fallback, pool or not. `needs.<job>.outputs['runs-on']` reads the same output. A matrix job may read one picker per leg, and a matrix value may carry a picker output; a matrix value that names the pool without one is a label used directly. The exemption marker on the line before a block `runs-on:` key waives it; a job written as a flow mapping cannot be exempt. A workflow that does not parse as YAML is a violation, and the other files are still checked.
- `picker-service` (Linux hosted inputs): every picker whose self-hosted labels do not identify only Windows or macOS sets `hosted: ${{ vars.HOSTED_LINUX_RUNNER || '"ubuntu-latest"' }}` and `weight: ${{ vars.HOSTED_LINUX_WEIGHT || 1 }}`. Omitted platform labels default to Linux. If `self-hosted` is a direct matrix reference (for example `${{ matrix.labels }}` or `${{ matrix['labels'] }}`), the rule skips the two Linux-specific checks because it cannot resolve the platform; source, capacity URL and tailnet identity are still enforced. Review such pickers at the call site: each Linux matrix leg supplies the organization-variable expressions above, while Windows and macOS legs retain their platform offers and weights. Other expressions, including `${{ vars.LINUX_LABELS }}` and literal Linux labels wrapped in an expression, still require both Linux inputs. Both inputs are enforced together, including in composite actions.
- `hosted-userns`: a job that reads a picker's `runs-on` output, in its `runs-on` or a matrix value it reads, and has a unit that does not name only Windows or macOS runners, has a first step whose `run` holds `sysctl -w kernel.apparmor_restrict_unprivileged_userns=0`. A reusable-workflow call is not checked; the called workflow's jobs are.
- `public-hosted-only`: `.archgate/repository.json` records the repository's visibility (`public`, `private` or `internal`), and a missing file, invalid JSON or an unknown visibility is a violation, each reported as such. In a public repository, no step uses a runner picker and no job targets a self-hosted or Blacksmith runner or a runner group, exempt or not. A change to the visibility record re-checks every workflow. The enterprise-adrs Sync workflow writes the file from GitHub's record of the repository.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference path="../rules.d.ts" />

/** The one picker action the enterprise uses. */
const PICKER_ACTION = "barretotech/runner-picker";
/** Any runner-picker action reference, with or without a subpath: owner, repository, subpath, ref. */
Expand Down Expand Up @@ -31,6 +30,11 @@ const REQUIRED_INPUTS: readonly (readonly [string, RegExp])[] = [
["source", /^service$/u],
["capacity-url", /^\$\{\{\s*vars\.RUNNER_CAPACITY_URL\s*\}\}$/u],
["tailnet-client-id", /^\$\{\{\s*vars\.TAILNET_CLIENT_ID_PICKER\s*\}\}$/u],
[
"hosted",
/^\$\{\{\s*vars\.HOSTED_LINUX_RUNNER\s*\|\|\s*'"ubuntu-latest"'\s*\}\}$/u,
],
["weight", /^\$\{\{\s*vars\.HOSTED_LINUX_WEIGHT\s*\|\|\s*1\s*\}\}$/u],
];
/** The command that lifts the hosted Ubuntu images' AppArmor block on unprivileged user namespaces. */
const USERNS = /sysctl\s+-w\s+kernel\.apparmor_restrict_unprivileged_userns=0/u;
Expand Down Expand Up @@ -78,7 +82,6 @@ function strings(value: Yaml | undefined): string[] {
return Object.values(value).flatMap((item) => strings(item));
return value === null || value === undefined ? [] : [String(value)];
}

/** The indentation of a line. */
const indentOf = (line: string): number =>
line.length - line.trimStart().length;
Expand All @@ -92,12 +95,10 @@ function keyOf(line: string): string | undefined {
? text.slice(0, colon).replaceAll(/^["']|["']$/gu, "")
: undefined;
}

/** A key whose value is a block scalar (`run: |`, `script: >-`). */
const BLOCK_SCALAR = /:\s*[|>](?:[+-]\d?|\d[+-]?)?\s*(?:#.*)?$/u;
/** A quoted value that opens on a line: the text from its opening quote on. */
const QUOTED_VALUE = /(?:^|:\s+|-\s+)(["'])(.*)$/u;

/** Whether `text`, inside a scalar quoted with `quote`, contains the closing quote. */
function closes(text: string, quote: string): boolean {
for (let index = 0; index < text.length; index++) {
Expand All @@ -109,7 +110,6 @@ function closes(text: string, quote: string): boolean {
}
return false;
}

/** Which lines are YAML structure rather than the inside of a block or multi-line quoted scalar. */
function structural(lines: string[]): boolean[] {
let block: number | undefined;
Expand All @@ -128,7 +128,6 @@ function structural(lines: string[]): boolean[] {
return !blank;
});
}

/** A token of a literal-only expression: literals, operators and parentheses. */
const TOKEN =
/\s*(?:\(|\)|==|!=|<=|>=|<|>|&&|\|\||!|true\b|false\b|null\b|-?\d+(?:\.\d+)?|'(?:[^']|'')*')/uy;
Expand Down Expand Up @@ -432,7 +431,7 @@ export default {
rules: {
"picker-pin": {
description:
"Runner pickers are barretotech/runner-picker pinned to a full commit SHA",
"Runner pickers use the enterprise action pinned to a full SHA",
async check(ctx) {
for (const step of (await load(ctx)).steps) {
const match = PICKER_REF.exec(step.uses);
Expand All @@ -459,23 +458,30 @@ export default {
async check(ctx) {
for (const step of (await load(ctx)).steps) {
if (!PICKER_REF.test(step.uses)) continue;
const labels = strings(step.with["self-hosted"]).join(" ");
// Direct matrix platform references need call-site review; other expressions stay checked.
const skipLinux =
/^\$\{\{\s*matrix(?:\.[\w-]+|\[\s*['"][\w-]+['"]\s*\])\s*\}\}$/u.test(
labels
) || notLinux(labels);
for (const [input, expected] of REQUIRED_INPUTS) {
if (skipLinux && (input === "hosted" || input === "weight"))
continue;
const value = step.with[input];
if (typeof value !== "string" || !expected.test(value.trim())) {
ctx.report.violation({
message: `The runner picker step's \`with: ${input}\` is not set as the ci-runners ADR requires`,
file: step.file,
line: step.line,
fix: "Under the step's `with:`, set `source: service`, `capacity-url: ${{ vars.RUNNER_CAPACITY_URL }}` and `tailnet-client-id: ${{ vars.TAILNET_CLIENT_ID_PICKER }}`",
fix: `Set \`${input}\` as shown in Decisions 3 and 4 of the ci-runners ADR`,
});
}
}
}
},
},
"routed-runs-on": {
description:
"Jobs reach the shared pool or Blacksmith only through a picker job's output, unless marked exempt",
description: "Pool jobs use a needed picker output, unless exempt",
async check(ctx) {
const { jobs, unreadable } = await load(ctx);
for (const { file, error } of unreadable) {
Expand Down Expand Up @@ -503,7 +509,7 @@ export default {
},
"hosted-userns": {
description:
"A job that can land on a GitHub-hosted Linux runner lifts the user-namespace restriction first",
"Routed Linux jobs lift the hosted user-namespace restriction",
async check(ctx) {
for (const job of (await load(ctx)).jobs) {
const picked = job.units.some((unit) => unit.search(OUTPUT_REF) >= 0);
Expand All @@ -518,8 +524,7 @@ export default {
},
},
"public-hosted-only": {
description:
"A public repository uses neither the runner picker nor a self-hosted or Blacksmith runner",
description: "Public repositories use GitHub-hosted runners only",
async check(ctx) {
const record = await visibilityOf(ctx);
if ("problem" in record) {
Expand Down
6 changes: 3 additions & 3 deletions .archgate/imports.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"imports": [
{
"source": "archgate/enterprise-adrs/packs/ci-runners",
"version": "1.3.1",
"importedAt": "2026-11-11T22:33:45.003Z",
"source": "BarretoTech/enterprise-adrs/packs/ci-runners",
"version": "1.4.0",
"importedAt": "2026-11-21T13:28:24.194Z",
"adrIds": ["ARCH-027"]
}
]
Expand Down