#!/usr/bin/env bash set -euo pipefail repository_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) cd "$repository_dir" # Use the installed toolchain unless the caller explicitly selects another. # Toolchains and dependencies must already be available locally. export GOTOOLCHAIN=${GOTOOLCHAIN:-local} export GOPROXY=off go version 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 # --no-index returns 1 for differing content even when whitespace is clean; # whitespace errors return 2. Preserve other failures as well. git diff --no-index --check -- /dev/null "$candidate_file" || { check_status=$? if ((check_status != 1)); then exit "$check_status" fi } done < <(git ls-files --others --exclude-standard -z) go test ./... go vet ./... go build ./...