From cde3e418ff746bd9380a2f518a601afb3eb25d9b Mon Sep 17 00:00:00 2001 From: Justin Carlson <40642470+justcarlson@users.noreply.github.com> Date: Sat, 28 Nov 2026 18:47:25 -0500 Subject: [PATCH] ci: collapse CI into one ci-ok job, fix ci-retro tiny-job guidance (#21) --- .github/workflows/ci.yml | 104 ++++++++++++---------------------- .github/workflows/pr-body.yml | 65 --------------------- scripts/validate_skills.py | 9 ++- skills/ci-retro/SKILL.md | 10 ++-- skills/file-pr/SKILL.md | 8 +++ tests/test_pr_body.py | 7 ++- tests/test_validate_skills.py | 8 +-- 7 files changed, 63 insertions(+), 148 deletions(-) delete mode 100644 .github/workflows/pr-body.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2eddba..09c215b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,8 +2,8 @@ name: ci on: pull_request: - push: - branches: [main] + # `edited` re-runs the PR-body lint when the body changes. + types: [opened, edited, reopened, synchronize, ready_for_review] workflow_dispatch: permissions: @@ -14,16 +14,36 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - validate-skills: + # One job, named for the required ruleset check: one VM boot and one checkout. + ci-ok: runs-on: ubuntu-24.04 - timeout-minutes: 10 + timeout-minutes: 15 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + fetch-depth: 0 persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: '24' + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + enable-cache: false + - name: PR body follows the pr skill + if: github.event_name == 'pull_request' && github.event.pull_request.user.type != 'Bot' + env: + PR_BODY: ${{ github.event.pull_request.body }} + run: | + # Run the validator embedded in the canonical template, so it has one source. + python3 - <<'PY' + import os, re, subprocess, sys, textwrap + + text = open("skills/pr/templates/pr-body.yml").read() + match = re.search(r"python3 - <<'PY'\n(.*?)\n\s*PY\n", text, re.DOTALL) + if not match: + sys.exit("::error::validator heredoc not found in skills/pr/templates/pr-body.yml") + sys.exit(subprocess.run([sys.executable, "-c", textwrap.dedent(match.group(1))], env=os.environ).returncode) + PY - name: Validate skills, manifests and size budget run: python3 scripts/validate_skills.py - name: skills CLI discovers every skill @@ -51,25 +71,21 @@ jobs: sys.exit(1) print(f"skills CLI lists all {len(want)} skills") PY - - privacy-and-secrets: - runs-on: ubuntu-24.04 - timeout-minutes: 10 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - persist-credentials: false - - name: Install pinned gitleaks + - name: Install pinned gitleaks and actionlint run: | set -euo pipefail - archive="$RUNNER_TEMP/gitleaks.tar.gz" - curl --fail --silent --show-error --location \ - https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz \ - --output "$archive" - printf '551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb %s\n' "$archive" | sha256sum --check mkdir -p "$RUNNER_TEMP/bin" - tar -xzf "$archive" -C "$RUNNER_TEMP/bin" gitleaks + fetch() { + # fetch + archive="$RUNNER_TEMP/$3.tar.gz" + curl --fail --silent --show-error --location "$1" --output "$archive" + printf '%s %s\n' "$2" "$archive" | sha256sum --check + tar -xzf "$archive" -C "$RUNNER_TEMP/bin" "$3" + } + fetch https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz \ + 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb gitleaks + fetch https://github.com/rhysd/actionlint/releases/download/v1.7.12/actionlint_1.7.12_linux_amd64.tar.gz \ + 8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8 actionlint echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH" - name: gitleaks (all history) run: gitleaks git --no-banner --redact --verbose . @@ -83,31 +99,7 @@ jobs: else python3 scripts/check_privacy.py --all fi - - lint-and-test: - runs-on: ubuntu-24.04 - timeout-minutes: 10 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - uses: taiki-e/install-action@cfdb7ed4ccc7c7dce37759eae89dc5674b469b39 # v2.90.3 - with: - tool: shellcheck@0.11.0 - - name: Install pinned actionlint - run: | - set -euo pipefail - archive="$RUNNER_TEMP/actionlint.tar.gz" - curl --fail --silent --show-error --location \ - https://github.com/rhysd/actionlint/releases/download/v1.7.12/actionlint_1.7.12_linux_amd64.tar.gz \ - --output "$archive" - printf '8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8 %s\n' "$archive" | sha256sum --check - mkdir -p "$RUNNER_TEMP/bin" - tar -xzf "$archive" -C "$RUNNER_TEMP/bin" actionlint - echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH" - - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 - with: - enable-cache: false + # shellcheck is pre-installed on ubuntu-24.04. - name: shellcheck run: shellcheck install.sh skills/omarchy-dev/scripts/omarchy-vm - name: actionlint @@ -116,25 +108,3 @@ jobs: run: uvx ruff@0.17.3 check --isolated scripts tests - name: pytest run: uv run --no-project --with pytest==9.0.1 --with pyyaml==6.0.3 pytest -q tests/ - - ci-ok: - if: always() - needs: [validate-skills, privacy-and-secrets, lint-and-test] - runs-on: ubuntu-24.04 - timeout-minutes: 2 - steps: - - name: Every required job succeeded - env: - NEEDS: ${{ toJSON(needs) }} - run: | - python3 - <<'PY' - import json, os, sys - - needs = json.loads(os.environ["NEEDS"]) - bad = {name: job["result"] for name, job in needs.items() if job["result"] != "success"} - for name, result in bad.items(): - print(f"::error::{name} finished with {result}") - if not needs: - print("::error::expected at least one needed job") - sys.exit(1 if bad or not needs else 0) - PY diff --git a/.github/workflows/pr-body.yml b/.github/workflows/pr-body.yml deleted file mode 100644 index 6cd0ac0..0000000 --- a/.github/workflows/pr-body.yml +++ /dev/null @@ -1,65 +0,0 @@ -# Canonical PR-body lint. Copy to .github/workflows/pr-body.yml in each repo; -# only `runs-on` may differ. -name: pr-body - -on: - pull_request: - types: [opened, edited, reopened, synchronize, ready_for_review] - -permissions: {} - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - lint: - # Bots such as Dependabot write their own bodies. - if: github.event.pull_request.user.type != 'Bot' - runs-on: ubuntu-24.04 - timeout-minutes: 2 - steps: - - name: Check the body follows the pr skill - env: - PR_BODY: ${{ github.event.pull_request.body }} - run: | - python3 - <<'PY' - import os, re, sys - - body = (os.environ.get("PR_BODY") or "").replace("\r\n", "\n") - errors = [] - # Headings inside fenced blocks do not count. - text = re.sub(r"(?ms)^ {0,3}(```|~~~).*?^ {0,3}\1[^\n]*$", lambda m: re.sub(r"(?m)^#", " ", m.group(0)), body) - headings = re.findall(r"(?m)^## +(.+?)\s*$", text) - wanted = ["Summary", "Evidence", "Merge Danger"] - if [h for h in headings if h in wanted] != wanted: - errors.append("Use the headings ## Summary, ## Evidence, ## Merge Danger, once each and in that order.") - if not body.lstrip().startswith("## Summary"): - errors.append("Start the body at ## Summary, with no preamble.") - - def section(name): - match = re.search(rf"(?ms)^## +{re.escape(name)}\s*$(.*?)(?=^## |\Z)", text) - return match.group(1) if match else "" - - if not re.search(r"(?m)^ {0,3}(```|~~~)", section("Summary")) and "![" not in section("Summary"): - errors.append("Summary needs a visual: a fenced diagram, tree, diff, or code block.") - evidence = section("Evidence") - for label in ("Before", "After"): - # Content may follow on the same line or below, up to the next label. - match = re.search(rf"(?s)\*\*{label}:\*\*(.*?)(?=\*\*(?:Before|After):\*\*|\Z)", evidence) - if not match or not match.group(1).strip(): - errors.append(f"Evidence needs a filled **{label}:** line.") - danger = section("Merge Danger") - if not re.search(r"\*\*Door:\*\* *(one|two)-way\b", danger, re.I): - errors.append("Merge Danger needs **Door:** one-way or two-way.") - if not re.search(r"\*\*Blast Radius:\*\* *\S", danger): - errors.append("Merge Danger needs a filled **Blast Radius:** line.") - placeholders = re.findall(r"<(?:diagram, diff-sketch, or tree|screenshot/output/[^>]*|one-way or two-way|one-word description|optional:[^>]*)>", body) - if placeholders: - errors.append("Replace template placeholders: " + ", ".join(sorted(set(placeholders)))) - for error in errors: - print(f"::error title=PR body::{error}") - if errors: - print("Template: https://github.com/mattpocock/skills/blob/main/skills/engineering/pr/SKILL.md") - sys.exit(1 if errors else 0) - PY diff --git a/scripts/validate_skills.py b/scripts/validate_skills.py index 96435bf..1d06913 100755 --- a/scripts/validate_skills.py +++ b/scripts/validate_skills.py @@ -8,7 +8,7 @@ - relative Markdown links resolve and stay inside their own skills//, or point into a sibling that scripts/install.py declares as a dependency; - plugin manifests share one version; -- .github/workflows/pr-body.yml matches skills/pr/templates/pr-body.yml; +- .github/workflows/ci.yml runs the PR-body lint from skills/pr/templates/pr-body.yml; - no CLAUDE.md at the repo root; - every skill appears in README.md; - description and body sizes stay within size-budget.json. @@ -369,10 +369,9 @@ def validate(root: Path) -> list[str]: if f"`{d.name}`" not in readme: errors.append(f"README.md: skill `{d.name}` is not listed") errors.extend(check_manifests(root)) - template = root / "skills/pr/templates/pr-body.yml" - workflow = root / ".github/workflows/pr-body.yml" - if not workflow.is_file() or workflow.read_bytes() != template.read_bytes(): - errors.append(".github/workflows/pr-body.yml must match skills/pr/templates/pr-body.yml byte for byte") + ci = root / ".github/workflows/ci.yml" + if not ci.is_file() or "skills/pr/templates/pr-body.yml" not in ci.read_text(): + errors.append(".github/workflows/ci.yml must run the PR-body lint from skills/pr/templates/pr-body.yml") if (root / "CLAUDE.md").exists(): errors.append("CLAUDE.md must not exist at the repo root; keep rosters in your own config") if not errors: diff --git a/skills/ci-retro/SKILL.md b/skills/ci-retro/SKILL.md index 2dc0d89..dc94aab 100644 --- a/skills/ci-retro/SKILL.md +++ b/skills/ci-retro/SKILL.md @@ -74,10 +74,12 @@ record its labels, capacity and monthly budget in its own `AGENTS.md` or - **Never register a self-hosted runner on a public repository.** A fork PR can run untrusted code on it. Run public repositories on hosted runners (`ubuntu-24.04`). -- **Match tiny, fast jobs to hosted runners** when their queue on a self-hosted - runner exceeds their run time (`pr-body`, `actionlint`). Hosted minutes are - billed per job, rounded up to a minute, so state each moved job's monthly - minutes in the PR. +- **Do not move tiny jobs to hosted runners on a private repository with a + self-hosted pool.** GitHub bills every hosted job at a 1-minute minimum, so a + 3-second check (`pr-body`, `actionlint`, `ci-ok`, `lint`) costs 20x. Fold it + into an existing self-hosted job as a step, or keep the gate on self-hosted + once a job finishes. Use hosted runners on a private repository only for + secret-isolated deploys, KVM, or a low-volume repository with no pool. - **Gate merges on one always-running aggregator job**, for example `ci-ok`, that `needs` every CI job and fails unless each one succeeded or was skipped by a tested scope rule. Put path filters inside the workflow, never in `on:` diff --git a/skills/file-pr/SKILL.md b/skills/file-pr/SKILL.md index c2dea18..7429aa8 100644 --- a/skills/file-pr/SKILL.md +++ b/skills/file-pr/SKILL.md @@ -41,6 +41,14 @@ If model identity is unavailable, name the harness without guessing a model. Before submission, check the title, description, quotes, and attachments for secrets and private details. +Before `gh pr create` or `pull_request_create`, check the body shape locally. +It must start at `## Summary` (with a visual), then `## Evidence` (filled +**Before:** and **After:**), then `## Merge Danger` (**Door:** and +**Blast Radius:**), in that order, with no template placeholders. CI rejects a +body that misses this. To run the exact CI check, extract the `python3` +heredoc from `skills/pr/templates/pr-body.yml` and run it with the body in +`PR_BODY`. + Open a real PR rather than a draft so review bots run. If `gh pr create` fails because the GraphQL rate limit is used up, open it through REST with `gh api repos///pulls -f title=... -f head=... -f base=... -F body=@`. If the user also asked diff --git a/tests/test_pr_body.py b/tests/test_pr_body.py index fac64cb..147d3de 100644 --- a/tests/test_pr_body.py +++ b/tests/test_pr_body.py @@ -13,7 +13,7 @@ ROOT = Path(__file__).resolve().parent.parent TEMPLATE = ROOT / "skills" / "pr" / "templates" / "pr-body.yml" -WORKFLOW = ROOT / ".github" / "workflows" / "pr-body.yml" +CI = ROOT / ".github" / "workflows" / "ci.yml" def extract_validator() -> str: @@ -56,8 +56,9 @@ def lint(body: str) -> tuple[int, str]: """ -def test_template_matches_workflow(): - assert TEMPLATE.read_bytes() == WORKFLOW.read_bytes() +def test_ci_runs_template_validator(): + assert "skills/pr/templates/pr-body.yml" in CI.read_text() + assert not (ROOT / ".github" / "workflows" / "pr-body.yml").exists() def test_valid_body_passes(): diff --git a/tests/test_validate_skills.py b/tests/test_validate_skills.py index 405b6b2..763d21f 100644 --- a/tests/test_validate_skills.py +++ b/tests/test_validate_skills.py @@ -162,10 +162,10 @@ def test_manifests_share_version(): assert set(vs.manifest_versions(ROOT).values()) == {"0.4.0"} -def test_pr_body_workflow_must_match(repo: Path): - p = repo / ".github/workflows/pr-body.yml" - p.write_bytes(p.read_bytes() + b"\n") - assert any("byte for byte" in e for e in errors(repo)) +def test_ci_must_run_pr_body_template(repo: Path): + p = repo / ".github/workflows/ci.yml" + p.write_text(p.read_text().replace("skills/pr/templates/pr-body.yml", "elsewhere.yml")) + assert any("PR-body lint" in e for e in errors(repo)) def test_root_claude_md_rejected(repo: Path):