Skip to content

Commit d0ea2e1

Browse files
committed
make pre-commit and GA smarter
1 parent 08af75a commit d0ea2e1

3 files changed

Lines changed: 53 additions & 11 deletions

File tree

.githooks/pre-commit

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,50 @@ exec 1>&2
88

99
echo "Running Pre-Commit Hooks..."
1010

11-
# Get staged nix files
11+
# Get staged files
1212
STAGED_NIX_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.nix$' || true)
13+
STAGED_MD_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.md$' || true)
14+
LOCK_CHANGED=$(git diff --cached --name-only --diff-filter=ACM | grep 'flake\.lock$' || true)
1315

16+
# --- NIX CHECKS ---
1417
if [ -n "$STAGED_NIX_FILES" ]; then
15-
echo "Formatting..."
18+
echo "Processing Nix files..."
19+
echo " -> Formatting..."
1620
nix run nixpkgs#alejandra -- -q $STAGED_NIX_FILES
1721

18-
echo "Checking for dead code..."
22+
echo " -> Checking for dead code..."
1923
nix run nixpkgs#deadnix -- -e $STAGED_NIX_FILES
2024

21-
echo "Running statix..."
22-
# Statix requires single files
25+
echo " -> Running statix..."
2326
for file in $STAGED_NIX_FILES; do
24-
echo " -> $file"
27+
echo " - $file"
2528
nix run nixpkgs#statix -- fix "$file"
2629
done
2730

2831
# Re-stage formatted files
2932
git add $STAGED_NIX_FILES
3033
fi
3134

32-
echo "Running nix flake check..."
33-
nix flake check
35+
if [ -n "$STAGED_NIX_FILES" ] || [ -n "$LOCK_CHANGED" ]; then
36+
echo "Running nix flake check..."
37+
nix flake check
38+
fi
39+
40+
# --- MARKDOWN CHECKS ---
41+
if [ -n "$STAGED_MD_FILES" ]; then
42+
echo "Processing Markdown files..."
43+
echo " -> Formatting..."
44+
nix run nixpkgs#prettier -- --write $STAGED_MD_FILES --ignore-path .gitignore
45+
46+
echo " -> Linting..."
47+
# We run lint on the whole repo to be safe, but only if md files changed
48+
nix run nixpkgs#markdownlint-cli2 -- '**/*.md' '#.direnv' '#result' '#.git'
49+
50+
# Re-stage formatted files
51+
git add $STAGED_MD_FILES
52+
fi
3453

54+
# --- AI TRACE SCAN ---
3555
echo "Scanning for AI traces..."
3656
if command -v ai-trace-scan &>/dev/null; then
3757
ai-trace-scan --staged --quiet

.github/workflows/check.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,45 @@ name: Cave-Check
22
on:
33
push:
44
branches: [main]
5+
paths:
6+
- "**/*.nix"
7+
- "**/*.md"
8+
- "flake.lock"
59
pull_request:
610
branches: [main]
11+
paths:
12+
- "**/*.nix"
13+
- "**/*.md"
14+
- "flake.lock"
15+
716
jobs:
817
check-stones:
918
runs-on: ubuntu-latest
1019
steps:
1120
- name: Fetch Cave
12-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
1323
- name: Build Fire (Nix)
1424
uses: cachix/install-nix-action@ba0dd844c9180cbf77aa72a116d6fbc515d0e87b # v27
1525
with:
1626
nix_path: nixpkgs=channel:nixos-unstable
27+
28+
- name: Get Changed Files
29+
id: changed-files
30+
uses: tj-actions/changed-files@dcc7a0cba800f454d79dea4b963bd225b9ab999c # v45.0.5
31+
1732
- name: Magic Eye (nix flake check)
33+
if: steps.changed-files.outputs.any_modified == 'true' && (contains(steps.changed-files.outputs.all_modified_files, '.nix') || contains(steps.changed-files.outputs.all_modified_files, 'flake.lock'))
1834
run: nix flake check
35+
1936
- name: Stone Linter (statix)
37+
if: steps.changed-files.outputs.any_modified == 'true' && contains(steps.changed-files.outputs.all_modified_files, '.nix')
2038
run: nix run nixpkgs#statix -- check .
39+
2140
- name: Polish Stones (Prettier)
41+
if: steps.changed-files.outputs.any_modified == 'true' && contains(steps.changed-files.outputs.all_modified_files, '.md')
2242
run: nix run nixpkgs#prettier -- --check '**/*.md' --ignore-path .gitignore
43+
2344
- name: Wash Stones (markdownlint)
45+
if: steps.changed-files.outputs.any_modified == 'true' && contains(steps.changed-files.outputs.all_modified_files, '.md')
2446
run: nix run nixpkgs#markdownlint-cli2 -- '**/*.md' '#.direnv' '#result' '#.git'

.github/workflows/mirror.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Fetch Cave
10-
uses: actions/checkout@v4
10+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1111
with:
1212
fetch-depth: 0
1313
- name: Mirror Move
14-
uses: pixta-dev/repository-mirroring-action@v1
14+
uses: pixta-dev/repository-mirroring-action@4833250ef80ca3d066cf6660fb0090066966099a # v1.1.1
1515
with:
1616
target_repo_url: git@codeberg.org:izaac/nixos-config.git
1717
ssh_private_key: ${{ secrets.CODEBERG_SSH_KEY }}

0 commit comments

Comments
 (0)