Skip to content

Commit 3a5b39b

Browse files
Merge pull request #18 from saltines321-debug/issue-14-generic-hygiene-checks
Add generic repository hygiene checks
2 parents b3f4c12 + bc36ee3 commit 3a5b39b

4 files changed

Lines changed: 101 additions & 0 deletions

File tree

.github/workflows/reusable-quality.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
required: false
99
default: 0
1010
type: number
11+
run-hygiene-check:
12+
description: Run generic repository hygiene checks.
13+
required: false
14+
default: true
15+
type: boolean
1116
setup-node:
1217
description: Enable Node.js setup.
1318
required: false
@@ -60,6 +65,11 @@ jobs:
6065
with:
6166
fetch-depth: ${{ inputs.checkout-fetch-depth }}
6267

68+
- name: Repository hygiene
69+
if: ${{ inputs.run-hygiene-check }}
70+
shell: bash
71+
run: bash scripts/hygiene.sh
72+
6373
- name: Set up Node.js
6474
if: ${{ inputs.setup-node }}
6575
uses: actions/setup-node@v4

docs/DEVEX.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ Template repositories should support these task names when applicable:
4444
- `lint` for static analysis
4545
- `test` for automated tests
4646

47+
Generic validation is always available through:
48+
49+
```bash
50+
bash scripts/hygiene.sh
51+
```
52+
53+
The hygiene check is stack-agnostic and currently verifies:
54+
55+
- required template files are present
56+
- shell scripts parse successfully
57+
- unresolved merge markers are not present
58+
- Markdown files start with a top-level heading
59+
60+
`bash scripts/validate.sh` runs the generic hygiene checks first, then runs project-specific package commands when a supported project setup is present.
61+
4762
The reusable GitHub Actions workflow can call custom commands for each project. Local validation should stay simple and safe to run repeatedly.
4863

4964
## Debugging workflow

scripts/hygiene.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
failures=0
5+
6+
report_failure() {
7+
echo "hygiene: $1" >&2
8+
failures=$((failures + 1))
9+
}
10+
11+
check_required_files() {
12+
local required_files=(
13+
README.md
14+
LICENSE
15+
CONTRIBUTING.md
16+
SECURITY.md
17+
CODE_OF_CONDUCT.md
18+
CHANGELOG.md
19+
.editorconfig
20+
.gitattributes
21+
.gitignore
22+
docs/ARCHITECTURE.md
23+
docs/DEVEX.md
24+
docs/REPOSITORY_STANDARDS.md
25+
config/.env.example
26+
)
27+
28+
for file in "${required_files[@]}"; do
29+
if [[ ! -f "$file" ]]; then
30+
report_failure "missing required file: $file"
31+
fi
32+
done
33+
}
34+
35+
check_shell_syntax() {
36+
local script
37+
while IFS= read -r -d '' script; do
38+
bash -n "$script" || report_failure "shell syntax failed: $script"
39+
done < <(find . -type f -name '*.sh' -not -path './.git/*' -print0)
40+
}
41+
42+
check_merge_markers() {
43+
local left middle right
44+
left="$(printf '<%.0s' {1..7})"
45+
middle="$(printf '=%.0s' {1..7})"
46+
right="$(printf '>%.0s' {1..7})"
47+
48+
if git grep -n -e "$left" -e "$middle" -e "$right" -- . ':!.git' >/tmp/hygiene-markers.txt; then
49+
cat /tmp/hygiene-markers.txt >&2
50+
report_failure "possible unresolved merge markers found"
51+
fi
52+
}
53+
54+
check_markdown_headings() {
55+
local file first_line
56+
while IFS= read -r -d '' file; do
57+
first_line="$(head -n 1 "$file")"
58+
if [[ "$first_line" != '#'* && "$first_line" != '---' ]]; then
59+
report_failure "markdown file should start with a heading or front matter: $file"
60+
fi
61+
done < <(find . -type f -name '*.md' -not -path './.git/*' -print0)
62+
}
63+
64+
check_required_files
65+
check_shell_syntax
66+
check_merge_markers
67+
check_markdown_headings
68+
69+
if [[ "$failures" -gt 0 ]]; then
70+
echo "Repository hygiene checks failed: $failures issue(s)." >&2
71+
exit 1
72+
fi
73+
74+
echo "Repository hygiene checks passed."

scripts/validate.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
bash scripts/hygiene.sh
5+
46
if [[ -f package.json ]]; then
57
if command -v npm >/dev/null 2>&1; then
68
npm run format:check --if-present

0 commit comments

Comments
 (0)