beads/scripts/repochecks/run_check.sh
Julian Knutsen b1fe68e63a
ci(bazel): run pr.yml's repository guards as Bazel tests (#7329)
fast-checks, PR Policy, and the Linux leg of check-doc-freshness-platforms
ran repository guards on GitHub runners. They now run as Bazel tests in
bazel.yml's `test` lane (remote, cached), each over only the files it reads:

- tools/bazel/repo_subset.bzl picks a narrow, path-selected slice of
  //:repo_files at analysis time. scripts/repochecks/run_check.sh copies that
  slice into a throwaway git checkout and runs the unchanged guard there.
- //scripts/repochecks: build_tags, workflow_tags, go_install_guidance,
  winget_portable_alias, migration_hygiene (checks A and B),
  fmt (registered SDK gofmt), doc_freshness, workapi_frontend_boundary,
  types_gen_drift (`make api-check` drift, oapi-codegen from go.mod).
- //scripts:doc_freshness_required_test (integration lane, -required-suite)
  and //scripts/gitattributespolicy:gitattributespolicy_required_host_test
  cover the Linux doc-freshness leg.
- check-versions stays covered by //internal/versioncheck:versioncheck_test.
  check-testing-short stays covered by //scripts:scripts_test.

pr-policy-wrapper is deleted. fast-checks keeps only the two checks that
need the PR base: migration hygiene's delta half (MIGRATION_HYGIENE_SCOPE=
delta) and the .beads diff. check-doc-flags stays, because it builds bd from
the pinned release tag. The example Go modules leave .bazelignore so gofmt
and the grep guards see them. check_testcases.py now accepts --not-go
//pkg:all.

Refs: ga-96smfk.20

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 00:59:18 +00:00

74 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# run_check.sh: run a repository guard over a declared slice of the checkout.
#
# run_check.sh [--tree MANIFEST]... [--env NAME=RLOCATION]... \
# [--path RLOCATION]... -- PROGRAM [ARG...]
#
# The guards under scripts/ (check-build-tags.sh, fmt-check.sh, ...) walk the
# repository root above their own directory, often with `git ls-files` or
# `git grep`. Under `bazel test` they get instead a throwaway checkout built
# from exactly their declared inputs:
#
# --tree MANIFEST a repo_subset manifest (tools/bazel/repo_subset.bzl),
# as an rlocation path: every file it lists is copied
# (dereferenced) to its checkout path, then the tree is
# `git add`ed, so git ls-files/grep see those files.
# --env NAME=RLOC export NAME as the absolute path of a runfile (e.g.
# GOFMT=<the registered SDK's gofmt>).
# --path RLOC put the runfile's directory first on PATH.
#
# PROGRAM is a checkout path (scripts/check-build-tags.sh) when the tree holds
# it, so the guard resolves its repository root to the tree; otherwise an
# rlocation path (a Bazel-built tool). It runs from the tree's root.
set -euo pipefail
runfiles="${TEST_SRCDIR:?run_check.sh runs under bazel test}"
tree="${TEST_TMPDIR:?}/checkout"
manifests=()
path_dirs=()
envs=()
while [[ $# -gt 0 ]]; do
case "$1" in
--tree) manifests+=("$2"); shift 2 ;;
--env) envs+=("$2"); shift 2 ;;
--path) path_dirs+=("$2"); shift 2 ;;
--) shift; break ;;
*) echo "run_check.sh: unknown argument $1" >&2; exit 2 ;;
esac
done
[[ $# -ge 1 ]] || { echo "run_check.sh: no PROGRAM" >&2; exit 2; }
[[ ${#manifests[@]} -gt 0 ]] || { echo "run_check.sh: no --tree" >&2; exit 2; }
rm -rf "$tree"
mkdir -p "$tree"
files=0
for m in "${manifests[@]}"; do
while read -r rel rloc; do
[[ -n "$rel" ]] || continue
mkdir -p "$tree/$(dirname "$rel")"
cp -L "$runfiles/$rloc" "$tree/$rel"
files=$((files + 1))
done <"$runfiles/$m"
done
echo "run_check.sh: checkout of $files declared files"
git -C "$tree" init -q
git -C "$tree" add -f -A .
for e in "${envs[@]+"${envs[@]}"}"; do
export "${e%%=*}=$runfiles/${e#*=}"
done
for p in "${path_dirs[@]+"${path_dirs[@]}"}"; do
PATH="$(dirname "$runfiles/$p"):$PATH"
done
export PATH
program="$1"
shift
if [[ -e "$tree/$program" ]]; then
program="$tree/$program"
else
program="$runfiles/$program"
fi
cd "$tree"
exec "$program" "$@"