@@ -26,10 +26,34 @@ jobs:
2626 - name : Checkout
2727 uses : actions/checkout@v4
2828
29+ - name : Fail if junk files are tracked
30+ run : ./scripts/check_junk_files.sh
31+
32+ - name : Detect Rust-relevant changes
33+ id : rust_changes
34+ run : |
35+ if [ "${{ github.event_name }}" != "pull_request" ]; then
36+ echo "changed=true" >> "$GITHUB_OUTPUT"
37+ exit 0
38+ fi
39+
40+ git fetch --no-tags --depth=1 origin "${{ github.base_ref }}"
41+ if git diff --name-only "origin/${{ github.base_ref }}...HEAD" | grep -Eq '(^|/)(Cargo\.toml|Cargo\.lock|rust-toolchain(\.toml)?)$|(^|/)\.cargo/|\.rs$'; then
42+ echo "changed=true" >> "$GITHUB_OUTPUT"
43+ else
44+ echo "changed=false" >> "$GITHUB_OUTPUT"
45+ fi
46+
47+ - name : Skip Rust build/test for non-Rust changes
48+ if : steps.rust_changes.outputs.changed != 'true'
49+ run : echo "No Rust-relevant file changes detected; skipping Rust compile/test steps."
50+
2951 - name : Set up Rust
52+ if : steps.rust_changes.outputs.changed == 'true'
3053 uses : dtolnay/rust-toolchain@stable
3154
3255 - name : Cache cargo
56+ if : steps.rust_changes.outputs.changed == 'true'
3357 uses : actions/cache@v4
3458 with :
3559 path : |
@@ -41,39 +65,47 @@ jobs:
4165 restore-keys : ${{ runner.os }}-cargo-
4266
4367 - name : Install cargo-audit
68+ if : steps.rust_changes.outputs.changed == 'true'
4469 run : |
4570 if ! command -v cargo-audit &> /dev/null; then
4671 cargo install cargo-audit --locked
4772 fi
4873
4974 - name : fmt
75+ if : steps.rust_changes.outputs.changed == 'true'
5076 run : cargo fmt --all -- --check
5177
5278 - name : clippy
79+ if : steps.rust_changes.outputs.changed == 'true'
5380 run : cargo clippy --workspace --all-targets -- -D warnings
5481
5582 - name : tests
83+ if : steps.rust_changes.outputs.changed == 'true'
5684 run : cargo test --workspace -- --test-threads=1
5785
5886 - name : Install cargo-llvm-cov
87+ if : steps.rust_changes.outputs.changed == 'true'
5988 uses : taiki-e/install-action@cargo-llvm-cov
6089
6190 - name : Run tests with coverage
91+ if : steps.rust_changes.outputs.changed == 'true'
6292 run : cargo llvm-cov --workspace --lcov --output-path lcov.info
6393
6494 - name : Upload coverage to Codecov
95+ if : ${{ always() && steps.rust_changes.outputs.changed == 'true' }}
6596 uses : codecov/codecov-action@v4
6697 with :
6798 files : lcov.info
6899 token : ${{ secrets.CODECOV_TOKEN }}
69- if : always()
70100
71101 - name : Build documentation
102+ if : steps.rust_changes.outputs.changed == 'true'
72103 run : cargo doc --workspace --no-deps
73104 env :
74105 RUSTDOCFLAGS : -D warnings
75106
76107 - name : Security audit
108+ if : steps.rust_changes.outputs.changed == 'true'
77109 run : cargo audit
78110
79111 benchmarks :
86118 with :
87119 fetch-depth : 0
88120
121+ - name : Fail if junk files are tracked
122+ run : ./scripts/check_junk_files.sh
123+
89124 - name : Set up Rust
90125 uses : dtolnay/rust-toolchain@stable
91126
@@ -169,6 +204,9 @@ jobs:
169204 - name : Checkout
170205 uses : actions/checkout@v4
171206
207+ - name : Fail if junk files are tracked
208+ run : ./scripts/check_junk_files.sh
209+
172210 - name : Set up Python
173211 uses : actions/setup-python@v5
174212 with :
0 commit comments