Skip to content

feat(pre-push): add format/verbosity/log-dir parity with pre-commit (#1780)#1783

Merged
josecelano merged 9 commits into
torrust:developfrom
josecelano:1780-refactor-pre-push-checks-performance-and-verbosity
May 14, 2026
Merged

feat(pre-push): add format/verbosity/log-dir parity with pre-commit (#1780)#1783
josecelano merged 9 commits into
torrust:developfrom
josecelano:1780-refactor-pre-push-checks-performance-and-verbosity

Conversation

@josecelano
Copy link
Copy Markdown
Member

@josecelano josecelano commented May 13, 2026

Closes #1780

Summary

Refactors contrib/dev-tools/git/hooks/pre-push.sh to align its operator experience with the pre-commit hook introduced in #1769:

  • --format=<text|json> with text as default
  • --verbosity=<concise|verbose> with concise as default (--verbose alias)
  • Concise per-step summaries; failures include log path and short tail
  • JSON output mode emits one structured payload to stdout
  • TORRUST_GIT_HOOKS_LOG_DIR env var for configurable log directory (default /tmp)
  • Fail-fast: stops on first failure

Also:

  • Updates pre-commit.sh to use TORRUST_GIT_HOOKS_LOG_DIR (replacing the old script-specific PRE_COMMIT_LOG_DIR var) so all hooks share the same env var
  • Adds .githooks/pre-push dispatcher (TTY detection: --format=text for interactive terminals, --format=json for non-interactive/agent runs)
  • Updates .githooks/pre-commit dispatcher to use the same TTY detection
  • Creates .github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md
  • Updates run-pre-commit-checks skill to document TORRUST_GIT_HOOKS_LOG_DIR
  • Updates AGENTS.md with env var and new skill reference
  • Updates Committer agent and both skills to check for installed git hook before running scripts manually (avoids duplicate execution when the hook is already installed)

Manual Verification Test Matrix

Tested with a fast-step stub (2–3 no-op steps), TORRUST_GIT_HOOKS_LOG_DIR=.tmp.

Test case Expected Result
--help / -h exit 0, usage text on stderr PASS
--format=bad exit 2, error + usage on stderr PASS
--verbosity=bad exit 2, error + usage on stderr PASS
--unknown exit 2, error + usage on stderr PASS
text concise pass path [Step N/M] … PASS (Xs) per step + SUCCESS footer, exit 0 PASS
text verbose pass path step header + streaming stdout + PASS summary + blank line, exit 0 PASS
--format=json pass path valid JSON, status: pass, exit_code: 0, all steps in array PASS
text concise fail path FAIL line + log path + tail lines; subsequent steps skipped; exit 1 PASS
--format=json fail path valid JSON, status: fail, exit_code: 1, failed_step, failure_tail PASS
--format=json --verbose JSON only — verbosity silently ignored PASS
TORRUST_GIT_HOOKS_LOG_DIR in pre-push log files created in .tmp/pre-push-*.log PASS
TORRUST_GIT_HOOKS_LOG_DIR in pre-commit logs in .tmp/pre-commit-*.log, JSON output valid PASS

Files Changed

File Change
contrib/dev-tools/git/hooks/pre-push.sh Full rewrite with format/verbosity/log-dir support
contrib/dev-tools/git/hooks/pre-commit.sh Replace PRE_COMMIT_LOG_DIR with TORRUST_GIT_HOOKS_LOG_DIR
.githooks/pre-push New dispatcher (TTY detection)
.githooks/pre-commit Updated with TTY detection
.github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md New skill
.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md Updated with TORRUST_GIT_HOOKS_LOG_DIR and agent duplicate-run guidance
.github/agents/committer.agent.md Hook-install check before manual pre-commit invocation
AGENTS.md Env var and new skill reference

- Add Design Decisions section (5 agreed decisions: TORRUST_GIT_HOOKS_LOG_DIR
  shared env var, new run-pre-push-checks skill, JSON-only in --format=json,
  fail-fast behavior, PRE_COMMIT_LOG_DIR backward compat for pre-commit)
- Expand scope section with precise env var name and list of artifacts to update
- Refine implementation plan from T1-T5 to T1-T8; mark T1 as DONE
- Add AC7 (JSON-only in json mode) and AC8 (fail-fast) to acceptance criteria
- Update progress log with planning entry (2026-05-13 19:00 UTC)
- Update frontmatter: last-updated-utc, add run-pre-push-checks to related-artifacts
- Add "parseable" to project-words.txt (used in Design Decisions table)
Add `.githooks/pre-push` that delegates to
`contrib/dev-tools/git/hooks/pre-push.sh`, mirroring the existing
`.githooks/pre-commit` pattern.

Run `./contrib/dev-tools/git/install-git-hooks.sh` to register it.

Also update issue spec torrust#1780:
- T7 evidence expanded to cover all verified output modes
- T9 added: add .githooks/pre-push dispatcher
- AC4 and AC6 evidence updated with manual verification notes
- Progress log updated
Pass `--format=text --verbosity=concise` explicitly in both
`.githooks/pre-commit` and `.githooks/pre-push` so the output mode is
declared rather than relying on implicit script defaults.

Also update issue spec torrust#1780:
- T10 added: explicit output mode in .githooks/ dispatchers
- Manual verification test matrix added to Acceptance Verification section
- Progress log updated
…atchers

Change both `.githooks/pre-commit` and `.githooks/pre-push` to pass
`--format=json` so hook output is machine-readable by default. The
underlying scripts still default to `--format=text` when invoked
directly from the command line.

Update issue spec torrust#1780: T10 note and progress log updated.
Update the Committer agent and run-pre-commit/run-pre-push-checks skills
to check whether the corresponding git hook is installed before invoking
the pre-commit.sh / pre-push.sh script manually.

When the hook is installed, git fires it automatically on commit/push,
so a prior manual run would execute every check twice. Agents now use:

  [[ -x "$(git rev-parse --git-path hooks)/pre-commit" ]]

to detect the installed hook and skip the redundant manual invocation.
Copilot AI review requested due to automatic review settings May 13, 2026 19:04
@josecelano josecelano requested a review from a team as a code owner May 13, 2026 19:04
@josecelano josecelano self-assigned this May 13, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the pre-push git-hook script to match the newer pre-commit hook’s operator contract (text vs JSON output, concise vs verbose modes, per-step log capture, and clearer failure summaries), and updates docs/skills/dispatchers to reflect the unified workflow (including a shared log-dir env var).

Changes:

  • Rewrites contrib/dev-tools/git/hooks/pre-push.sh to support --format=<text|json>, --verbosity=<concise|verbose>, fail-fast execution, and per-step log files under TORRUST_GIT_HOOKS_LOG_DIR.
  • Updates pre-commit.sh to fall back to TORRUST_GIT_HOOKS_LOG_DIR after PRE_COMMIT_LOG_DIR, and updates workflow docs/skills/agents accordingly.
  • Adds/updates .githooks/* dispatchers and introduces a new “run-pre-push-checks” skill doc.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
contrib/dev-tools/git/hooks/pre-push.sh Full rewrite adding format/verbosity support, fail-fast behavior, JSON emission, and shared log-dir usage.
contrib/dev-tools/git/hooks/pre-commit.sh Adds TORRUST_GIT_HOOKS_LOG_DIR fallback and updates help text.
.githooks/pre-push New pre-push dispatcher invoking the rewritten script.
.githooks/pre-commit Dispatcher updated to explicitly request JSON output.
.github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md New skill documenting pre-push hook usage and output modes.
.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md Skill updated to document shared log-dir fallback and hook-installed guard.
.github/agents/committer.agent.md Adds guidance to avoid double-running checks when hooks are installed.
AGENTS.md Documents shared log-dir env var and references the new skill.
docs/issues/open/1780-refactor-pre-push-checks-performance-and-verbosity.md Spec updated with design decisions, progress, and verification matrix.
project-words.txt Adds/relocates terms to keep cspell wordlist consistent and sorted.
Comments suppressed due to low confidence (1)

AGENTS.md:162

  • The docs recommend cleaning up pre-commit-*.log / pre-push-*.log, but the hook scripts currently create log files without a .log suffix (via mktemp ...-XXXXXX). Update the cleanup glob here (or change the scripts to emit .log files) so the guidance matches the actual filenames.
When using `.tmp`, periodically clean old logs (for example, remove stale `pre-commit-*.log` and
`pre-push-*.log` files) because OS-managed `/tmp` cleanup does not apply.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contrib/dev-tools/git/hooks/pre-push.sh
Comment thread contrib/dev-tools/git/hooks/pre-push.sh Outdated
Comment thread contrib/dev-tools/git/hooks/pre-commit.sh Outdated
Comment thread AGENTS.md Outdated
Comment thread .github/skills/dev/git-workflow/run-pre-push-checks/SKILL.md
Comment thread .githooks/pre-push Outdated
Comment thread .githooks/pre-commit Outdated
Comment thread .github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.24%. Comparing base (19131d7) to head (a916d0b).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1783   +/-   ##
========================================
  Coverage    78.24%   78.24%           
========================================
  Files          376      376           
  Lines        28369    28369           
  Branches     28369    28369           
========================================
  Hits         22198    22198           
  Misses        5859     5859           
  Partials       312      312           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add .log suffix to mktemp in pre-push.sh and pre-commit.sh so log
  files match the *.log cleanup globs documented in skills/AGENTS.md
- Propagate actual exit code from run_step (exit 2 for infra errors,
  exit 1 for check failures) instead of hardcoding 1
- Replace PRE_COMMIT_LOG_DIR with TORRUST_GIT_HOOKS_LOG_DIR in
  pre-commit.sh — single env var for all hooks, default /tmp
- Use TTY detection in .githooks/ dispatchers: --format=text for
  interactive terminals, --format=json for non-interactive/agent runs
- Update usage text, AGENTS.md, skill docs, and issue spec accordingly
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Comment thread contrib/dev-tools/git/hooks/pre-push.sh Outdated
Comment thread contrib/dev-tools/git/hooks/pre-commit.sh
Comment thread contrib/dev-tools/git/hooks/pre-push.sh
Comment thread docs/issues/open/1780-refactor-pre-push-checks-performance-and-verbosity.md Outdated
Comment thread contrib/dev-tools/git/hooks/pre-commit.sh
- Fix mktemp portability: create temp file with XXXXXX at end, then
  mv to add .log suffix (XXXXXX must be last token on BSD/macOS mktemp)
- Normalize exit_code to 1 for check failures; keep 2 for
  infrastructure/script errors so consumers see a stable contract
- Update issue spec T10 note to reflect TTY detection in dispatchers
  rather than hardcoded --format=json
@josecelano
Copy link
Copy Markdown
Member Author

ACK a916d0b

@josecelano josecelano merged commit 42ea432 into torrust:develop May 14, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor pre-push checks for output-mode parity and clearer failure feedback

2 participants