Files
BlueArchiveToolkit/scripts/ci-check.sh
T
nyaKazuha c17904ee1c
bat-rust / Build and test Rust (push) Canceled after 0s
bat-rust / Build and test Go API (push) Canceled after 0s
fix(repo):统一发布健康与只读质量门禁
2026-09-13 22:09:44 +08:00

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'