-
Notifications
You must be signed in to change notification settings - Fork 52
feat(pre-push): add format/verbosity/log-dir parity with pre-commit (#1780) #1783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josecelano
merged 9 commits into
torrust:develop
from
josecelano:1780-refactor-pre-push-checks-performance-and-verbosity
May 14, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bda95ee
docs(issues): record design decisions and refine plan for #1780
josecelano f5bfe34
feat(pre-push): add format/verbosity/log-dir parity with pre-commit
josecelano 1489823
docs(skills): add run-pre-push-checks skill and update pre-commit skill
josecelano d2d1420
chore(git-hooks): add pre-push dispatcher to .githooks
josecelano d006839
chore(git-hooks): make output mode explicit in .githooks dispatchers
josecelano 3987eba
chore(git-hooks): use JSON as default output format in .githooks disp…
josecelano fc3f80c
docs(git-hooks): skip manual hook run when git hook is already installed
josecelano 0787de6
fix(git-hooks): address Copilot PR review and simplify log-dir env var
josecelano a916d0b
fix(git-hooks): address Copilot PR review round 2
josecelano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| repo_root="$(git rev-parse --show-toplevel)" | ||
|
|
||
| # Use human-friendly text format when stdout is a terminal; JSON for non-interactive / agent runs. | ||
| if [[ -t 1 ]]; then | ||
| "$repo_root/contrib/dev-tools/git/hooks/pre-push.sh" --format=text | ||
| else | ||
| "$repo_root/contrib/dev-tools/git/hooks/pre-push.sh" --format=json | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
.github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| name: run-pre-push-checks | ||
| description: Run all mandatory pre-push verification steps for the torrust-tracker project. Covers the pre-push script (automated checks), output modes, and log-directory configuration. Use before pushing or when running the comprehensive developer gate including nightly checks and E2E tests. Triggers on "pre-push checks", "run pre-push", "verify before push", or "push checks". | ||
| metadata: | ||
| author: torrust | ||
| version: "1.0" | ||
| --- | ||
|
|
||
| # Run Pre-push Checks | ||
|
|
||
| ## Git Hook (Recommended Setup) | ||
|
|
||
| The repository ships a `pre-push` Git hook that runs `./contrib/dev-tools/git/hooks/pre-push.sh` | ||
| automatically on every `git push`. Install it once after cloning: | ||
|
|
||
| ```bash | ||
| ./contrib/dev-tools/git/install-git-hooks.sh | ||
| ``` | ||
|
|
||
| After installation the hook fires automatically; you do not need to invoke the script | ||
| manually before each push. | ||
|
|
||
| > **For AI agents**: before invoking the script manually, check whether the hook is installed: | ||
| > | ||
| > ```bash | ||
| > [[ -x "$(git rev-parse --git-path hooks)/pre-push" ]] && echo "installed" || echo "not installed" | ||
| > ``` | ||
| > | ||
| > If installed, skip the manual run — `git push` will trigger it automatically. | ||
| > Running both would execute every check twice. | ||
|
|
||
| ## Automated Checks | ||
|
|
||
| > **⏱️ Expected runtime: ~15 minutes** on a modern developer machine with warm caches. | ||
| > AI agents should set a command timeout of **at least 30 minutes** before invoking | ||
| > `./contrib/dev-tools/git/hooks/pre-push.sh`. | ||
|
|
||
| Run the pre-push script. **It must exit with code `0` before every push.** | ||
|
|
||
| ```bash | ||
| ./contrib/dev-tools/git/hooks/pre-push.sh | ||
| ``` | ||
|
|
||
| The script runs these steps in order: | ||
|
|
||
| 1. `cargo +stable machete` - unused dependency check | ||
| 2. `linter all` - all linters (markdown, YAML, TOML, clippy, rustfmt, shellcheck, cspell) | ||
| 3. `cargo +nightly fmt --check` - nightly format check | ||
| 4. `cargo +nightly check ...` - nightly workspace check | ||
| 5. `cargo +nightly doc ...` - nightly documentation build | ||
| 6. `cargo +stable test --doc --workspace` - documentation tests | ||
| 7. `cargo +stable test --tests --benches --examples --workspace --all-targets --all-features` - all tests | ||
| 8. `cargo +stable run --bin e2e_tests_runner ...` - end-to-end tests | ||
|
|
||
| ## Output Modes | ||
|
|
||
| The pre-push script supports concise human output, verbose human output, and JSON output for | ||
| automation. | ||
|
|
||
| ```bash | ||
| # Default: text + concise | ||
| ./contrib/dev-tools/git/hooks/pre-push.sh | ||
|
|
||
| # Explicit text + concise | ||
| ./contrib/dev-tools/git/hooks/pre-push.sh --format=text --verbosity=concise | ||
|
|
||
| # Text + verbose streaming command output | ||
| ./contrib/dev-tools/git/hooks/pre-push.sh --format=text --verbosity=verbose | ||
|
|
||
| # Compatibility alias | ||
| ./contrib/dev-tools/git/hooks/pre-push.sh --format=text --verbose | ||
|
|
||
| # Structured output (single JSON document to stdout) | ||
| ./contrib/dev-tools/git/hooks/pre-push.sh --format=json | ||
| ``` | ||
|
|
||
| Flag behavior: | ||
|
|
||
| - `--format=<text|json>` defaults to `text` | ||
| - `--verbosity=<concise|verbose>` defaults to `concise` | ||
| - `--verbose` is an alias for `--verbosity=verbose` | ||
| - Duplicate `--format`/`--verbosity` flags: last value wins | ||
| - Invalid values or unknown flags exit with code `2` and print usage guidance to stderr | ||
| - In `--format=json`, structured output remains JSON regardless of verbosity value | ||
| - Per-step logs are written to `TORRUST_GIT_HOOKS_LOG_DIR` (default: `/tmp`) | ||
|
|
||
| For restricted agent environments that cannot write outside the workspace, run with: | ||
|
|
||
| ```bash | ||
| TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-push.sh | ||
| ``` | ||
|
|
||
| The `.tmp/` directory is git-ignored. | ||
| Because `.tmp/` is workspace-local, clean stale `pre-push-*.log` files periodically. | ||
|
|
||
| ## Check Tier Ownership | ||
|
|
||
| Check ownership is intentionally split by gate: | ||
|
|
||
| - Pre-commit: fast local gate (`cargo machete`, `linter all`, `cargo test --doc --workspace`) | ||
| - Pre-push: comprehensive developer gate (nightly format/check/doc + stable tests + E2E) | ||
| - CI: merge authority with full validation and E2E matrix jobs | ||
|
|
||
| E2E is intentionally excluded from pre-commit and remains a pre-push/CI responsibility. | ||
|
|
||
| ## Troubleshooting Output Modes | ||
|
|
||
| - Concise mode shows high-signal per-step summaries only. On failure, it prints the log path and | ||
| a short failure tail. | ||
| - Verbose mode streams full command output to the terminal. Use this for deep local debugging. | ||
| - JSON mode emits one structured document to stdout; diagnostics and usage errors go to stderr. | ||
| - If concise output is too short for debugging, re-run the same command with | ||
| `--format=text --verbosity=verbose`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.