utils/scripts/dep_freshness_changed.sh
Krzysztof kuhy Rudnicki c75f6310b0
Some checks are pending
app_errors tests / test (push) Waiting to run
crdt-sync pre-commit / pre-commit (push) Waiting to run
crdt-sync tests / test (push) Waiting to run
earned_time pre-commit / pre-commit (push) Waiting to run
earned_time tests / test (push) Waiting to run
file length / file-length (push) Waiting to run
focus-project pre-commit / pre-commit (push) Waiting to run
focus-project tests / test (push) Waiting to run
freedays pre-commit / pre-commit (push) Waiting to run
freedays tests / test (push) Waiting to run
game_recording pre-commit / pre-commit (push) Waiting to run
game_recording tests / test (push) Waiting to run
gatelock pre-commit / pre-commit (push) Waiting to run
gatelock tests / test (push) Waiting to run
holds pre-commit / pre-commit (push) Waiting to run
holds tests / test (push) Waiting to run
leetcode-coach pre-commit / pre-commit (push) Waiting to run
leetcode-coach tests / test (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
music_theory tests / test (push) Waiting to run
omniroute_offload pre-commit / pre-commit (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
sickdays pre-commit / pre-commit (push) Waiting to run
sickdays tests / test (push) Waiting to run
sql-drills pre-commit / pre-commit (push) Waiting to run
sql-drills tests / test (push) Waiting to run
get rid of github ci/cd version check of package…
Todo: 2556952d
2026-11-19 18:11:07 +01:00

76 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# dep_freshness_changed.sh - run the dependency-freshness gate on the
# manifests THIS BRANCH changed, not on every manifest pre-commit hands over.
#
# Why: `pre-commit run --all-files` (the todoImplementer runner's check) passes
# every manifest in the monorepo, so one feature branch went red on 43 stale
# pins in 12 projects it never touched. Scoping to changed manifests makes the
# hook answer "did this change leave a stale pin?". The repo-wide question
# is a local sweep (scripts/check_dependency_freshness.sh --all --strict);
# there is no CI workflow for it (.dep-freshness-no-workflow).
#
# "Changed" = differs from the merge-base with $DEP_FRESHNESS_BASE (default
# main, then origin/main), working tree included, plus untracked files.
# A plain commit only passes staged files, which are all "changed", so normal
# commits behave exactly as before.
#
# Fails closed: no resolvable base, or a cwd that is not the repo root (so
# paths cannot be compared), forwards every file unfiltered.
#
# Usage: scripts/dep_freshness_changed.sh <file>...
# Env: DEP_FRESHNESS_GATE gate to call (default: check_dependency_freshness.sh
# next to this script); DEP_FRESHNESS_BASE (main)
# ============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_DIR
readonly GATE="${DEP_FRESHNESS_GATE:-$SCRIPT_DIR/check_dependency_freshness.sh}"
readonly BASE="${DEP_FRESHNESS_BASE:-main}"
# Print the merge-base with $BASE (or origin/$BASE); empty when neither exists.
merge_base() {
local ref
for ref in "$BASE" "origin/$BASE"; do
if git rev-parse --verify --quiet "$ref^{commit}" >/dev/null; then
git merge-base HEAD "$ref" 2>/dev/null && return
fi
done
}
# Print root-relative paths changed since $1, one per line.
changed_since() {
git diff --name-only "$1"
git ls-files --others --exclude-standard --full-name
}
main() {
local base
base="$(merge_base || true)"
if [[ -z "$base" || -n "$(git rev-parse --show-prefix)" ]]; then
exec bash "$GATE" "$@"
fi
local -A changed=()
local path
while IFS= read -r path; do
changed["$path"]=1
done < <(changed_since "$base")
local -a keep=()
for path in "$@"; do
if [[ -n "${changed[$path]:-}" ]]; then
keep+=("$path")
fi
done
if [[ ${#keep[@]} -eq 0 ]]; then
exit 0
fi
exec bash "$GATE" "${keep[@]}"
}
main "$@"