mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-11-22 07:57:56 +08:00
Why:
1. With docs/docs.go embedding swagger.json via //go:embed instead of codegen,
editing docs/swagger.{json,yaml} or docs/swag.overrides without touching a
.go file would bypass .github/workflows/app.yml path filters.
2. Cross-platform localsandbox CI only test-compiled seatbelt on darwin and
skipped go test -c across the remaining darwin/windows localsandbox packages.
3. Excluding client/** from root pre-push Go checks dropped local gofmt
enforcement on client/*.go and inherited developer WEKNORA_LOG_FORMAT in
client/cli hook test runs.
What:
- Add docs/swagger.json, docs/swagger.yaml, and docs/swag.overrides to app.yml
push and pull_request path triggers.
- Compile test binaries (go test -c) for every ./internal/localsandbox/...
package on both darwin/arm64 and windows/amd64, and include client/go.sum in
cli.yml cache-dependency-path.
- Enforce gofmt -l . and WEKNORA_LOG_FORMAT="" in run_client_checks() /
run_cli_checks(), format staged cli/client Go files in pre-commit, and add
regression coverage in scripts/test-git-hooks.sh.
41 lines
1009 B
Bash
Executable File
41 lines
1009 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Fast checks on staged files (PR checklist + gofmt). Mirrors app.yml formatting gate.
|
|
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
# shellcheck source=scripts/git-hooks/common.sh
|
|
source "$ROOT/scripts/git-hooks/common.sh"
|
|
|
|
if hook_skip; then
|
|
exit 0
|
|
fi
|
|
|
|
cd "$ROOT"
|
|
|
|
log_step "pre-commit"
|
|
|
|
check_whitespace --cached
|
|
|
|
staged_go=()
|
|
while IFS= read -r line; do
|
|
[[ -n "$line" ]] && staged_go+=("$line")
|
|
done < <(git diff --cached --name-only --diff-filter=ACMR -- '*.go' || true)
|
|
|
|
if [[ ${#staged_go[@]} -gt 0 ]]; then
|
|
go_files=()
|
|
for f in "${staged_go[@]}"; do
|
|
go_files+=("$ROOT/$f")
|
|
done
|
|
check_gofmt_files write "${go_files[@]}"
|
|
|
|
if git diff --cached --name-only --diff-filter=ACMR -- '*.go' ':!cli/**' ':!client/**' | grep -q .; then
|
|
if command -v golangci-lint >/dev/null 2>&1; then
|
|
# Lint only what differs from HEAD (staged + unstaged in root module packages).
|
|
run_golangci_if_available HEAD
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
log_ok "pre-commit passed"
|