Skip to content

Commit 928aa0b

Browse files
committed
chore(ci): implement smart test caching with just across all languages
1 parent d32605c commit 928aa0b

3 files changed

Lines changed: 107 additions & 6 deletions

File tree

.github/workflows/tests.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ jobs:
8787
if: ${{ matrix.project == '2021/_4' }}
8888
- name: Set up cargo-nextest
8989
uses: taiki-e/install-action@nextest
90+
- name: Install just
91+
uses: taiki-e/install-action@just
92+
- name: Restore cache
93+
uses: actions/cache@v4
94+
with:
95+
path: .cache
96+
key: ${{ runner.os }}-rust-cache-${{ hashFiles('**/Cargo.lock', 'aoc-rust-common/src/**') }}-${{ matrix.project }}
97+
restore-keys: |
98+
${{ runner.os }}-rust-cache-
9099
- name: Run Clippy
91100
run: cargo clippy --workspace -- -A warnings
92101
working-directory: ${{ matrix.project }}
93102
continue-on-error: true
94103
- name: Run Rust tests
95-
run: cargo test
96-
working-directory: ${{ matrix.project }}
104+
run: just test-project-rust ${{ matrix.project }}
97105
env:
98106
RUSTFLAGS: --cfg advent_of_code_ci
99107

@@ -112,9 +120,17 @@ jobs:
112120
with:
113121
go-version: '1.22.x'
114122
cache: false
123+
- name: Install just
124+
uses: taiki-e/install-action@just
125+
- name: Restore cache
126+
uses: actions/cache@v4
127+
with:
128+
path: .cache
129+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.mod', 'aoc-go-common/**') }}-${{ matrix.project }}
130+
restore-keys: |
131+
${{ runner.os }}-go-cache-
115132
- name: Run Go tests
116-
run: go test ./...
117-
working-directory: ${{ matrix.project }}
133+
run: just test-project-go ${{ matrix.project }}
118134

119135
zig_tests:
120136
needs: detect_changes
@@ -130,7 +146,15 @@ jobs:
130146
uses: goto-bus-stop/setup-zig@v2
131147
with:
132148
version: 0.14.0
149+
- name: Install just
150+
uses: taiki-e/install-action@just
151+
- name: Restore cache
152+
uses: actions/cache@v4
153+
with:
154+
path: .cache
155+
key: ${{ runner.os }}-zig-cache-${{ matrix.project }}
156+
restore-keys: |
157+
${{ runner.os }}-zig-cache-
133158
- name: Run Zig tests
134-
run: zig build test
135-
working-directory: ${{ matrix.project }}
159+
run: just test-project-zig ${{ matrix.project }}
136160
continue-on-error: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.gemini/
44
gha-creds-*.json
55
target/
6+
.cache/

justfile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
set shell := ["bash", "-c"]
2+
3+
# Run all tests across all languages
4+
test-all:
5+
just test-rust
6+
just test-go
7+
just test-zig
8+
9+
# --- Rust ---
10+
11+
# Run all Rust tests
12+
test-rust:
13+
@for project in 2015 2018 2019/aoc_rust 2020/01 2021/_1 2021/_2 2021/_3 2021/_4 2021/_5 2021/_6 2021/_7 2022 2023/rust 2025/rust runner; do \
14+
just test-project-rust $project; \
15+
done
16+
17+
# Run a specific Rust project if its files or aoc-rust-common changed
18+
test-project-rust project:
19+
@mkdir -p .cache/rust
20+
@SAFE_NAME=$(echo {{project}} | tr '/' '_')
21+
@# Hash the project dir AND the shared rust library
22+
@HASH=$(find {{project}} aoc-rust-common -type f -not -path "*/target/*" -not -path "*/.git/*" 2>/dev/null | sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
23+
@if [ -z "$HASH" ]; then HASH="empty"; fi
24+
@if [ -f .cache/rust/$SAFE_NAME.success ] && [ "$(cat .cache/rust/$SAFE_NAME.success)" = "$HASH" ]; then \
25+
echo "✅ Rust: {{project}} (Cached)"; \
26+
else \
27+
echo "🚀 Rust: Running {{project}}..."; \
28+
(cd {{project}} && cargo test) && echo "$HASH" > .cache/rust/$SAFE_NAME.success; \
29+
fi
30+
31+
# --- Go ---
32+
33+
# Run all Go tests
34+
test-go:
35+
@for project in 2017 2019/go 2020/02 2024/golang; do \
36+
just test-project-go $project; \
37+
done
38+
39+
# Run a specific Go project if its files or aoc-go-common changed
40+
test-project-go project:
41+
@mkdir -p .cache/go
42+
@SAFE_NAME=$(echo {{project}} | tr '/' '_')
43+
@# Hash the project dir AND the shared go library
44+
@HASH=$(find {{project}} aoc-go-common -type f -not -path "*/.git/*" 2>/dev/null | sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
45+
@if [ -z "$HASH" ]; then HASH="empty"; fi
46+
@if [ -f .cache/go/$SAFE_NAME.success ] && [ "$(cat .cache/go/$SAFE_NAME.success)" = "$HASH" ]; then \
47+
echo "✅ Go: {{project}} (Cached)"; \
48+
else \
49+
echo "🚀 Go: Running {{project}}..."; \
50+
(cd {{project}} && go test ./...) && echo "$HASH" > .cache/go/$SAFE_NAME.success; \
51+
fi
52+
53+
# --- Zig ---
54+
55+
# Run all Zig tests
56+
test-zig:
57+
@for project in 2021/zig 2024/zig; do \
58+
just test-project-zig $project; \
59+
done
60+
61+
# Run a specific Zig project if its files changed
62+
test-project-zig project:
63+
@mkdir -p .cache/zig
64+
@SAFE_NAME=$(echo {{project}} | tr '/' '_')
65+
@HASH=$(find {{project}} -type f -not -path "*/.zig-cache/*" -not -path "*/zig-out/*" -not -path "*/.git/*" 2>/dev/null | sort | xargs shasum -a 256 | shasum -a 256 | awk '{print $1}')
66+
@if [ -z "$HASH" ]; then HASH="empty"; fi
67+
@if [ -f .cache/zig/$SAFE_NAME.success ] && [ "$(cat .cache/zig/$SAFE_NAME.success)" = "$HASH" ]; then \
68+
echo "✅ Zig: {{project}} (Cached)"; \
69+
else \
70+
echo "🚀 Zig: Running {{project}}..."; \
71+
(cd {{project}} && zig build test) && echo "$HASH" > .cache/zig/$SAFE_NAME.success; \
72+
fi
73+
74+
# Clean all test caches
75+
clean-cache:
76+
rm -rf .cache

0 commit comments

Comments
 (0)