beads/scripts/check-winget-portable-alias.sh
Julian Knutsen 0500fc6f40
ci(bazel): run the scripts and source-walking tests remotely; retire their go test legs (#7320)
//scripts:scripts_test and //scripts/check-versions:check-versions_test
drop their host-tools/no-remote-exec/no-remote-cache tags and run on the
rbe-west workers like every other target (the worker image ships bash, git,
python3, jq, yq, curl, openssl, unzip and coreutils; a missing tool fails the
test under Bazel rather than skipping it). Go comes in hermetically as the
registered SDK; check-versions.sh's `go build` is stood in for by the
Bazel-built checker.

The tests that walked the source checkout now get it as data:
tools/bazel/go_srcs.py keeps a managed `repo_files` filegroup in every
package and aggregates them into //:repo_files (exactly the tracked files
Bazel can see; make bazel-sync-check fails on a package without one).
scripts_test and docsync_test take it instead of hand-listed filegroups,
and every TEST_SRCDIR/IsBazel skip and go-test-only block in them is gone.
The release formula under .bazelignore'd .beads/ comes in through a
@beads_formulas local repository; npm-package/ and .claude/ are visible to
Bazel again (only their node_modules/worktrees stay ignored), so the npm
manifest release check and the AGENTS.md skill links run under Bazel too.
TestZZStdioNotLeaked falls back to TestMain's pre-run streams instead of
skipping in a shard without its baseline.

tools/bazel/equivalence_allowlist.txt shrinks from 20 skip entries to the
two cmd/bd tests of plain go test's own bd build fallback, which Bazel never
takes; pr-preflight-platforms now runs them on Linux, macOS and Windows. The
scripts-go-checks scripts-test and allowlisted legs, their scripts
(scripts-go-test.sh, allowlisted-go-tests.sh, run_allowlisted_go_tests.py)
and main.yml's --compile-only warm for them are removed. The vet leg stays
(ga-96smfk.18).

Refs: ga-96smfk.16

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-06 22:20:16 +00:00

71 lines
2.9 KiB
Bash
Executable file

#!/bin/bash
# Guard: winget installer manifests must set PortableCommandAlias (GH#4908).
# Parses with yq rather than grep so a corrupt/unparseable manifest (e.g. a
# multi-line InstallerSha256 from a checksum-matching bug) fails loudly
# instead of a bare substring match reporting OK.
#
# yq flavour portability: these expressions stay inside the vocabulary shared
# by mikefarah yq v4 (what ubuntu-latest ships) and python-yq/jq — identity,
# `==`, `[]`, `select`, and `-e`'s exit status. Avoid builtins the two spell
# differently, e.g. jq's `any(cond)` against mikefarah's `any_c`.
set -euo pipefail
# No workflow job installs yq (ubuntu-latest and the rbe-west workers ship
# it), so name a missing tool instead of reporting every manifest as missing
# its alias.
if ! command -v yq >/dev/null 2>&1; then
echo "FAIL: yq is required by this guard but is not installed"
exit 1
fi
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
shopt -s nullglob
files=("$ROOT"/winget/*.installer.yaml)
if [ "${#files[@]}" -eq 0 ]; then
echo "FAIL: no winget/*.installer.yaml files found"
exit 1
fi
# The placeholder scripts/update-winget.sh substitutes when a release publishes
# no windows_arm64 checksum.
ZERO_SHA256="0000000000000000000000000000000000000000000000000000000000000000"
fail=0
for f in "${files[@]}"; do
# Parse before classifying. An unparseable manifest has to fail here rather
# than fall through the NestedInstallerType test below and get skipped as
# "not portable". yq's own diagnostic is left on stderr deliberately: the
# point of this guard is that a missing tool or a parse error is
# distinguishable from a missing alias.
if ! yq -e '.' "$f" >/dev/null; then
echo "FAIL: $f is not parseable YAML"
fail=1
continue
fi
# PortableCommandAlias exists only for nested portable installers, so an
# msi/exe/msix manifest added later is outside this guard's class rather than
# in violation of it.
if ! yq -e '.NestedInstallerType == "portable"' "$f" >/dev/null; then
echo "SKIP: $f is not a nested portable installer"
continue
fi
if yq -e '.NestedInstallerFiles[] | select(.PortableCommandAlias == "bd")' "$f" >/dev/null; then
echo "OK: $f has PortableCommandAlias"
else
echo "FAIL: $f missing valid PortableCommandAlias: bd (GH#4908)"
fail=1
fi
# Placeholder-hash tripwire. Advisory, not fatal: the only occurrence in the
# tree today is the arm64 entry of the legacy SteveYegge manifest, which this
# guard does not otherwise gate, so failing would turn a required check red
# over pre-existing content. grep is deliberate here — this looks for a
# known-bad literal, so unlike the alias assertion above it can only miss a
# bad value, never report OK on a manifest it failed to understand.
if grep -Eq "InstallerSha256:[[:space:]]*\"?${ZERO_SHA256}\"?[[:space:]]*\$" "$f"; then
echo "WARNING: $f carries a placeholder all-zero InstallerSha256 — do not publish that entry"
fi
done
exit "$fail"