Skip to content

Commit e86417d

Browse files
chore: improve CI/CD infrastructure and tooling configuration
- Refactored GitHub Actions workflows with deny, WASM, and enhanced caching - Simplified mise.toml to tool definitions only (removed task aliases) - Refactored install scripts for cross-project reusability with environment config - Added yamllint configuration for YAML validation - Updated CHANGELOG.md with comprehensive infrastructure improvements
1 parent 2f18c2e commit e86417d

File tree

11 files changed

+629
-583
lines changed

11 files changed

+629
-583
lines changed
Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
---
2-
name: Cleanup caches for closed PRs
2+
name: Cache Cleanup
33

44
on:
5-
# Run twice every day to remove the cache so that the caches from the closed prs
6-
# are removed.
75
schedule:
86
- cron: '0 17 * * *'
97
- cron: '30 18 * * *'
8+
109
workflow_dispatch:
1110

11+
permissions: write-all
12+
1213
jobs:
1314
cleanup:
14-
name: Clear all GitHub action caches
15+
name: Cleanup Caches
1516
runs-on: ubuntu-latest
16-
permissions: write-all
17-
1817
steps:
19-
- name: Clear all caches
18+
- name: Get all cache keys
19+
id: caches
2020
run: |
21-
echo "Fetching list of cache key"
22-
cacheKeysForPR=$(gh cache list --limit 1000 --json id --jq '.[].id')
21+
gh cache list --limit 100 --json id,key --jq '.[].id' > cache_ids.txt
22+
CACHE_COUNT=$(wc -l < cache_ids.txt)
23+
echo "Found $CACHE_COUNT caches to delete"
24+
echo "cache_count=$CACHE_COUNT" >> "$GITHUB_OUTPUT"
25+
env:
26+
GH_TOKEN: ${{ github.token }}
2327

24-
## Setting this to not fail the workflow while deleting cache keys.
25-
set +e
26-
echo "Deleting caches..."
27-
for cacheKey in $cacheKeysForPR
28-
do
29-
gh cache delete $cacheKey
30-
done
31-
echo "Done"
28+
- name: Delete all caches
29+
if: steps.caches.outputs.cache_count != '0'
30+
run: |
31+
set +e # Don't fail if some caches can't be deleted
32+
while read -r cache_id; do
33+
echo "Deleting cache: $cache_id"
34+
gh cache delete "$cache_id"
35+
done < cache_ids.txt
3236
env:
3337
GH_TOKEN: ${{ github.token }}
34-
GH_REPO: ${{ github.repository }}
38+
39+
- name: Summary
40+
run: |
41+
echo "Cache cleanup completed"
42+
if [ "${{ steps.caches.outputs.cache_count }}" = "0" ]; then
43+
echo "No caches to delete"
44+
else
45+
echo "Deleted ${{ steps.caches.outputs.cache_count }} caches"
46+
fi

.github/workflows/ci.yml

Lines changed: 97 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ env:
1717
CARGO_INCREMENTAL: 0
1818
CARGO_NET_RETRY: 10
1919
RUSTUP_MAX_RETRIES: 10
20-
# Performance improvements
2120
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
2221
CARGO_PROFILE_DEV_DEBUG: 0
2322

@@ -26,7 +25,6 @@ concurrency:
2625
cancel-in-progress: true
2726

2827
jobs:
29-
# Detect which crates have changed
3028
changed-files:
3129
name: Detect changed crates
3230
runs-on: ubuntu-latest
@@ -48,16 +46,7 @@ jobs:
4846
files: |
4947
Cargo.toml
5048
Cargo.lock
51-
file-formats/archives/wow-mpq/**
52-
file-formats/world-data/wow-adt/**
53-
file-formats/world-data/wow-wdl/**
54-
file-formats/world-data/wow-wdt/**
55-
file-formats/graphics/wow-blp/**
56-
file-formats/graphics/wow-m2/**
57-
file-formats/graphics/wow-wmo/**
58-
file-formats/database/wow-cdbc/**
59-
warcraft-rs/**
60-
ffi/**
49+
crates/**
6150
files_ignore: |
6251
**/*.md
6352
**/*.txt
@@ -70,46 +59,42 @@ jobs:
7059
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
7160
run: |
7261
echo "Changed files: $ALL_CHANGED_FILES"
73-
74-
# If no files changed, we still need to run tests (e.g., scheduled runs)
62+
7563
if [ -z "$ALL_CHANGED_FILES" ]; then
7664
echo "No files changed, will test all crates"
77-
echo "any_crate_changed=true" >> $GITHUB_OUTPUT
78-
echo "crates_changed=" >> $GITHUB_OUTPUT
65+
echo "any_crate_changed=true" >> "$GITHUB_OUTPUT"
66+
echo "crates_changed=" >> "$GITHUB_OUTPUT"
7967
exit 0
8068
fi
81-
82-
# Detect which crates changed
83-
crates_changed=""
84-
85-
# Check if root Cargo.toml or Cargo.lock changed (affects all crates)
69+
8670
if echo "$ALL_CHANGED_FILES" | grep -E "^Cargo\.(toml|lock)$"; then
8771
echo "Root Cargo files changed, will test all crates"
88-
echo "any_crate_changed=true" >> $GITHUB_OUTPUT
89-
echo "crates_changed=" >> $GITHUB_OUTPUT
72+
echo "any_crate_changed=true" >> "$GITHUB_OUTPUT"
73+
echo "crates_changed=" >> "$GITHUB_OUTPUT"
9074
exit 0
9175
fi
92-
93-
# Check individual crate changes
94-
for crate in wow-mpq wow-adt wow-wdl wow-wdt wow-blp wow-m2 wow-wmo wow-cdbc warcraft-rs; do
95-
if echo "$ALL_CHANGED_FILES" | grep -E "$crate/"; then
96-
crates_changed="$crates_changed $crate"
97-
fi
98-
done
99-
100-
# Remove leading space and output
101-
crates_changed=$(echo $crates_changed | xargs)
76+
77+
crates_changed=""
78+
if [ -d "crates" ]; then
79+
for crate_dir in crates/*/; do
80+
crate=$(basename "$crate_dir")
81+
if echo "$ALL_CHANGED_FILES" | grep -E "crates/$crate/"; then
82+
crates_changed="$crates_changed $crate"
83+
fi
84+
done
85+
fi
86+
87+
crates_changed=$(echo "$crates_changed" | xargs)
10288
if [ -n "$crates_changed" ]; then
10389
echo "Crates changed: $crates_changed"
104-
echo "any_crate_changed=true" >> $GITHUB_OUTPUT
105-
echo "crates_changed=$crates_changed" >> $GITHUB_OUTPUT
90+
echo "any_crate_changed=true" >> "$GITHUB_OUTPUT"
91+
echo "crates_changed=$crates_changed" >> "$GITHUB_OUTPUT"
10692
else
10793
echo "No crate changes detected"
108-
echo "any_crate_changed=false" >> $GITHUB_OUTPUT
109-
echo "crates_changed=" >> $GITHUB_OUTPUT
94+
echo "any_crate_changed=false" >> "$GITHUB_OUTPUT"
95+
echo "crates_changed=" >> "$GITHUB_OUTPUT"
11096
fi
11197
112-
# Quick checks that should fail fast
11398
quick-checks:
11499
name: Quick Checks
115100
runs-on: ubuntu-latest
@@ -120,7 +105,7 @@ jobs:
120105
- name: Install Rust toolchain with formatting and linting components
121106
uses: dtolnay/rust-toolchain@v1
122107
with:
123-
toolchain: 1.92.0
108+
toolchain: 1.92
124109
components: rustfmt, clippy
125110

126111
- name: Cache Rust dependencies
@@ -130,19 +115,29 @@ jobs:
130115
cache-on-failure: true
131116
cache-all-crates: true
132117

133-
# Format check (fastest)
134118
- name: Check formatting
135119
run: cargo fmt --all -- --check
136120

137-
# Check compilation
138121
- name: Check compilation
139-
run: cargo check --all-features --all-targets
122+
run: cargo check --workspace --all-targets
140123

141-
# Clippy lints
142124
- name: Clippy
143-
run: cargo clippy --all-features --all-targets -- -D warnings
125+
run: cargo clippy --workspace --all-targets
126+
127+
deny:
128+
name: Cargo Deny
129+
runs-on: ubuntu-latest
130+
steps:
131+
- name: Checkout repository
132+
uses: actions/checkout@v4
133+
134+
- name: Check dependencies
135+
uses: EmbarkStudios/cargo-deny-action@v2
136+
with:
137+
command: check
138+
arguments: --all-features
139+
rust-version: "1.92"
144140

145-
# Main test suite with optimized matrix
146141
test:
147142
name: Test (${{ matrix.rust }} on ${{ matrix.os }})
148143
needs: [quick-checks, changed-files]
@@ -152,7 +147,7 @@ jobs:
152147
matrix:
153148
include:
154149
- os: ubuntu-latest
155-
rust: 1.92.0
150+
rust: 1.92
156151
- os: ubuntu-latest
157152
rust: stable
158153
runs-on: ${{ matrix.os }}
@@ -165,6 +160,11 @@ jobs:
165160
with:
166161
toolchain: ${{ matrix.rust }}
167162

163+
- name: Install cargo-nextest
164+
uses: taiki-e/install-action@v2
165+
with:
166+
tool: cargo-nextest
167+
168168
- name: Cache Rust dependencies for ${{ matrix.os }}
169169
uses: Swatinem/rust-cache@v2
170170
with:
@@ -173,49 +173,61 @@ jobs:
173173
cache-all-crates: true
174174
save-if: ${{ github.ref == 'refs/heads/main' }}
175175

176-
- name: Install cargo-nextest
177-
uses: taiki-e/install-action@v2
178-
with:
179-
tool: cargo-nextest
180-
181-
# Determine test scope based on changed crates
182176
- name: Determine test scope
183177
id: test-scope
184178
env:
185179
CRATES_CHANGED: ${{ needs.changed-files.outputs.crates_changed }}
186180
run: |
187181
if [ -z "$CRATES_CHANGED" ]; then
188182
echo "Testing all crates (full workspace test)"
189-
echo "test_args=--workspace" >> $GITHUB_OUTPUT
183+
echo "test_args=--workspace" >> "$GITHUB_OUTPUT"
190184
else
191185
echo "Testing only changed crates: $CRATES_CHANGED"
192186
args=""
193187
for crate in $CRATES_CHANGED; do
194188
args="$args -p $crate"
195189
done
196-
echo "test_args=$args" >> $GITHUB_OUTPUT
190+
echo "test_args=$args" >> "$GITHUB_OUTPUT"
197191
fi
198192
199-
# Test with all features
200-
- name: Test all features (changed crates)
201-
run: cargo nextest run --all-features ${{ steps.test-scope.outputs.test_args }}
193+
- name: Test default features (changed crates)
194+
run: cargo nextest run --profile ci ${{ steps.test-scope.outputs.test_args }}
202195

203-
# Test with no default features
204196
- name: Test no default features (changed crates)
205-
run: cargo nextest run --no-default-features ${{ steps.test-scope.outputs.test_args }}
197+
run: cargo nextest run --profile ci --no-default-features ${{ steps.test-scope.outputs.test_args }}
206198

207-
# Test each changed crate individually (only on stable Linux)
208-
- name: Test individual changed crates
209-
if: matrix.os == 'ubuntu-latest' && matrix.rust == 'stable' && needs.changed-files.outputs.crates_changed != ''
199+
wasm:
200+
name: WASM Compilation
201+
runs-on: ubuntu-latest
202+
if: vars.WASM_CRATES != '[]'
203+
steps:
204+
- name: Checkout repository
205+
uses: actions/checkout@v4
206+
207+
- name: Install Rust toolchain with WASM target
208+
uses: dtolnay/rust-toolchain@v1
209+
with:
210+
toolchain: 1.92
211+
targets: wasm32-unknown-unknown
212+
213+
- name: Cache Rust dependencies
214+
uses: Swatinem/rust-cache@v2
215+
with:
216+
shared-key: "wasm-${{ hashFiles('**/Cargo.lock') }}"
217+
cache-on-failure: true
218+
cache-all-crates: true
219+
220+
- name: Check WASM compilation
210221
env:
211-
CRATES_CHANGED: ${{ needs.changed-files.outputs.crates_changed }}
222+
WASM_CRATES: ${{ vars.WASM_CRATES }}
212223
run: |
213-
for crate in $CRATES_CHANGED; do
214-
echo "Testing $crate individually..."
215-
cargo nextest run -p $crate --all-features
216-
done
224+
if [ -n "$WASM_CRATES" ]; then
225+
for crate in $(echo "$WASM_CRATES" | jq -r '.[]'); do
226+
echo "Checking $crate for WASM..."
227+
cargo check --target wasm32-unknown-unknown -p "$crate"
228+
done
229+
fi
217230
218-
# Documentation build - runs in parallel
219231
docs:
220232
name: Documentation
221233
runs-on: ubuntu-latest
@@ -226,23 +238,23 @@ jobs:
226238
- name: Install Rust toolchain for documentation
227239
uses: dtolnay/rust-toolchain@v1
228240
with:
229-
toolchain: 1.92.0
241+
toolchain: 1.92
230242

231243
- name: Cache documentation dependencies
232244
uses: Swatinem/rust-cache@v2
233245
with:
234246
shared-key: "docs-${{ hashFiles('**/Cargo.lock') }}"
235247
cache-on-failure: true
236248
cache-all-crates: true
249+
237250
- name: Build documentation
238-
run: cargo doc --all-features --no-deps
251+
run: cargo doc --workspace --no-deps
239252
env:
240253
RUSTDOCFLAGS: -D warnings
241-
- name: Check for broken links
242-
run: cargo doc --all-features --no-deps --document-private-items
243254

255+
- name: Check for broken links
256+
run: cargo doc --workspace --no-deps --document-private-items
244257

245-
# Coverage collection - runs in parallel
246258
coverage:
247259
name: Code Coverage
248260
runs-on: ubuntu-latest
@@ -269,8 +281,13 @@ jobs:
269281
with:
270282
tool: cargo-llvm-cov
271283

284+
- name: Install cargo-nextest for faster coverage collection
285+
uses: taiki-e/install-action@v2
286+
with:
287+
tool: cargo-nextest
288+
272289
- name: Collect coverage
273-
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
290+
run: cargo llvm-cov nextest --workspace --lcov --output-path lcov.info
274291

275292
- name: Upload coverage reports to Codecov
276293
uses: codecov/codecov-action@v5
@@ -279,25 +296,24 @@ jobs:
279296
fail_ci_if_error: false
280297
token: ${{ secrets.CODECOV_TOKEN }}
281298

282-
# Success marker for branch protection
283299
ci-success:
284300
name: CI Success
285301
if: always()
286-
needs: [quick-checks, test, docs, changed-files]
302+
needs: [quick-checks, deny, test, docs, wasm, coverage, changed-files]
287303
runs-on: ubuntu-latest
288304
steps:
289305
- name: Check all jobs
290306
run: |
291-
# Skip test job check if no crates changed
292307
if [[ "${{ needs.changed-files.outputs.any_crate_changed }}" == "false" ]]; then
293308
echo "No crate changes detected, skipping test job check"
294-
if [[ "${{ needs.quick-checks.result }}" == "failure" || "${{ needs.docs.result }}" == "failure" ]]; then
295-
echo "Quick checks or docs failed"
309+
if [[ "${{ needs.quick-checks.result }}" == "failure" || "${{ needs.deny.result }}" == "failure" || "${{ needs.docs.result }}" == "failure" ]]; then
310+
echo "Quick checks, deny, or docs failed"
296311
exit 1
297312
fi
298313
else
299-
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
300-
echo "One or more jobs failed"
314+
# Check critical jobs (wasm and coverage are optional)
315+
if [[ "${{ needs.quick-checks.result }}" == "failure" || "${{ needs.deny.result }}" == "failure" || "${{ needs.test.result }}" == "failure" || "${{ needs.docs.result }}" == "failure" ]]; then
316+
echo "Critical job failed"
301317
exit 1
302318
fi
303319
fi

0 commit comments

Comments
 (0)