From 7cfc5dc0549b4a5487b4a161f08da0632aec52d4 Mon Sep 17 00:00:00 2001 From: repo-worker-code-g Date: Fri, 6 Nov 2026 23:18:06 -0600 Subject: [PATCH] ci: generic basic-tier workflow validation (actionlint) for workflows + actions (#5743) --- .github/ci-policy.md | 19 +++ .github/scripts/check-workflows.sh | 152 ++++++++++++++++++++++++ .github/scripts/check-workflows.test.sh | 130 ++++++++++++++++++++ .github/workflows/bws-freshness.yml | 1 - .github/workflows/workflow-lint.yml | 59 +++++++++ 5 files changed, 360 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/check-workflows.sh create mode 100755 .github/scripts/check-workflows.test.sh create mode 100644 .github/workflows/workflow-lint.yml diff --git a/.github/ci-policy.md b/.github/ci-policy.md index 29a011b42a..e0eecb991b 100644 --- a/.github/ci-policy.md +++ b/.github/ci-policy.md @@ -94,6 +94,24 @@ service rehomed as `fleet serve search`) to the same rule, with its own pinned headers. Intentional changes land in both copies in the same PR; intentional header changes update the guard script in the same PR. +## Workflow and composite-action validation (#5743) + +`.github/workflows/workflow-lint.yml` is a **basic-tier** check +(job `basic: workflow lint`): on pull requests touching +`.github/workflows/**` or `.github/actions/**`, and on merge +groups, it runs `.github/scripts/check-workflows.sh`, which lints +the complete workflow set with actionlint (shellcheck over `run:` +blocks at `-S warning` when shellcheck is available, matching the +mcpx leg) and shape-validates every `.github/actions/*/action.yml` +(actionlint parses every file it is given as a workflow, so action +metadata gets a dedicated validator in the same script). The mcpx +actionlint leg stays scoped to the mcpx workflows (#1996); this is +its generic counterpart. Shell contract tests live in +`.github/scripts/check-workflows.test.sh` and run in the same job +against valid and deliberately invalid workflow/action fixtures. +actionlint is a pinned release binary, checksum-verified in the +workflow before use. + ## OpenCode metered-provider config guard `.github/workflows/opencode-config-guard.yml` runs the static guard and @@ -139,6 +157,7 @@ main-breakage rate (issues labelled `main-broken`) proves out. | -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | | nix ci | — (PR and merge-group proxy check is in the dedicated workflow below) | proxy port fallbacks + full flake-check (formatting auto-fixed on main by the auto-format workflow) | schedule in nix-ci.yml | | proxy-port-fallbacks | `basic: proxy port fallbacks` on `pull_request` and `merge_group` | — (main copy remains in nix-ci.yml) | — | +| workflow-lint | `basic: workflow lint` on `pull_request` (paths `.github/workflows/**`, `.github/actions/**`) and `merge_group` | — | — | | id | guard + affected-crate matrix (`id-pr-checks.txt`) | + full `nix flake check ./pkgs/id` job | schedule in id-check.yml + id-e2e-nightly.yml (full flake check) | | mcpx conformance | spec-parity leg only (measured 28s exec, run 40801660942, 2026-10-29 — under the 5m fast-leg limit) | all conformance legs + records + spec-parity | — (main covers it) | | id bench | — (removed) | yes | — | diff --git a/.github/scripts/check-workflows.sh b/.github/scripts/check-workflows.sh new file mode 100755 index 0000000000..a599c43cdc --- /dev/null +++ b/.github/scripts/check-workflows.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash +# check-workflows.sh — generic workflow validation (#5743). +# +# The basic-tier gate for .github/workflows/** and .github/actions/**: +# mcpx.yml's actionlint leg covers only .github/workflows/mcpx*.yml +# (#1996), so workflow and composite-action changes elsewhere could +# merge with no validator at all. This script is that validator: +# +# - workflow files: actionlint (syntax, expressions, action +# references and their inputs), with shellcheck over run: blocks +# at -S warning when shellcheck is available (same severity as +# the mcpx leg). +# - action metadata (action.yml / action.yaml): actionlint parses +# every file it is given as a workflow, so composite-action +# metadata gets a dedicated shape validation instead (below). +# +# Usage: +# check-workflows.sh lint the full repo set +# check-workflows.sh FILE [FILE..] lint exactly these files +# (used by the contract tests) +# +# actionlint is taken from $ACTIONLINT_BIN when set, else from PATH. +# The workflow-lint workflow installs the pinned release (with +# checksum verification) before calling this script. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +cd "$REPO_ROOT" + +ACTIONLINT="${ACTIONLINT_BIN:-actionlint}" +if ! command -v "$ACTIONLINT" >/dev/null 2>&1; then + echo "check-workflows: actionlint not found (set ACTIONLINT_BIN or put it on PATH)" >&2 + exit 1 +fi + +# actionlint shellcheck integration: same severity as mcpx.yml. +if command -v shellcheck >/dev/null 2>&1; then + SHELLCHECK_OPT=(-shellcheck "shellcheck -S warning") +else + echo "check-workflows: shellcheck not on PATH; run: blocks are not shellchecked" >&2 + SHELLCHECK_OPT=(-shellcheck "") +fi + +# validate_action_metadata FILE — shape-check one action.yml. +# Oracle: the GitHub composite/action metadata schema — a mapping +# with name + description, a runs mapping whose using is one of the +# supported runtimes, steps for composite actions, and no unknown +# top-level keys (a typo'd `run:` for `runs:` is the failure this +# catches). PyYAML gives a real parse when importable; otherwise a +# structural fallback enforces the same rules over top-level keys. +validate_action_metadata() { + local file="$1" + if python3 -c 'import yaml' >/dev/null 2>&1; then + python3 - "$file" <<'PYEOF' +import sys +import yaml + +path = sys.argv[1] +try: + with open(path, encoding="utf-8") as fh: + doc = yaml.safe_load(fh) +except Exception as exc: # YAML syntax error: fail with the parser's words + print(f"{path}: invalid YAML: {exc}", file=sys.stderr) + sys.exit(1) + +errors = [] +if not isinstance(doc, dict): + errors.append("top level is not a mapping") +else: + allowed = {"name", "author", "description", "inputs", "outputs", "runs", "branding"} + for key in doc: + if key not in allowed: + errors.append(f"unexpected top-level key {key!r}") + for key in ("name", "description"): + if not isinstance(doc.get(key), str) or not doc[key]: + errors.append(f"{key!r} must be a non-empty string") + runs = doc.get("runs") + if not isinstance(runs, dict): + errors.append("'runs' must be a mapping") + else: + using = runs.get("using") + if using not in ("composite", "docker", "node16", "node20", "node24"): + errors.append(f"runs.using {using!r} is not a supported runtime") + elif using == "composite": + steps = runs.get("steps") + if not isinstance(steps, list) or not steps: + errors.append("composite action must declare a non-empty runs.steps list") + elif using == "docker": + if not isinstance(runs.get("image"), str) or not runs["image"]: + errors.append("docker action must declare runs.image") +for err in errors: + print(f"{path}: {err}", file=sys.stderr) +sys.exit(1 if errors else 0) +PYEOF + else + echo "check-workflows: PyYAML not importable; structural fallback for $file" >&2 + local keys using key + keys="$(grep -oE '^[A-Za-z][A-Za-z0-9_-]*:' "$file" | tr -d ':' | sort -u)" + local allowed=" name author description inputs outputs runs branding " + while IFS= read -r key; do + case "$allowed" in + *" $key "*) ;; + *) echo "$file: unexpected top-level key '$key'" >&2; return 1 ;; + esac + done <<<"$keys" + for key in name description runs; do + if ! grep -qx "$key" <<<"$keys"; then + echo "$file: missing top-level key '$key'" >&2 + return 1 + fi + done + using="$(awk '/^runs:/{in_runs=1; next} /^[A-Za-z]/{in_runs=0} in_runs && /using:/{print; exit}' "$file")" + case "$using" in + *composite*|*docker*|*node16*|*node20*|*node24*) ;; + *) echo "$file: runs.using is missing or not a supported runtime" >&2; return 1 ;; + esac + fi +} + +classify() { # classify FILE -> workflow|action + case "$(basename "$1")" in + action.yml|action.yaml) echo action ;; + *) echo workflow ;; + esac +} + +declare -a WORKFLOWS=() ACTIONS=() +if [ "$#" -gt 0 ]; then + for f in "$@"; do + if [ "$(classify "$f")" = action ]; then ACTIONS+=("$f"); else WORKFLOWS+=("$f"); fi + done +else + while IFS= read -r f; do WORKFLOWS+=("$f"); done < <( + find .github/workflows -maxdepth 1 \( -name '*.yml' -o -name '*.yaml' \) | sort) + while IFS= read -r f; do ACTIONS+=("$f"); done < <( + find .github/actions -name 'action.yml' -o -name 'action.yaml' | sort) +fi + +status=0 +if [ "${#WORKFLOWS[@]}" -gt 0 ]; then + echo "check-workflows: actionlint over ${#WORKFLOWS[@]} workflow file(s)" + "$ACTIONLINT" "${SHELLCHECK_OPT[@]}" "${WORKFLOWS[@]}" || status=1 +fi +for f in "${ACTIONS[@]}"; do + echo "check-workflows: validating action metadata $f" + validate_action_metadata "$f" || status=1 +done +if [ "$status" -eq 0 ]; then + echo "check-workflows: OK" +fi +exit "$status" diff --git a/.github/scripts/check-workflows.test.sh b/.github/scripts/check-workflows.test.sh new file mode 100755 index 0000000000..9ab245e00f --- /dev/null +++ b/.github/scripts/check-workflows.test.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# Contract tests for check-workflows.sh (#5743): the validator passes +# a well-formed workflow and a well-formed composite action, and +# fails — with a diagnostic — on a broken ${{ }} expression, on an +# unknown input to a well-known action, on action metadata with no +# runs section, and on action metadata with an unsupported runtime. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CHECK="$SCRIPT_DIR/check-workflows.sh" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +RC=0 +run_check() { # run_check FILE [FILE..] + RC=0 + bash "$CHECK" "$@" >"$TMP/out" 2>&1 || RC=$? +} + +expect_pass() { # expect_pass + if [ "$RC" -ne 0 ]; then + echo "FAIL: $1 should have passed check-workflows" >&2 + cat "$TMP/out" >&2 + exit 1 + fi + echo "pass: $1 passes" +} + +expect_fail() { # expect_fail + if [ "$RC" -eq 0 ]; then + echo "FAIL: $1 should have failed check-workflows" >&2 + cat "$TMP/out" >&2 + exit 1 + fi + echo "pass: $1 fails" +} + +# 1. A well-formed workflow passes. +cat >"$TMP/valid-workflow.yml" <<'EOF' +name: demo +on: + push: +jobs: + build: + runs-on: ubuntu-latest + steps: + - run: echo "hello ${{ github.sha }}" +EOF +run_check "$TMP/valid-workflow.yml" +expect_pass "valid workflow" + +# 2. A broken ${{ }} expression fails. +cat >"$TMP/bad-expression.yml" <<'EOF' +name: demo +on: + push: +jobs: + build: + runs-on: ubuntu-latest + steps: + - run: echo "${{ github.event..name }}" +EOF +run_check "$TMP/bad-expression.yml" +expect_fail "workflow with a broken expression" + +# 3. An unknown input to a well-known action fails. (checkout is +# pinned to v4 here because that is the newest major in actionlint +# 1.7.7's bundled action database; newer majors are not input-checked +# offline.) +cat >"$TMP/bad-input.yml" <<'EOF' +name: demo +on: + push: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + not-a-real-input: x +EOF +run_check "$TMP/bad-input.yml" +expect_fail "workflow passing an unknown input to actions/checkout" + +# 4. A well-formed composite action passes. +mkdir -p "$TMP/good-action" +cat >"$TMP/good-action/action.yml" <<'EOF' +name: demo-action +description: A well-formed composite action fixture. +inputs: + who: + description: Who to greet + required: false +runs: + using: composite + steps: + - run: echo "hello" + shell: bash +EOF +run_check "$TMP/good-action/action.yml" +expect_pass "valid composite action" + +# 5. Action metadata with no runs section fails. +mkdir -p "$TMP/no-runs-action" +cat >"$TMP/no-runs-action/action.yml" <<'EOF' +name: demo-action +description: Missing its runs section entirely. +inputs: + who: + description: Who to greet + required: false +EOF +run_check "$TMP/no-runs-action/action.yml" +expect_fail "action metadata with no runs section" + +# 6. Action metadata with an unsupported runtime fails. +mkdir -p "$TMP/bad-using-action" +cat >"$TMP/bad-using-action/action.yml" <<'EOF' +name: demo-action +description: Declares a runtime GitHub does not support. +runs: + using: banana + steps: + - run: echo "hello" + shell: bash +EOF +run_check "$TMP/bad-using-action/action.yml" +expect_fail "action metadata with runs.using: banana" + +echo "check-workflows.test: all contract tests passed" diff --git a/.github/workflows/bws-freshness.yml b/.github/workflows/bws-freshness.yml index 557be02b5f..36fa80d20e 100644 --- a/.github/workflows/bws-freshness.yml +++ b/.github/workflows/bws-freshness.yml @@ -108,7 +108,6 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - title="bws.yaml mirror drift detected" existing="$(bash lib/bws-freshness-drift-issue.sh)" if [ -n "$existing" ]; then gh issue close "$existing" --comment "A later scheduled freshness check (#5451) found the mirror up to date; closing this drift episode." diff --git a/.github/workflows/workflow-lint.yml b/.github/workflows/workflow-lint.yml new file mode 100644 index 0000000000..35d8ec2669 --- /dev/null +++ b/.github/workflows/workflow-lint.yml @@ -0,0 +1,59 @@ +name: workflow-lint + +# CI tier policy: see .github/ci-policy.md +# +# Generic basic-tier validation for workflow and composite-action +# changes (#5743): mcpx.yml's actionlint leg covers only +# .github/workflows/mcpx*.yml (#1996), so a workflow-only PR could +# merge with no validator at all. This workflow runs +# .github/scripts/check-workflows.sh — actionlint over the whole +# workflow set plus shape validation of .github/actions/*/action.yml +# — whenever a change touches those paths. Pure bash + one pinned +# static binary, so this stays a seconds-long basic check. + +on: + pull_request: + paths: + - ".github/workflows/**" + - ".github/actions/**" + - ".github/scripts/check-workflows.sh" + - ".github/scripts/check-workflows.test.sh" + merge_group: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: workflow-lint-${{ github.ref }} + cancel-in-progress: true + +env: + ACTIONLINT_VERSION: "1.7.7" + ACTIONLINT_SHA256: "023070a287cd8cccd71515fedc843f1985bf96c436b7effaecce67290e7e0757" + +jobs: + workflow-lint: + name: "basic: workflow lint" + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v7 + - name: Install actionlint (pinned, checksum-verified) + run: | + tarball="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" + curl -sL -o "$RUNNER_TEMP/$tarball" \ + "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/$tarball" + echo "$ACTIONLINT_SHA256 $RUNNER_TEMP/$tarball" | sha256sum -c - + tar -xzf "$RUNNER_TEMP/$tarball" -C "$RUNNER_TEMP" actionlint + echo "ACTIONLINT_BIN=$RUNNER_TEMP/actionlint" >> "$GITHUB_ENV" + - name: Ensure PyYAML for action-metadata validation (best effort) + run: | + python3 -c 'import yaml' 2>/dev/null \ + || python3 -m pip install --break-system-packages --quiet 'pyyaml>=6,<7' \ + || python3 -m pip install --quiet 'pyyaml>=6,<7' \ + || echo "PyYAML unavailable; check-workflows.sh uses its structural fallback" + - name: Contract tests for the workflow validator (#5743) + run: bash .github/scripts/check-workflows.test.sh + - name: Validate workflows and composite actions + run: bash .github/scripts/check-workflows.sh