Files
ConfigKit/scripts/release-check.sh

80 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repository_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
cd "$repository_dir"
baseline_toolchain=${CONFIGKIT_BASELINE_TOOLCHAIN:?set CONFIGKIT_BASELINE_TOOLCHAIN to a cached supported Go 1.25 patch release}
run_go() {
local toolchain=$1
shift
GOTOOLCHAIN="$toolchain" GOPROXY=off go "$@"
}
check_toolchain() {
local toolchain=$1
GOTOOLCHAIN="$toolchain" GOPROXY=off go version >/dev/null
run_go "$toolchain" mod download
}
check_toolchain "$baseline_toolchain"
bash -n scripts/release-check.sh
temporary_dir=$(mktemp -d)
trap 'rm -rf -- "$temporary_dir"' EXIT
candidate_manifest=$temporary_dir/candidate-files
while IFS= read -r -d '' candidate_file; do
if [[ -e "$candidate_file" || -L "$candidate_file" ]]; then
printf '%s\0' "$candidate_file" >>"$candidate_manifest"
fi
done < <(git ls-files --cached --others --exclude-standard -z)
tar --null --files-from="$candidate_manifest" --create --file=- |
tar --extract --file=- --directory="$temporary_dir"
(
cd "$temporary_dir"
GOTOOLCHAIN="$baseline_toolchain" GOPROXY=off go mod tidy
)
diff -u go.mod "$temporary_dir/go.mod"
diff -u go.sum "$temporary_dir/go.sum"
go_files=()
while IFS= read -r -d '' go_file; do
if [[ -f "$go_file" ]]; then
go_files+=("$go_file")
fi
done < <(git ls-files --cached --others --exclude-standard -z -- '*.go')
if ((${#go_files[@]})); then
unformatted=$(gofmt -l -- "${go_files[@]}")
if [[ -n "$unformatted" ]]; then
printf 'gofmt required for:\n%s\n' "$unformatted" >&2
exit 1
fi
fi
git diff --check HEAD --
while IFS= read -r -d '' candidate_file; do
if [[ ! -f "$candidate_file" ]]; then
continue
fi
case "$candidate_file" in
*.go|*.md|*.sh|go.mod|go.sum|LICENSE|.gitignore|AGENTS.md)
if LC_ALL=C grep -nE '[[:blank:]]+$' -- "$candidate_file"; then
printf 'trailing whitespace found in %s\n' "$candidate_file" >&2
exit 1
fi
;;
esac
done < <(git ls-files --cached --others --exclude-standard -z)
# Verbose output reports skipped cases without a separate evidence run.
run_go "$baseline_toolchain" test -race -v ./...
run_go "$baseline_toolchain" vet ./...
# Only release-validated targets gate publication; macOS is best-effort.
for target in linux/amd64 linux/arm64; do
target_os=${target%/*}
target_arch=${target#*/}
GOTOOLCHAIN="$baseline_toolchain" GOPROXY=off CGO_ENABLED=0 GOOS="$target_os" GOARCH="$target_arch" go build ./...
done