Repository navigation
fix(ci): regenerate actions.lock entries so CI starts again; guard drift #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hyperpolymath
wants to merge
11
commits into
main
Choose a base branch
from
claude/ci-actions-lock
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+286
−25
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c692533
fix(ci): regenerate actions.lock entries so CI starts again; guard drift
HoTT-stuff fe174af
style(ci): [[ ]] tests and named locals in check-actions-lock.sh (Son…
HoTT-stuff 7fa3736
fix(ci): actions.lock guard sees flow-style steps and transitive depe…
HoTT-stuff 71ac72e
fix(ci): actions.lock guard reads quoted uses keys, ignores run-scrip…
HoTT-stuff 97f8623
style(ci): quote the joined lists in check-actions-lock.sh messages (…
HoTT-stuff b18fb9e
fix(ci): actions.lock guard allows space before the uses colon
HoTT-stuff 57f6e23
fix(ci): actions.lock guard keeps refs whose branch contains /
HoTT-stuff 1d2b480
fix(ci): actions.lock guard fails closed on unreadable uses values
HoTT-stuff 7fc0186
fix(ci): tell reusable-workflow calls from steps by context, not path
HoTT-stuff e3eb086
style(ci): name positional parameters in tag()/refs() (Sonar S7679)
HoTT-stuff 5ede7ec
fix(ci): keep indentless step sequences in step context; add guard se…
HoTT-stuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # | ||
| # actions.lock consistency guard. | ||
| # | ||
| # `.github/workflows/actions.lock` (GitHub's actions lockfile, generated by | ||
| # `gh actions-lock`) is this repo's pin authority: it maps every action a | ||
| # workflow uses to a commit SHA. GitHub refuses to start a workflow whose | ||
| # `uses:` refs do not match the lock, and reports only a `startup_failure` | ||
| # with zero jobs. That is how the `CI` workflow stopped running on every | ||
| # push and PR from 2026-10-11: Dependabot (#782) bumped | ||
| # `actions/setup-node` and `actions/upload-artifact` in ci.yml without | ||
| # regenerating the lock. | ||
| # | ||
| # For each workflow, this check compares the set of external actions its | ||
| # `uses:` lines reference (sub-path actions such as | ||
| # `github/codeql-action/init@v4` count as `github/codeql-action@v4`; local | ||
| # `./` actions, `docker://` images and reusable workflows (a job-level | ||
| # `uses:` naming a `.github/workflows/*.yml` file) are not locked) | ||
| # with the set the lock lists for it, and fails on any difference, either | ||
| # way round. It also fails if a locked action has no `dependencies:` entry. | ||
| # | ||
| # Usage: tools/ci/check-actions-lock.sh [WORKFLOW_DIR] (default .github/workflows) | ||
| set -uo pipefail | ||
|
|
||
| dir="${1:-.github/workflows}" | ||
| lock="$dir/actions.lock" | ||
| fail=0 | ||
| err() { printf '::error::%s\n' "$*"; fail=1; } | ||
|
|
||
| [[ -f "$lock" ]] || { err "actions lockfile missing: $lock"; exit 1; } | ||
|
|
||
| # Split a workflow (comments stripped) by context: lines inside a `steps:` | ||
| # block (more indented than its `steps:` key) are tagged S, all others J. | ||
| # A reusable workflow is called by a job (`jobs.<id>.uses`), never by a step, | ||
| # so the reusable-workflow exclusion below applies to J lines only: a step | ||
| # action whose directory happens to be named `.github/workflows/x.yml` is | ||
| # still checked. | ||
| tag() { | ||
| local file="$1" | ||
| sed -E 's/[[:space:]]+#.*$//' "$file" | awk ' | ||
| { match($0, /^ */); ind = RLENGTH } | ||
| /^[[:space:]]*$/ { next } | ||
| # An indentless sequence (`steps:` then `- uses: …` at the same indent) is | ||
| # still step context: only a non-`-` line at or above the key ends it. | ||
| in_steps && (ind < sind || (ind == sind && $0 !~ /^ *-/)) { in_steps = 0 } | ||
| /^[[:space:]]*["'\'']?steps["'\'']?[[:space:]]*:/ { | ||
| # `steps: [{uses: …}]` (flow sequence on the key line) is step context too. | ||
| print (match($0, /:[[:space:]]*[^[:space:]]/) ? "S" : "J") "\t" $0 | ||
| in_steps = 1; sind = ind; next | ||
| } | ||
| { print (in_steps ? "S" : "J") "\t" $0 } | ||
| ' | ||
| } | ||
|
|
||
| # The `uses:` values on lines tagged $2 (S or J), action-shaped only. | ||
| # Block style (`- uses: x`), flow style (`- {uses: x, with: …}`) and quoted keys (`"uses": x`). | ||
| # Only action-shaped values count (`owner/repo[/path]@ref`, a ref may hold `/`), so `uses:` text in | ||
| # a `run:` script (a grep pattern, say) is not mistaken for a step. | ||
| refs() { | ||
| local file="$1" ctx="$2" | ||
| tag "$file" | grep -E "^$ctx"$'\t' | cut -f2- \ | ||
| | grep -oE '(^|[{,[:space:]-])["'\'']?uses["'\'']?[[:space:]]*:[[:space:]]*[^[:space:],}]+' \ | ||
| | sed -E 's/^.*uses["'\'']?[[:space:]]*:[[:space:]]*//; s/^["'\'']//; s/["'\'']$//' \ | ||
| | grep -vE '^(\./|docker://)' \ | ||
| | grep -E '^[A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+@[A-Za-z0-9_./-]+$' | ||
| } | ||
|
|
||
| # The actions a workflow file uses, normalised and sorted. | ||
| used() { | ||
| local file="$1" | ||
| { refs "$file" S; refs "$file" J | grep -vE '/\.github/workflows/[^/@]+\.ya?ml@'; } \ | ||
| | sed -E 's#^([^/@]+/[^/@]+)/[^@]*@#\1@#' \ | ||
| | sort -u | ||
| } | ||
|
|
||
| # Fail closed: a `uses:` key at the start of a line (block `uses:` / `- uses:`, | ||
| # or a flow mapping opened on the line, `- {uses: …}`) whose value the matcher | ||
| # above cannot read is an error, not a silent skip. That covers folded or | ||
| # literal scalars (`uses: >-` with the ref on the next line), an empty value, | ||
| # and anything else that is not a local action (`./…`), a Docker image | ||
| # (`docker://…`), a reusable workflow (`owner/repo/.github/workflows/x.yml@ref`) | ||
| # or an action (`owner/repo[/path]@ref`). Write such a step as a plain scalar. | ||
| unreadable() { | ||
| local file="$1" | ||
| sed -E 's/[[:space:]]+#.*$//' "$file" \ | ||
| | grep -nE '^[[:space:]]*(-[[:space:]]+)?\{?[[:space:]]*["'\'']?uses["'\'']?[[:space:]]*:' \ | ||
| | while IFS= read -r line; do | ||
| local n="${line%%:*}" v | ||
| v=$(printf '%s\n' "${line#*:}" \ | ||
| | sed -E 's/^[[:space:]]*(-[[:space:]]+)?\{?[[:space:]]*["'\'']?uses["'\'']?[[:space:]]*:[[:space:]]*//; s/[[:space:]]*[,}].*$//; s/^["'\'']//; s/["'\'']$//') | ||
| if ! printf '%s\n' "$v" | grep -qE '^(\./|docker://|[A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+@[A-Za-z0-9_./-]+$)'; then | ||
| printf '%s: %s\n' "$n" "${v:-<empty>}" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # The actions the lock lists for workflow path $1, sorted. | ||
| locked() { | ||
| local path="$1" | ||
| awk -v wf="'$path':" ' | ||
| /^workflows:/ { inwf = 1; next } | ||
| /^dependencies:/ { inwf = 0 } | ||
| inwf && $1 == wf { on = 1; next } | ||
| inwf && on && /^ - / { v = $2; gsub(/'\''/, "", v); print v; next } | ||
| inwf && on { on = 0 } | ||
| ' "$lock" | sort -u | ||
| } | ||
|
|
||
| # Dependency keys present in the lock. | ||
| deps=$(awk '/^dependencies:/ { d = 1; next } d && /^ '\''/ { k = $1; gsub(/['\'':]/, "", k); print k }' "$lock") | ||
|
|
||
| checked=0 | ||
| for wf in "$dir"/*.yml "$dir"/*.yaml; do | ||
| [[ -f "$wf" ]] || continue | ||
| rel=".github/workflows/$(basename "$wf")" | ||
| checked=$((checked + 1)) | ||
| bad=$(unreadable "$wf") | ||
| [[ -z "$bad" ]] || err "$rel has uses: values this guard cannot read (write them as plain scalars): ${bad//$'\n'/; }" | ||
| u=$(used "$wf") | ||
| l=$(locked "$rel") | ||
| if ! grep -qF "'$rel':" "$lock"; then | ||
| [[ -z "$u" ]] || err "$rel uses actions but has no actions.lock entry: ${u//$'\n'/ }" | ||
| continue | ||
| fi | ||
| missing=$(comm -23 <(printf '%s\n' "$u" | sed '/^$/d') <(printf '%s\n' "$l" | sed '/^$/d')) | ||
| stale=$(comm -13 <(printf '%s\n' "$u" | sed '/^$/d') <(printf '%s\n' "$l" | sed '/^$/d')) | ||
| [[ -z "$missing" ]] || err "$rel uses actions the lock does not list (regenerate actions.lock): ${missing//$'\n'/ }" | ||
| [[ -z "$stale" ]] || err "$rel: actions.lock lists actions the workflow no longer uses: ${stale//$'\n'/ }" | ||
| for a in $l; do | ||
| printf '%s\n' "$deps" | grep -qxF "$a" || err "actions.lock has no dependencies entry for $a ($rel)" | ||
| done | ||
| done | ||
|
|
||
| # Transitive references: an action the lock records may itself use other | ||
| # actions (`uses:` under its dependency record, e.g. upload-pages-artifact -> | ||
| # upload-artifact@<sha>). Each of those must have its own record too. | ||
| while IFS= read -r t; do | ||
| [[ -n "$t" ]] || continue | ||
| printf '%s\n' "$deps" | grep -qxF "$t" || err "actions.lock: a dependency uses $t, which has no dependencies entry" | ||
| done < <(awk '/^dependencies:/ { d = 1; next } d && /^ uses:/ { u = 1; next } d && u && /^ - / { v = $2; gsub(/'\''/, "", v); print v; next } { u = 0 }' "$lock" | sort -u) | ||
|
|
||
| if [[ "$fail" -ne 0 ]]; then | ||
| echo "actions.lock check FAILED: a mismatched workflow does not start (startup_failure, zero jobs)." | ||
| exit 1 | ||
| fi | ||
| echo "actions.lock check: OK ($checked workflows match the lock)" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # | ||
| # Regression tests for tools/ci/check-actions-lock.sh. Each case appends a | ||
| # job to a copy of the real workflows and asserts whether the guard passes. | ||
| # A reference in step context is always checked; only a job-level call of a | ||
| # workflow file (`jobs.<id>.uses: …/.github/workflows/x.yml@ref`) is skipped. | ||
| # | ||
| # Usage: tools/ci/test-check-actions-lock.sh (from the repo root) | ||
| set -uo pipefail | ||
|
|
||
| guard=tools/ci/check-actions-lock.sh | ||
| work=$(mktemp -d) | ||
| trap 'rm -rf "$work"' EXIT | ||
| fails=0 | ||
|
|
||
| # expect <pass|fail> <name> <yaml appended to ci.yml> | ||
| expect() { | ||
| local want="$1" name="$2" yaml="$3" got | ||
| rm -rf "$work/wf" && mkdir "$work/wf" | ||
| cp .github/workflows/*.yml .github/workflows/actions.lock "$work/wf/" | ||
| printf '%s\n' "$yaml" >> "$work/wf/ci.yml" | ||
| if "$guard" "$work/wf" >/dev/null 2>&1; then got=pass; else got=fail; fi | ||
| if [[ "$got" == "$want" ]]; then | ||
| echo "ok $name" | ||
| else | ||
| echo "FAIL $name (expected $want, got $got)" | ||
| fails=$((fails + 1)) | ||
| fi | ||
| } | ||
|
|
||
| expect pass "real workflows" "" | ||
| expect fail "unlocked step action" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - uses: acme/build-action@v1' | ||
| expect fail "step action under a .github/workflows/*.yml directory" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - name: odd | ||
| uses: acme/repo/.github/workflows/my-action.yml@v1' | ||
| expect fail "indentless step sequence" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - name: odd | ||
| uses: acme/repo/.github/workflows/my-action.yml@v1' | ||
| expect fail "flow sequence on the steps: line" ' t: | ||
| runs-on: x | ||
| steps: [{uses: acme/repo/.github/workflows/f.yml@v2}]' | ||
| expect fail "flow mapping step" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - {uses: acme/build-action@v1, with: {a: b}}' | ||
| expect fail "quoted key, spaced colon" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - "uses" : acme/build-action@v1' | ||
| expect fail "ref containing a slash" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - uses: acme/build-action@release/v1' | ||
| expect fail "folded scalar fails closed" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - uses: >- | ||
| acme/build-action@v1' | ||
| expect fail "job-level non-workflow path is still an action" ' t: | ||
| uses: acme/repo/.github/workflows/my-action@v1' | ||
| expect pass "job-level reusable workflow call" ' t: | ||
| uses: acme/repo/.github/workflows/x.yml@0123456789abcdef0123456789abcdef01234567' | ||
| expect pass "reusable call after an indentless steps block" ' a: | ||
| runs-on: x | ||
| steps: | ||
| - run: echo | ||
| timeout-minutes: 5 | ||
| b: | ||
| uses: acme/repo/.github/workflows/x.yaml@v1' | ||
| expect pass "local action and docker image" ' t: | ||
| runs-on: x | ||
| steps: | ||
| - uses: ./tools/local-action | ||
| - uses: docker://alpine:3' | ||
|
|
||
| if [[ "$fails" -ne 0 ]]; then | ||
| echo "check-actions-lock self-test: $fails case(s) FAILED" | ||
| exit 1 | ||
| fi | ||
| echo "check-actions-lock self-test: OK" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.