CI always starts and reports one CI passed check a ruleset can require; a prose-only change skips the jobs inside the run instead of skipping the run
A path filter on the trigger meant a docs-only pull request never got the checks a ruleset would require, so it could never merge. scripts/ci-changes.py decides from the diff whether the jobs have work, and CI passed sums them up, since a skipped matrix job reports under no name a ruleset can hold. The old filter also skipped crates/luxe-cli/guide.md, which the CLI compiles in, and docs/guide/, which the suite checks against the code; both now run the jobs.
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
|
# 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.
|
# 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/`
|
# So the workflow always starts, and `changes` (scripts/ci-changes.py) decides whether the jobs
|
||||||
# is listed, and no `.md` in the tree is pulled in with `include_str!` — checked, not assumed. Adding
|
# have work; a prose-only change skips them and `CI passed` still reports. That one job is what a
|
||||||
# one later means taking it off this list.
|
# 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:
|
on:
|
||||||
# Re-run the gate on demand — how a timing change to this file gets measured against a warm cache,
|
# 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.
|
# and how a run that failed on something external gets another go without an empty commit.
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [master, main]
|
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:
|
pull_request:
|
||||||
branches: [master, main]
|
branches: [master, main]
|
||||||
paths-ignore: *prose
|
|
||||||
|
|
||||||
# Least privilege: CI only needs to read the repo.
|
# Least privilege: CI only needs to read the repo.
|
||||||
permissions:
|
permissions:
|
||||||
@@ -52,8 +45,32 @@ env:
|
|||||||
CARGO_PROFILE_TEST_DEBUG: line-tables-only
|
CARGO_PROFILE_TEST_DEBUG: line-tables-only
|
||||||
|
|
||||||
jobs:
|
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:
|
gate:
|
||||||
name: build · test · clippy · fmt
|
name: build · test · clippy · fmt
|
||||||
|
needs: changes
|
||||||
|
if: needs.changes.outputs.code == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# A bound, because the absence of one cost real money. This job's test step has been hanging on
|
# 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
|
# `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.
|
# Linux gate. Without this, Windows-only code is the one code path that ships unlinted.
|
||||||
portability:
|
portability:
|
||||||
name: build · clippy · test (${{ matrix.os }})
|
name: build · clippy · test (${{ matrix.os }})
|
||||||
|
needs: changes
|
||||||
|
if: needs.changes.outputs.code == 'true'
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
# Windows sets the wall clock for the whole workflow: ~10 minutes warm and ~15 cold, building,
|
# 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
|
# 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.
|
# trusts that number, and it said 1.85 for months while the dependencies needed 1.88.
|
||||||
msrv:
|
msrv:
|
||||||
name: msrv
|
name: msrv
|
||||||
|
needs: changes
|
||||||
|
if: needs.changes.outputs.code == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
steps:
|
steps:
|
||||||
@@ -242,6 +263,8 @@ jobs:
|
|||||||
|
|
||||||
supply-chain:
|
supply-chain:
|
||||||
name: cargo-deny
|
name: cargo-deny
|
||||||
|
needs: changes
|
||||||
|
if: needs.changes.outputs.code == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
@@ -266,6 +289,8 @@ jobs:
|
|||||||
# build should not read as a broken harness.
|
# build should not read as a broken harness.
|
||||||
website:
|
website:
|
||||||
name: web build
|
name: web build
|
||||||
|
needs: changes
|
||||||
|
if: needs.changes.outputs.code == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
@@ -316,3 +341,25 @@ jobs:
|
|||||||
- name: Cross-browser (dev server)
|
- name: Cross-browser (dev server)
|
||||||
run: node ../scripts/site-cross.mjs --require webkit
|
run: node ../scripts/site-cross.mjs --require webkit
|
||||||
working-directory: web
|
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:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
# The site reads `docs/guide/` for the manual, which CI's prose filter skips, so a guide-only
|
# The site reads `docs/guide/` for the manual, so a guide-only change has to reach here
|
||||||
# change still has to reach here
|
|
||||||
paths:
|
paths:
|
||||||
- "web/**"
|
- "web/**"
|
||||||
- "docs/guide/**"
|
- "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.
|
# 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
|
# Its own workflow, with no path filter, so it can be a required check beside `CI passed`: a
|
||||||
# requests, and a required check that never starts blocks the merge forever. Whether a bump is owed
|
# required check that never starts blocks the merge forever. Whether a bump is owed is the script's
|
||||||
# is the script's call, from the diff. See scripts/version-check.py for the rules.
|
# call, from the diff. See scripts/version-check.py for the rules.
|
||||||
name: Version
|
name: Version
|
||||||
|
|
||||||
on:
|
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