Merge pull request #8 from evanwhittaker/sync-ci-always-reports
CI always reports a single required check
This commit is contained in:
69
.github/workflows/ci.yml
vendored
69
.github/workflows/ci.yml
vendored
@@ -11,25 +11,18 @@ name: CI
|
||||
# workflow costs three runners (Windows sets the wall clock at ~10 minutes warm). The journal moves
|
||||
# on nearly every iteration, so this is where the minutes actually go.
|
||||
#
|
||||
# Deliberately narrow: only paths that are provably not inputs to the build. Nothing under `crates/`
|
||||
# is listed, and no `.md` in the tree is pulled in with `include_str!` — checked, not assumed. Adding
|
||||
# one later means taking it off this list.
|
||||
# So the workflow always starts, and `changes` (scripts/ci-changes.py) decides whether the jobs
|
||||
# have work; a prose-only change skips them and `CI passed` still reports. That one job is what a
|
||||
# ruleset requires: a required check that never starts, which is what a path filter on the trigger
|
||||
# made of every job here, blocks a merge for good.
|
||||
on:
|
||||
# Re-run the gate on demand — how a timing change to this file gets measured against a warm cache,
|
||||
# and how a run that failed on something external gets another go without an empty commit.
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [master, main]
|
||||
paths-ignore: &prose
|
||||
- "**/*.md"
|
||||
- "docs/**"
|
||||
- ".pi/**"
|
||||
- "LICENSE-*"
|
||||
# Dependabot's own schedule: it decides what gets proposed, never what gets built.
|
||||
- ".github/dependabot.yml"
|
||||
pull_request:
|
||||
branches: [master, main]
|
||||
paths-ignore: *prose
|
||||
|
||||
# Least privilege: CI only needs to read the repo.
|
||||
permissions:
|
||||
@@ -52,8 +45,32 @@ env:
|
||||
CARGO_PROFILE_TEST_DEBUG: line-tables-only
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
name: what changed
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
outputs:
|
||||
code: ${{ steps.diff.outputs.code }}
|
||||
steps:
|
||||
# Full history: the diff is taken from a merge base
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: The classifier's own tests
|
||||
run: python3 scripts/ci_changes_test.py
|
||||
|
||||
# A pull request diffs against its target, a push against the tip it replaced
|
||||
- name: Whether anything but prose changed
|
||||
id: diff
|
||||
run: python3 scripts/ci-changes.py "$BASE" >> "$GITHUB_OUTPUT"
|
||||
env:
|
||||
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
|
||||
|
||||
gate:
|
||||
name: build · test · clippy · fmt
|
||||
needs: changes
|
||||
if: needs.changes.outputs.code == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
# A bound, because the absence of one cost real money. This job's test step has been hanging on
|
||||
# `ubuntu-latest` — the same `cargo nextest run` that takes ~11s locally and passes on the macOS
|
||||
@@ -156,6 +173,8 @@ jobs:
|
||||
# Linux gate. Without this, Windows-only code is the one code path that ships unlinted.
|
||||
portability:
|
||||
name: build · clippy · test (${{ matrix.os }})
|
||||
needs: changes
|
||||
if: needs.changes.outputs.code == 'true'
|
||||
runs-on: ${{ matrix.os }}
|
||||
# Windows sets the wall clock for the whole workflow: ~10 minutes warm and ~15 cold, building,
|
||||
# linting and testing the whole workspace on the slowest runner. This is headroom over that, not
|
||||
@@ -224,6 +243,8 @@ jobs:
|
||||
# trusts that number, and it said 1.85 for months while the dependencies needed 1.88.
|
||||
msrv:
|
||||
name: msrv
|
||||
needs: changes
|
||||
if: needs.changes.outputs.code == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
@@ -242,6 +263,8 @@ jobs:
|
||||
|
||||
supply-chain:
|
||||
name: cargo-deny
|
||||
needs: changes
|
||||
if: needs.changes.outputs.code == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
@@ -266,6 +289,8 @@ jobs:
|
||||
# build should not read as a broken harness.
|
||||
website:
|
||||
name: web build
|
||||
needs: changes
|
||||
if: needs.changes.outputs.code == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
@@ -316,3 +341,25 @@ jobs:
|
||||
- name: Cross-browser (dev server)
|
||||
run: node ../scripts/site-cross.mjs --require webkit
|
||||
working-directory: web
|
||||
|
||||
# The one check a ruleset requires. A skipped job reports as passing but a skipped matrix job
|
||||
# reports under no name a ruleset can hold, so this sums them up: it fails when any job failed or
|
||||
# was cancelled, `changes` included, and passes when each one passed or had nothing to check.
|
||||
passed:
|
||||
name: CI passed
|
||||
needs: [changes, gate, portability, msrv, supply-chain, website]
|
||||
if: always()
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- name: Every job passed or had nothing to check
|
||||
run: |
|
||||
echo "results: $RESULTS"
|
||||
for result in $RESULTS; do
|
||||
case "$result" in
|
||||
success | skipped) ;;
|
||||
*) echo "a job ended $result" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
env:
|
||||
RESULTS: ${{ join(needs.*.result, ' ') }}
|
||||
|
||||
3
.github/workflows/site.yml
vendored
3
.github/workflows/site.yml
vendored
@@ -10,8 +10,7 @@ on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
# The site reads `docs/guide/` for the manual, which CI's prose filter skips, so a guide-only
|
||||
# change still has to reach here
|
||||
# The site reads `docs/guide/` for the manual, so a guide-only change has to reach here
|
||||
paths:
|
||||
- "web/**"
|
||||
- "docs/guide/**"
|
||||
|
||||
6
.github/workflows/version.yml
vendored
6
.github/workflows/version.yml
vendored
@@ -1,8 +1,8 @@
|
||||
# Version — a pull request that changes what ships bumps the version by one semver step.
|
||||
#
|
||||
# Its own workflow, with no path filter, so it can be a required check: CI skips prose-only pull
|
||||
# requests, and a required check that never starts blocks the merge forever. Whether a bump is owed
|
||||
# is the script's call, from the diff. See scripts/version-check.py for the rules.
|
||||
# Its own workflow, with no path filter, so it can be a required check beside `CI passed`: a
|
||||
# required check that never starts blocks the merge forever. Whether a bump is owed is the script's
|
||||
# call, from the diff. See scripts/version-check.py for the rules.
|
||||
name: Version
|
||||
|
||||
on:
|
||||
|
||||
56
scripts/ci-changes.py
Normal file
56
scripts/ci-changes.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""ci-changes — whether a pull request touched anything CI has to build.
|
||||
|
||||
Pull-request CI always runs so it can be a required check; a required check that never starts
|
||||
blocks the merge for good. This decides whether the jobs have work: prose cannot change what the
|
||||
compiler, the suite or the site says, so a prose-only change skips them and reports a pass.
|
||||
|
||||
Prose is only what is provably not an input: Markdown, `docs/`, `.pi/`, the licenses and
|
||||
Dependabot's schedule, except that nothing under `crates/` counts (`luxe-cli` compiles its bundled
|
||||
`guide.md` in) and neither does `docs/guide/`, which the suite checks against the code and the site
|
||||
renders.
|
||||
|
||||
Usage: scripts/ci-changes.py [base-sha] prints `code=true|false` for $GITHUB_OUTPUT.
|
||||
|
||||
When there is nothing to diff against, the jobs run: no base (a run by hand), the all-zero base a
|
||||
push of a new branch reports, or a base the history no longer holds after a force-push. Skipping
|
||||
has to be proven; running never needs to be.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
PROSE = re.compile(r"\.md$|^docs/|^\.pi/|^LICENSE-|^\.github/dependabot\.yml$")
|
||||
INPUTS_AMONG_PROSE = re.compile(r"^crates/|^docs/guide/")
|
||||
|
||||
|
||||
def is_input(path: str) -> bool:
|
||||
"""Whether a change to `path` can change what CI reports."""
|
||||
return bool(INPUTS_AMONG_PROSE.search(path)) or not PROSE.search(path)
|
||||
|
||||
|
||||
def changed_since(base: str) -> list[str] | None:
|
||||
"""The paths changed since HEAD's merge base with `base`, or `None` when that cannot be said."""
|
||||
if re.fullmatch(r"0*", base):
|
||||
return None
|
||||
diff = ["git", "diff", "--name-only", f"{base}...HEAD"]
|
||||
result = subprocess.run(diff, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
print(f"ci-changes: {' '.join(diff)} failed, so everything runs: {result.stderr.strip()}",
|
||||
file=sys.stderr)
|
||||
return None
|
||||
return result.stdout.split()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
changed = changed_since(sys.argv[1] if len(sys.argv) > 1 else "")
|
||||
code = changed is None or any(is_input(path) for path in changed)
|
||||
print(f"code={str(code).lower()}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
52
scripts/ci_changes_test.py
Normal file
52
scripts/ci_changes_test.py
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests for ci-changes.py. Run: python3 scripts/ci_changes_test.py"""
|
||||
|
||||
import importlib.util
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
# The script's name has a hyphen, like its neighbors, so it is loaded by path rather than imported
|
||||
SPEC = importlib.util.spec_from_file_location("ci_changes", Path(__file__).with_name("ci-changes.py"))
|
||||
assert SPEC and SPEC.loader, "ci-changes.py sits beside this file"
|
||||
cc: Any = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(cc)
|
||||
|
||||
|
||||
class IsInput(unittest.TestCase):
|
||||
def test_prose_is_not(self):
|
||||
for path in ["README.md", "CHANGELOG.md", "docs/brand/voice.md", ".pi/x.txt", "LICENSE-MIT",
|
||||
".github/dependabot.yml"]:
|
||||
with self.subTest(path):
|
||||
self.assertFalse(cc.is_input(path))
|
||||
|
||||
def test_markdown_the_build_or_suite_reads_is(self):
|
||||
# luxe-cli compiles its guide bundle in; the suite checks docs/guide against the code
|
||||
for path in ["crates/luxe-cli/guide.md", "crates/luxe-core/README.md", "docs/guide/index.md"]:
|
||||
with self.subTest(path):
|
||||
self.assertTrue(cc.is_input(path))
|
||||
|
||||
def test_everything_else_is(self):
|
||||
for path in ["crates/luxe-core/src/lib.rs", "Cargo.lock", "web/src/pages/index.astro",
|
||||
".github/workflows/ci.yml", "scripts/ci-changes.py", "docs.rs", "mdbook.toml"]:
|
||||
with self.subTest(path):
|
||||
self.assertTrue(cc.is_input(path))
|
||||
|
||||
|
||||
class NothingToDiff(unittest.TestCase):
|
||||
"""Skipping has to be proven: without a base to diff against, everything runs."""
|
||||
|
||||
def test_no_base_or_a_new_branch_cannot_be_diffed(self):
|
||||
for base in ["", "0000000000000000000000000000000000000000"]:
|
||||
with self.subTest(base):
|
||||
self.assertIsNone(cc.changed_since(base))
|
||||
|
||||
def test_a_base_the_history_lacks_cannot_be_diffed(self):
|
||||
self.assertIsNone(cc.changed_since("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"))
|
||||
|
||||
def test_a_real_base_lists_what_changed(self):
|
||||
self.assertIsInstance(cc.changed_since("HEAD"), list)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user