Skip to content

Commit d51ef29

Browse files
committed
Merge #1704: refactor(dev-tools): consolidate git hook scripts under contrib/dev-tools/git
b3d1e6b fix(dev-tools): address Copilot review suggestions on PR #1704 (Jose Celano) 8efa87f refactor(dev-tools): consolidate git hook scripts under contrib/dev-tools/git (Jose Celano) Pull request description: ## Summary Consolidates the duplicate/misplaced scripts from `scripts/` into their canonical location under `contrib/dev-tools/git/`. ## Changes ### Files moved / deleted - `scripts/install-git-hooks.sh` → `contrib/dev-tools/git/install-git-hooks.sh` - `scripts/pre-commit.sh` → **deleted** (duplicate; canonical version now lives in hooks dir) ### Scripts rewritten in new structured style Both hook scripts now use a `STEPS` array with per-step timing and clear `PASSED`/`FAILED` output, matching the style of the new `pre-commit.sh`. **`contrib/dev-tools/git/hooks/pre-commit.sh`** (fast, ~3 min): 1. `cargo machete` — unused dependency check 2. `linter all` — all linters 3. `cargo test --doc --workspace` — documentation tests 4. `cargo test --tests --benches --examples --workspace --all-targets --all-features` — all tests Nightly toolchain checks and e2e tests are **intentionally excluded** — they are too slow for pre-commit and are covered by CI and `pre-push`. **`contrib/dev-tools/git/hooks/pre-push.sh`** (comprehensive, ~15 min): 1. `cargo machete` 2. `linter all` 3. `cargo +nightly fmt --check` 4. `cargo +nightly check …` 5. `cargo +nightly doc …` 6. `cargo test --doc --workspace` 7. `cargo test … --all-targets --all-features` 8. E2E tests (`e2e_tests_runner`) ### References updated All references to the old `scripts/` paths have been updated across: - `.githooks/pre-commit` - `AGENTS.md` - `.github/workflows/copilot-setup-steps.yml` - `.github/agents/committer.agent.md` - `.github/agents/implementer.agent.md` - `.github/skills/dev/git-workflow/commit-changes/SKILL.md` - `.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md` - `.github/skills/dev/maintenance/setup-dev-environment/SKILL.md` - `.github/skills/dev/maintenance/update-dependencies/SKILL.md` - `docs/issues/1697-ai-agent-configuration.md` ACKs for top commit: josecelano: ACK b3d1e6b Tree-SHA512: 22c7b43908f2359143254e6fea9af1222d7b3717f3a6b58962f9d2a2939b9a5c379ee07e7ec5da4a9822815217592c731048ee08e92e0b0d0dec204735f90db6
2 parents 4b8a21f + b3d1e6b commit d51ef29

14 files changed

Lines changed: 199 additions & 132 deletions

File tree

.githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -euo pipefail
44

55
repo_root="$(git rev-parse --show-toplevel)"
66

7-
"$repo_root/scripts/pre-commit.sh"
7+
"$repo_root/contrib/dev-tools/git/hooks/pre-commit.sh"

.github/agents/committer.agent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Treat every commit request as a review-and-verify workflow, not as a blind reque
1717

1818
- Follow `AGENTS.md` for repository-wide behaviour and
1919
`.github/skills/dev/git-workflow/commit-changes/SKILL.md` for commit-specific reference details.
20-
- The pre-commit validation command is `./scripts/pre-commit.sh`.
20+
- The pre-commit validation command is `./contrib/dev-tools/git/hooks/pre-commit.sh`.
2121
- Create GPG-signed Conventional Commits (`git commit -S`).
2222

2323
## Required Workflow
2424

2525
1. Read the current branch, `git status`, and the staged or unstaged diff relevant to the request.
2626
2. Summarize the intended commit scope before taking action.
2727
3. Ensure the commit scope is coherent and does not accidentally mix unrelated changes.
28-
4. Run `./scripts/pre-commit.sh` when feasible and fix issues that are directly related to the
28+
4. Run `./contrib/dev-tools/git/hooks/pre-commit.sh` when feasible and fix issues that are directly related to the
2929
requested commit scope.
3030
5. Propose a precise Conventional Commit message.
3131
6. Create the commit with `git commit -S` only after the scope is clear and blockers are resolved.

.github/agents/implementer.agent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Reference: [Beck Design Rules](https://martinfowler.com/bliki/BeckDesignRules.ht
2727
## Repository Rules
2828

2929
- Follow `AGENTS.md` for repository-wide conventions.
30-
- The pre-commit validation command is `./scripts/pre-commit.sh`.
30+
- The pre-commit validation command is `./contrib/dev-tools/git/hooks/pre-commit.sh`.
3131
- Relevant skills to load when needed:
3232
- `.github/skills/dev/testing/write-unit-test/SKILL.md` — test naming and Arrange/Act/Assert pattern.
3333
- `.github/skills/dev/rust-code-quality/handle-errors-in-code/SKILL.md` — error handling.
@@ -82,5 +82,5 @@ description of what was implemented. Do not commit directly — always delegate
8282
- Do not implement more than was asked — scope creep is a defect.
8383
- Do not suppress compiler warnings or clippy lints without a documented reason.
8484
- Do not add dependencies without running `cargo machete` afterward.
85-
- Do not commit code that fails `./scripts/pre-commit.sh`.
85+
- Do not commit code that fails `./contrib/dev-tools/git/hooks/pre-commit.sh`.
8686
- Do not skip the audit step, even for small changes.

.github/skills/dev/git-workflow/commit-changes/SKILL.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ This skill guides you through the complete commit process for the Torrust Tracke
1414

1515
```bash
1616
# One-time setup: install the pre-commit Git hook
17-
./scripts/install-git-hooks.sh
17+
./contrib/dev-tools/git/install-git-hooks.sh
1818

1919
# Stage changes
2020
git add <files>
2121

2222
# Commit with conventional format and GPG signature (MANDATORY)
23-
# The pre-commit hook runs ./scripts/pre-commit.sh automatically
23+
# The pre-commit hook runs ./contrib/dev-tools/git/hooks/pre-commit.sh automatically
2424
git commit -S -m "<type>[(<scope>)]: <description>"
2525
```
2626

@@ -66,11 +66,11 @@ git commit -S -m "your commit message"
6666

6767
### Git Hook
6868

69-
The repository ships a `pre-commit` Git hook that runs `./scripts/pre-commit.sh`
69+
The repository ships a `pre-commit` Git hook that runs `./contrib/dev-tools/git/hooks/pre-commit.sh`
7070
automatically on every `git commit`. Install it once after cloning:
7171

7272
```bash
73-
./scripts/install-git-hooks.sh
73+
./contrib/dev-tools/git/install-git-hooks.sh
7474
```
7575

7676
Once installed, the hook fires on every commit and you do not need to run the script manually.
@@ -84,7 +84,7 @@ If the hook is not installed, run the script explicitly before committing.
8484
> command timeout of **at least 5 minutes** before invoking this script.
8585
8686
```bash
87-
./scripts/pre-commit.sh
87+
./contrib/dev-tools/git/hooks/pre-commit.sh
8888
```
8989

9090
The script runs:

.github/skills/dev/git-workflow/run-pre-commit-checks/SKILL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ metadata:
1010

1111
## Git Hook (Recommended Setup)
1212

13-
The repository ships a `pre-commit` Git hook that runs `./scripts/pre-commit.sh`
13+
The repository ships a `pre-commit` Git hook that runs `./contrib/dev-tools/git/hooks/pre-commit.sh`
1414
automatically on every `git commit`. Install it once after cloning:
1515

1616
```bash
17-
./scripts/install-git-hooks.sh
17+
./contrib/dev-tools/git/install-git-hooks.sh
1818
```
1919

2020
After installation the hook fires automatically; you do not need to invoke the script
@@ -23,14 +23,14 @@ manually before each commit.
2323
## Automated Checks
2424

2525
> **⏱️ Expected runtime: ~3 minutes** on a modern developer machine. AI agents must set a
26-
> command timeout of **at least 5 minutes** before invoking `./scripts/pre-commit.sh`. Agents
26+
> command timeout of **at least 5 minutes** before invoking `./contrib/dev-tools/git/hooks/pre-commit.sh`. Agents
2727
> with a default per-command timeout below 5 minutes will likely time out and report a false
2828
> failure.
2929
3030
Run the pre-commit script. **It must exit with code `0` before every commit.**
3131

3232
```bash
33-
./scripts/pre-commit.sh
33+
./contrib/dev-tools/git/hooks/pre-commit.sh
3434
```
3535

3636
The script runs these steps in order:

.github/skills/dev/maintenance/setup-dev-environment/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ cargo install cargo-machete # Unused dependency checker
7272
Install the project pre-commit hook (one-time, re-run after hook changes):
7373

7474
```bash
75-
./scripts/install-git-hooks.sh
75+
./contrib/dev-tools/git/install-git-hooks.sh
7676
```
7777

78-
The hook runs `./scripts/pre-commit.sh` automatically on every `git commit`.
78+
The hook runs `./contrib/dev-tools/git/hooks/pre-commit.sh` automatically on every `git commit`.
7979

8080
## Step 8: Smoke Test
8181

.github/skills/dev/maintenance/update-dependencies/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cargo update 2>&1 | tee /tmp/cargo-update.txt
3737
# If Cargo.lock has no changes, nothing to do — stop here.
3838

3939
# Verify
40-
./scripts/pre-commit.sh
40+
./contrib/dev-tools/git/hooks/pre-commit.sh
4141

4242
# Commit and push
4343
git add Cargo.lock
@@ -92,7 +92,7 @@ cargo update --precise {old-version} {crate-name}
9292

9393
```bash
9494
cargo machete
95-
./scripts/pre-commit.sh
95+
./contrib/dev-tools/git/hooks/pre-commit.sh
9696
```
9797

9898
Fix any failures before proceeding.

.github/workflows/copilot-setup-steps.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ on:
77
push:
88
paths:
99
- .github/workflows/copilot-setup-steps.yml
10-
- scripts/install-git-hooks.sh
11-
- scripts/pre-commit.sh
10+
- contrib/dev-tools/git/install-git-hooks.sh
11+
- contrib/dev-tools/git/hooks/pre-commit.sh
1212
pull_request:
1313
paths:
1414
- .github/workflows/copilot-setup-steps.yml
15-
- scripts/install-git-hooks.sh
16-
- scripts/pre-commit.sh
15+
- contrib/dev-tools/git/install-git-hooks.sh
16+
- contrib/dev-tools/git/hooks/pre-commit.sh
1717

1818
jobs:
1919
# The job MUST be called `copilot-setup-steps` or it will not be picked up
@@ -47,7 +47,7 @@ jobs:
4747
run: cargo install cargo-machete
4848

4949
- name: Install Git pre-commit hooks
50-
run: ./scripts/install-git-hooks.sh
50+
run: ./contrib/dev-tools/git/install-git-hooks.sh
5151

5252
- name: Smoke-check — run all linters
5353
run: linter all

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ native IPv4/IPv6 support, private/whitelisted mode, and a management REST API.
3838
- `packages/` — Cargo workspace packages (all domain logic lives here; see package catalog below)
3939
- `console/` — Console tools (e.g., `tracker-client`)
4040
- `contrib/` — Community-contributed utilities (`bencode`) and developer tooling
41-
- `contrib/dev-tools/` — Developer tools: git hooks (`pre-commit.sh`, `pre-push.sh`),
41+
- `contrib/dev-tools/` — Developer tools: git hooks (`pre-commit.sh`, `pre-push.sh`, `install-git-hooks.sh`),
4242
container scripts, and init scripts
4343
- `tests/` — Integration tests (`integration.rs`, `servers/`)
4444
- `docs/` — Project documentation, ADRs, issue specs, and benchmarking guides
@@ -127,7 +127,7 @@ All packages live under `packages/`. The workspace version is `3.0.0-develop`.
127127
```sh
128128
rustup show # Check active toolchain
129129
rustup update # Update toolchain
130-
rustup toolchain install nightly # Optional: only needed for manual cargo +nightly doc; the repo hook runs ./scripts/pre-commit.sh
130+
rustup toolchain install nightly # Optional: needed for manual cargo +nightly commands and the repo pre-push checks (fmt/check/doc)
131131
```
132132

133133
### Build
Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,83 @@
1-
#!/bin/bash
2-
3-
cargo +nightly fmt --check &&
4-
cargo +nightly check --tests --benches --examples --workspace --all-targets --all-features &&
5-
cargo +nightly doc --no-deps --bins --examples --workspace --all-features &&
6-
cargo +nightly machete &&
7-
cargo +stable build &&
8-
CARGO_INCREMENTAL=0 cargo +stable clippy --no-deps --tests --benches --examples --workspace --all-targets --all-features -- -D clippy::correctness -D clippy::suspicious -D clippy::complexity -D clippy::perf -D clippy::style -D clippy::pedantic &&
9-
cargo +stable test --doc --workspace &&
10-
cargo +stable test --tests --benches --examples --workspace --all-targets --all-features
1+
#!/usr/bin/env bash
2+
# Pre-commit verification script
3+
# Run all mandatory checks before committing changes.
4+
#
5+
# Usage:
6+
# ./contrib/dev-tools/git/hooks/pre-commit.sh
7+
#
8+
# Expected runtime: ~3 minutes on a modern developer machine.
9+
# AI agents: set a per-command timeout of at least 5 minutes before invoking this script.
10+
#
11+
# All steps must pass (exit 0) before committing.
12+
13+
set -euo pipefail
14+
15+
# ============================================================================
16+
# STEPS
17+
# ============================================================================
18+
# Each step: "description|success_message|command"
19+
20+
declare -a STEPS=(
21+
"Checking for unused dependencies (cargo machete)|No unused dependencies found|cargo machete"
22+
"Running all linters|All linters passed|linter all"
23+
"Running documentation tests|Documentation tests passed|cargo test --doc --workspace"
24+
"Running all tests|All tests passed|cargo test --tests --benches --examples --workspace --all-targets --all-features"
25+
)
26+
27+
# ============================================================================
28+
# HELPER FUNCTIONS
29+
# ============================================================================
30+
31+
format_time() {
32+
local total_seconds=$1
33+
local minutes=$((total_seconds / 60))
34+
local seconds=$((total_seconds % 60))
35+
if [ "$minutes" -gt 0 ]; then
36+
echo "${minutes}m ${seconds}s"
37+
else
38+
echo "${seconds}s"
39+
fi
40+
}
41+
42+
run_step() {
43+
local step_number=$1
44+
local total_steps=$2
45+
local description=$3
46+
local success_message=$4
47+
local command=$5
48+
49+
echo "[Step ${step_number}/${total_steps}] ${description}..."
50+
51+
local step_start=$SECONDS
52+
local -a cmd_array
53+
read -ra cmd_array <<< "${command}"
54+
"${cmd_array[@]}"
55+
local step_elapsed=$((SECONDS - step_start))
56+
57+
echo "PASSED: ${success_message} ($(format_time "${step_elapsed}"))"
58+
echo
59+
}
60+
61+
trap 'echo ""; echo "=========================================="; echo "FAILED: Pre-commit checks failed!"; echo "Fix the errors above before committing."; echo "=========================================="; exit 1' ERR
62+
63+
# ============================================================================
64+
# MAIN
65+
# ============================================================================
66+
67+
TOTAL_START=$SECONDS
68+
TOTAL_STEPS=${#STEPS[@]}
69+
70+
echo "Running pre-commit checks..."
71+
echo
72+
73+
for i in "${!STEPS[@]}"; do
74+
IFS='|' read -r description success_message command <<< "${STEPS[$i]}"
75+
run_step $((i + 1)) "${TOTAL_STEPS}" "${description}" "${success_message}" "${command}"
76+
done
77+
78+
TOTAL_ELAPSED=$((SECONDS - TOTAL_START))
79+
echo "=========================================="
80+
echo "SUCCESS: All pre-commit checks passed! ($(format_time "${TOTAL_ELAPSED}"))"
81+
echo "=========================================="
82+
echo
83+
echo "You can now safely stage and commit your changes."

0 commit comments

Comments
 (0)