mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-11-23 15:11:15 +08:00
Why: 1. In tests/lite_smoke/lite_e2e_test.go, exited was a 1-buffered channel sent once without closing: if waitForHealth consumed <-exited on an early server crash, t.Cleanup blocked forever on <-exited; serverLogs also used an unsynchronized bytes.Buffer read concurrently on startup/shutdown timeouts under -race, and subprocess/client HTTP calls could inherit developer ENV_FILE, REDIS_ADDR, or proxy settings. 2. frontend/src/utils/catalogToolDisplay.test.ts asserts UI locale coverage against docs/swagger.json, but frontend.yml did not trigger on swagger.json changes. 3. pre-push and cli.yml enforced gofmt on client/ and root Go files, but skipped gofmt checks on changed cli/**/*.go files, and cli-e2e.yml omitted client/go.sum from its Go cache key. What: - Replace single-read exited channel and raw bytes.Buffer in lite_e2e_test.go with a closed done channel + mutex-guarded syncBuffer, and isolate subprocess ENV_FILE/REDIS_ADDR/NO_PROXY and loopback HTTP transport from local proxies. - Add docs/swagger.json to frontend.yml push and pull_request path triggers. - Check gofmt on all changed Go files in pre-push and changed cli Go files in cli.yml, and add client/go.sum to cli-e2e.yml cache-dependency-path.
89 lines
2.3 KiB
Bash
Executable File
89 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Pre-push checks aligned with CI (.github/workflows/app.yml, frontend.yml, cli.yml).
|
|
|
|
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"
|
|
|
|
remote="${1:-origin}"
|
|
while read -r _local_ref local_sha remote_ref remote_sha; do
|
|
if [[ "$local_sha" =~ ^0+$ ]]; then
|
|
continue
|
|
fi
|
|
|
|
log_step "pre-push ($remote ${remote_ref#refs/heads/})"
|
|
|
|
ensure_origin_main
|
|
pr_ref="$(pr_diff_base_ref)"
|
|
pr_tip="$local_sha"
|
|
pr_diff="${pr_ref}...${pr_tip}"
|
|
lint_from_rev="$pr_ref"
|
|
|
|
if [[ "$remote_sha" =~ ^0+$ ]]; then
|
|
push_start="$(git -C "$ROOT" merge-base "$pr_ref" "$local_sha")"
|
|
push_range="${push_start}..${local_sha}"
|
|
log_step "new branch; PR diff ${pr_ref}...${local_sha:0:12}"
|
|
else
|
|
if [[ "$remote_sha" == "$local_sha" ]]; then
|
|
log_ok "pre-push: nothing new to push"
|
|
continue
|
|
fi
|
|
push_range="${remote_sha}..${local_sha}"
|
|
log_step "pushing ${remote_sha:0:12}..${local_sha:0:12}; PR diff ${pr_ref}...${local_sha:0:12}"
|
|
fi
|
|
|
|
check_whitespace "$push_range"
|
|
|
|
pr_changed=()
|
|
while IFS= read -r line; do
|
|
[[ -n "$line" ]] && pr_changed+=("$line")
|
|
done < <(git diff --name-only --diff-filter=ACMR "$pr_diff" || true)
|
|
|
|
if [[ ${#pr_changed[@]} -eq 0 ]]; then
|
|
log_ok "pre-push: no PR diff changes"
|
|
continue
|
|
fi
|
|
|
|
all_changed_go=()
|
|
while IFS= read -r line; do
|
|
[[ -n "$line" ]] && all_changed_go+=("$ROOT/$line")
|
|
done < <(git diff --name-only --diff-filter=ACMR "$pr_diff" -- '*.go' || true)
|
|
if [[ ${#all_changed_go[@]} -gt 0 ]]; then
|
|
check_gofmt_files check "${all_changed_go[@]}"
|
|
fi
|
|
|
|
pr_changed_go=()
|
|
while IFS= read -r line; do
|
|
[[ -n "$line" ]] && pr_changed_go+=("$line")
|
|
done < <(git diff --name-only --diff-filter=ACMR "$pr_diff" -- '*.go' ':!cli/**' ':!client/**' || true)
|
|
|
|
if [[ ${#pr_changed_go[@]} -gt 0 ]]; then
|
|
run_golangci_if_available "$lint_from_rev"
|
|
|
|
run_app_vet_test
|
|
|
|
log_step "go build ./cmd/server"
|
|
go build ./cmd/server
|
|
log_ok "go build ./cmd/server"
|
|
fi
|
|
|
|
if paths_match_prefix "cli/" "${pr_changed[@]}" || paths_match_prefix "client/" "${pr_changed[@]}"; then
|
|
run_cli_checks
|
|
fi
|
|
if paths_match_prefix "frontend/" "${pr_changed[@]}"; then
|
|
run_frontend_checks
|
|
fi
|
|
|
|
log_ok "pre-push passed"
|
|
done
|
|
|
|
exit 0
|