mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 08:14:55 +08:00
27 lines
607 B
Bash
27 lines
607 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "${repo_root}"
|
|
|
|
: "${GOCACHE:=/tmp/bat-go-cache}"
|
|
export GOCACHE
|
|
|
|
mapfile -t go_dirs < <(go list -f '{{.Dir}}' ./...)
|
|
go_files=()
|
|
for dir in "${go_dirs[@]}"; do
|
|
while IFS= read -r -d '' file; do
|
|
go_files+=("${file}")
|
|
done < <(find "${dir}" -maxdepth 1 -type f -name '*.go' -print0)
|
|
done
|
|
|
|
if ((${#go_files[@]} == 0)); then
|
|
exit 0
|
|
fi
|
|
|
|
formatted="$(gofmt -l "${go_files[@]}")"
|
|
if [[ -n "${formatted}" ]]; then
|
|
printf 'gofmt required; files need formatting:\n%s\n' "${formatted}" >&2
|
|
exit 1
|
|
fi
|