Files
full/scripts/verify-workspace.sh
2026-09-22 21:15:34 +08:00

42 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -Eeuo pipefail
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
readonly WORKSPACE_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
cd -- "${WORKSPACE_ROOT}"
# 本地开发前提go.work 把共享 SDK 替换为工作区外的相对路径,缺少该目录时整个工作区都无法解析。
readonly SDK_DIR="${WORKSPACE_ROOT}/../../bsm-sdk/core"
if [[ ! -d "${SDK_DIR}" ]]; then
echo "error: 未找到共享 SDK 目录: ${SDK_DIR}" >&2
echo "error: 本地开发前提不满足:请先将 bsm-sdk/core 检出到工作区上一级目录的同级路径,即 ${SDK_DIR}" >&2
exit 1
fi
unformatted="$(gofmt -l pkgs module scripts)"
if [[ -n "${unformatted}" ]]; then
printf 'error: gofmt required:\n%s\n' "${unformatted}" >&2
exit 1
fi
mapfile -t modules < <(go list -m -f '{{.Dir}}')
if (( ${#modules[@]} == 0 )); then
echo "error: 未解析到任何工作区模块go list -m 可能失败或返回空列表" >&2
exit 1
fi
for module_dir in "${modules[@]}"; do
echo "==> ${module_dir}"
(
cd -- "${module_dir}"
if [[ "${SKIP_VET:-0}" != "1" ]]; then
go vet ./...
fi
go test ./...
)
done
echo "Workspace verification completed successfully."