@@ -3,24 +3,28 @@ set +o histexpand
33
44# check-stale-lock-files.sh - Lightweight guard for stale .lock.yml files
55#
6- # Detects workflow .md files that have been modified (in the git working tree or
7- # staging area) without their compiled .lock.yml being regenerated.
6+ # Detects workflow .md files that changed without their compiled .lock.yml being
7+ # regenerated.
88#
99# Unlike check-workflow-drift.sh, this script does not require the gh-aw binary:
1010# it uses git to identify modified .md files and checks whether each has a
1111# corresponding .lock.yml that was also modified. Use check-workflow-drift.sh
1212# for a thorough recompile-based verification; use this script as a fast early
1313# gate that catches the obvious case where a .md was edited and not recompiled.
1414#
15- # When there are no modified .md files in the working tree or staging area the
16- # script exits 0 immediately, so it is a no-op on a clean checkout.
15+ # By default, the script inspects staged/unstaged changes in the current working
16+ # tree. With --base-ref, it instead compares HEAD to a base ref, which is useful
17+ # for CI runs on a clean checkout.
1718#
1819# Usage:
19- # check-stale-lock-files.sh [--dir <workflows-dir>]
20+ # check-stale-lock-files.sh [--dir <workflows-dir>] [--base-ref <git-ref>]
2021#
2122# Options:
2223# --dir <dir> Workflows directory to scan (default: .github/workflows).
2324# The script only examines .md files under this directory.
25+ # --base-ref <git-ref>
26+ # Git base ref used to detect changed files via
27+ # `git diff <base-ref>...HEAD`. Intended for CI.
2428#
2529# Exit codes:
2630# 0 - No modified .md files detected, or every modified .md has a
4448fi
4549
4650WORKFLOWS_DIR=" .github/workflows"
51+ BASE_REF=" "
4752
4853while [[ $# -gt 0 ]]; do
4954 case " $1 " in
5055 --dir)
5156 WORKFLOWS_DIR=" ${2:? --dir requires an argument} "
5257 shift 2
5358 ;;
59+ --base-ref)
60+ BASE_REF=" ${2:? --base-ref requires an argument} "
61+ shift 2
62+ ;;
5463 * )
5564 echo -e " ${RED} ERROR${NC} : unknown argument: $1 " >&2
56- echo " Usage: check-stale-lock-files.sh [--dir <workflows-dir>]" >&2
65+ echo " Usage: check-stale-lock-files.sh [--dir <workflows-dir>] [--base-ref <git-ref>] " >&2
5766 exit 1
5867 ;;
5968 esac
@@ -64,9 +73,21 @@ if [ ! -d "$WORKFLOWS_DIR" ]; then
6473 exit 1
6574fi
6675
67- # Collect all files that git sees as modified (staged or unstaged vs HEAD).
68- # On a clean checkout with no edits this set is empty, so the check is a no-op.
69- all_modified=$( git diff --name-only HEAD 2> /dev/null || true)
76+ collect_modified_files () {
77+ # Explicit base ref compare (clean checkout safe, CI-friendly).
78+ if [ -n " $BASE_REF " ]; then
79+ if git rev-parse --verify " ${BASE_REF} ^{commit}" > /dev/null 2>&1 ; then
80+ git diff --name-only " ${BASE_REF} ...HEAD" 2> /dev/null || true
81+ return
82+ fi
83+ echo -e " ${YELLOW} WARN${NC} : --base-ref not found (${BASE_REF} ); falling back to working-tree check." >&2
84+ fi
85+
86+ # Local contributor path: staged/unstaged vs HEAD.
87+ git diff --name-only HEAD 2> /dev/null || true
88+ }
89+
90+ all_modified=$( collect_modified_files)
7091
7192# Filter to .md files within the workflows directory.
7293# Strip a leading "./" from WORKFLOWS_DIR for consistent prefix matching.
@@ -88,6 +109,7 @@ stale_files=()
88109missing_locks=()
89110
90111while IFS= read -r md; do
112+ [ -f " $md " ] || continue
91113 [ -n " $md " ] || continue
92114 lock=" ${md% .md} .lock.yml"
93115
0 commit comments