mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 06:34:54 +08:00
76 lines
2.3 KiB
Bash
76 lines
2.3 KiB
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
|
|
: "${XDG_CACHE_HOME:=/tmp/bat-xdg-cache}"
|
|
export XDG_CACHE_HOME
|
|
|
|
run_required() {
|
|
local name="$1"
|
|
shift
|
|
printf 'RUN required: %s\n' "${name}"
|
|
"$@"
|
|
printf 'PASS required: %s\n' "${name}"
|
|
}
|
|
|
|
check_gofmt() {
|
|
local -a go_dirs=()
|
|
local -a go_files=()
|
|
local dir file formatted dirs_file
|
|
dirs_file="$(mktemp)"
|
|
if ! go list -f '{{.Dir}}' ./... >"${dirs_file}"; then
|
|
rm -f "${dirs_file}"
|
|
return 1
|
|
fi
|
|
mapfile -t go_dirs <"${dirs_file}"
|
|
rm -f "${dirs_file}"
|
|
for dir in "${go_dirs[@]}"; do
|
|
for file in "${dir}"/*.go; do
|
|
[[ -f "${file}" ]] && go_files+=("${file}")
|
|
done
|
|
done
|
|
if ((${#go_files[@]} == 0)); then
|
|
return
|
|
fi
|
|
formatted="$(gofmt -l "${go_files[@]}")"
|
|
if [[ -n "${formatted}" ]]; then
|
|
printf 'gofmt required; files need formatting:\n%s\n' "${formatted}" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
run_required "Rust formatting" cargo fmt --all -- --check
|
|
run_required "Go formatting" check_gofmt
|
|
run_required "Rust check" cargo check --workspace --locked
|
|
run_required "Rust release build" cargo build --workspace --release --locked
|
|
run_required "Rust clippy" cargo clippy --workspace --all-targets --locked -- -D warnings
|
|
run_required "Rust tests" cargo test --workspace --locked
|
|
run_required "Go API tests" go test ./internal/api/... ./internal/backendrpc/... ./cmd/bat-api/...
|
|
run_required "Go API vet" go vet ./internal/api/... ./internal/backendrpc/... ./cmd/bat-api/...
|
|
run_required "Go API build" go build -o /tmp/bat-api ./cmd/bat-api
|
|
run_required "Documentation, OpenAPI, and contract checks" make check-docs
|
|
|
|
optional_failed=0
|
|
if command -v golangci-lint >/dev/null 2>&1; then
|
|
printf 'RUN optional: Go lint (golangci-lint)\n'
|
|
if golangci-lint run ./...; then
|
|
printf 'PASS optional: Go lint (golangci-lint)\n'
|
|
else
|
|
printf 'FAIL optional: Go lint (golangci-lint); reason=lint findings\n' >&2
|
|
optional_failed=1
|
|
fi
|
|
else
|
|
printf 'SKIP optional: Go lint (golangci-lint); reason=command not installed\n'
|
|
fi
|
|
|
|
if ((optional_failed)); then
|
|
printf 'required check-only gates passed; optional gates failed\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf 'required check-only gates passed; optional gates are reported above\n'
|