Repository navigation
feat(scripts,agents): add diff-aware pre-commit/pre-push gates and pr-quality-ci skill - #1288
Conversation
…-quality-ci skill
There was a problem hiding this comment.
Code Review
This pull request introduces diff-scoped verification scripts (pre-commit.sh and pre-push.sh) along with corresponding Makefile targets and documentation to streamline local and CI-parity checks. Feedback on these changes points out an invalid --fail-fast flag used with gh pr checks in the documentation, a potential failure in pre-commit.sh when directory paths contain spaces, and portability issues caused by hardcoding /bin/bash in both the test suite and Makefile recipes.
| Never run `sleep` loops in a shell to poll CI. Watch checks asynchronously with `--fail-fast` so execution wakes immediately on the first failure without waiting up to an hour for `github-deploy-ondemand`: | ||
|
|
||
| ```bash | ||
| gh pr checks <pr_number> --repo GoogleCloudPlatform/khi --watch --fail-fast --interval 30 | ||
| ``` |
There was a problem hiding this comment.
| dir_has_go_files() { | ||
| local rel_dir="$1" | ||
| local abs_dir="${REPO_ROOT}/${rel_dir}" | ||
| [[ -d "${abs_dir}" ]] || return 1 | ||
| compgen -G "${abs_dir}/*.go" >/dev/null | ||
| } |
There was a problem hiding this comment.
The use of compgen -G to check for the existence of Go files will fail if the repository path contains spaces, because compgen -G performs word splitting on its argument before expanding the glob. To make this robust against spaces in directory paths, use a standard glob loop instead.
| dir_has_go_files() { | |
| local rel_dir="$1" | |
| local abs_dir="${REPO_ROOT}/${rel_dir}" | |
| [[ -d "${abs_dir}" ]] || return 1 | |
| compgen -G "${abs_dir}/*.go" >/dev/null | |
| } | |
| dir_has_go_files() { | |
| local rel_dir="$1" | |
| local abs_dir="${REPO_ROOT}/${rel_dir}" | |
| [[ -d "${abs_dir}" ]] || return 1 | |
| local f | |
| for f in "${abs_dir}"/*.go; do | |
| [[ -e "${f}" ]] && return 0 | |
| done | |
| return 1 | |
| } |
| writeStubCLIs(t, binDir, callsFile, diffFixture) | ||
|
|
||
| scriptPath := filepath.Join(realRepoRoot, "scripts", tc.scriptName) | ||
| cmd := exec.CommandContext(context.Background(), "/bin/bash", scriptPath) |
There was a problem hiding this comment.
Hardcoding /bin/bash makes the test suite incompatible with Windows environments (even when Git Bash or MSYS2 is installed and bash is in the PATH) and some non-standard Unix environments. Using "bash" directly allows Go's exec.CommandContext to look up the executable in the system's PATH dynamically.
| cmd := exec.CommandContext(context.Background(), "/bin/bash", scriptPath) | |
| cmd := exec.CommandContext(context.Background(), "bash", scriptPath) |
| fi \ | ||
| fi | ||
| pre-commit: ## Auto-format and run fast static checks on modified files in working copy | ||
| @/bin/bash ./scripts/pre-commit.sh |
There was a problem hiding this comment.
|
|
||
| .PHONY: pre-push | ||
| pre-push: ## Run full CI-parity verification gates on changed branch files (optional: BASE=<rev>) | ||
| @BASE="$(BASE)" /bin/bash ./scripts/pre-push.sh |
There was a problem hiding this comment.
Go Quality Report (
|
| Metric | Result |
|---|---|
| Changed Scope | 0 prod file(s), 1 test file(s), 6 unit(s) |
| Patch Coverage | 100.0% (0/0 lines) |
| Mutation Score | 100.0% (0/0 killed, 0 survived) |
Commit: ea51184d0c05 · Cloud Build Logs
Summary
Consolidates local code quality verification into two diff-aware
makecommands (make pre-commitandmake pre-push) and adds thepr-quality-ciagent skill to minimize pre-push rework and standardize autonomous post-PR CI monitoring, transient failure reruns, review triage, and incrementaljjfixes.What Changed
Diff-Scoped
make pre-commit& CI-Paritymake pre-push(scripts/pre-commit.sh,scripts/pre-push.sh,scripts/make/*.mk):make pre-commit: Inspects modified files in the active working copy (@in Jujutsu, or index/working tree in Git), running only the formatters and fast static checks relevant to touched domains (add-licenses, Proto, package-scoped Goformat-go/lint-go+codequality-fast, Web, misc YAML/JSON, and Markdown). Fails explicitly when@is empty instead of silently passing as a no-op.make pre-push(optionalBASE=<parent-bookmark>for stacked PRs): Evaluatesfork_point(BASE | @)..@across the branch diff and runs affected CI gates in fail-fast order with GitHub Actions (PR Tests) and Cloud Build (github-codequality) parity — includingcheck-licenses,lint-*,build-web(prod+dev),build-storybook, cross-OSbuild-go-binaries, unit tests, and differentialcodequalitywith unlimited mutants (CODEQUALITY_MAX=0,CODEQUALITY_TIMEOUT=10m).CODEQUALITY_BASE/CODEQUALITY_TARGETshell arguments inscripts/make/testing.mkso Jujutsu revsets such astrunk()pass cleanly, and removes the duplicatecodequalityentry inmake help.scripts/codequality/hooks_script_test.go.Agent Skill & Workflow Documentation (
.agents/skills/pr_quality_ci/SKILL.md,.agents/skills/jj_workflow/SKILL.md,GEMINI.md,scripts/GEMINI.md):pr-quality-cicovering the two-command local verification workflow,codequalityremediation priority, PR creation, non-pollinggh pr checks --watch --fail-fastmonitoring, transient failure CI reruns (gh run rerun --failedand Check Runrerequest), sticky<!-- khi-codequality-report -->commit-SHA freshness checks, criticalgemini-code-assist[bot]/ reviewer comment evaluation, no-squash incremental fix pushes, and review thread / PR summary commenting rules.jj-workflow,GEMINI.md, andscripts/GEMINI.mdontomake pre-commitandmake pre-push.Verification
go test -v ./scripts/codequality -run TestHookScripts:PASSmake pre-commit:PASSmake pre-push:PASS(0violations acrosscheck-licenses,lint-md,lint-go,codequality-fast,test-go,build-go-binaries, andcodequality-gowithCODEQUALITY_MAX=0)