File tree Expand file tree Collapse file tree 2 files changed +69
-0
lines changed
Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Mechanics naming guard
2+
3+ on :
4+ pull_request :
5+ paths :
6+ - " doc/06_mechanics/**/*.md"
7+ push :
8+ branches : [main]
9+
10+ jobs :
11+ mechanics-naming :
12+ runs-on : ubuntu-latest
13+
14+ steps :
15+ - name : Checkout
16+ uses : actions/checkout@v4
17+ with :
18+ fetch-depth : 0
19+
20+ - name : Run mechanics naming check
21+ run : |
22+ chmod +x tooling/git-hooks/pre-commit
23+ FILES_CMD="git diff origin/main...HEAD --name-only" \
24+ tooling/git-hooks/pre-commit
25+
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ echo " Linting Protopipe mechanics naming…"
5+
6+ APPROVED_REGEX=' ^doc/06_mechanics/approved/M-[0-9]{3}_[a-z0-9-]+_(over|by-default|without)_[a-z0-9-]+\.md$'
7+ CANDIDATE_REGEX=' ^doc/06_mechanics/candidates/[a-z0-9-]+_(over|by-default|without)_[a-z0-9-]+\.md$'
8+
9+ FILES_CMD=${FILES_CMD:- " git diff --cached --name-only" }
10+
11+ FAILED=0
12+
13+ for file in $( eval " $FILES_CMD " ) ; do
14+
15+ if [[ " $( basename " $file " ) " == " README.md" ]]; then
16+ continue
17+ fi
18+
19+ if [[ " $( basename " $file " ) " =~ [a-z]+-template\. md ]]; then
20+ continue
21+ fi
22+
23+ if [[ " $file " == doc/06_mechanics/approved/* .md ]]; then
24+ if ! [[ " $file " =~ $APPROVED_REGEX ]]; then
25+ echo " Invalid approved mechanic filename: $file "
26+ FAILED=1
27+ fi
28+ fi
29+
30+ if [[ " $file " == doc/06_mechanics/candidates/* .md ]]; then
31+ if ! [[ " $file " =~ $CANDIDATE_REGEX ]]; then
32+ echo " Invalid candidate mechanic filename: $file "
33+ FAILED=1
34+ fi
35+ fi
36+ done
37+
38+ if [[ " $FAILED " -eq 1 ]]; then
39+ echo " Commit rejected: mechanic filename violations"
40+ exit 1
41+ fi
42+
43+ echo " Mechanics naming OK"
44+
You can’t perform that action at this time.
0 commit comments