@@ -3,8 +3,18 @@ name: CI
33on :
44 push :
55 branches : [ main, develop ]
6+ paths :
7+ - ' **.rs'
8+ - ' Cargo.toml'
9+ - ' Cargo.lock'
10+ - ' .github/workflows/ci.yml'
611 pull_request :
712 branches : [ main, develop ]
13+ paths :
14+ - ' **.rs'
15+ - ' Cargo.toml'
16+ - ' Cargo.lock'
17+ - ' .github/workflows/ci.yml'
818
919env :
1020 CARGO_TERM_COLOR : always
@@ -21,10 +31,20 @@ jobs:
2131 with :
2232 components : rustfmt, clippy
2333
34+ - name : Cache prek binary
35+ id : cache-prek
36+ uses : actions/cache@v4
37+ with :
38+ path : ~/.local/bin/prek
39+ key : prek-${{ runner.os }}-latest
40+
2441 - name : Install prek
42+ if : steps.cache-prek.outputs.cache-hit != 'true'
2543 run : |
2644 curl -LsSf https://github.com/j178/prek/releases/latest/download/prek-installer.sh | sh
27- echo "$HOME/.local/bin" >> $GITHUB_PATH
45+
46+ - name : Add prek to PATH
47+ run : echo "$HOME/.local/bin" >> $GITHUB_PATH
2848
2949 - name : Run prek
3050 run : prek run --all-files
@@ -35,52 +55,68 @@ jobs:
3555 strategy :
3656 matrix :
3757 os : [ubuntu-latest, macos-latest, windows-latest]
38- rust : [stable, beta]
58+ rust : [stable]
59+ include :
60+ # Only run on Linux for PR, all platforms for push to main
61+ - os : ubuntu-latest
62+ rust : stable
3963 steps :
4064 - uses : actions/checkout@v4
4165
42- - name : Install Rust
43- uses : dtolnay/rust-toolchain@master
44- with :
45- toolchain : ${{ matrix.rust }}
46- components : rustfmt, clippy
47-
48- - name : Cache cargo registry
49- uses : actions/cache@v4
50- with :
51- path : ~/.cargo/registry
52- key : ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
66+ # Skip macOS and Windows tests on pull requests
67+ - name : Check if should run
68+ id : should-run
69+ run : |
70+ if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ matrix.os }}" != "ubuntu-latest" ]; then
71+ echo "skip=true" >> $GITHUB_OUTPUT
72+ else
73+ echo "skip=false" >> $GITHUB_OUTPUT
74+ fi
75+ shell : bash
5376
54- - name : Cache cargo index
55- uses : actions/cache@v4
56- with :
57- path : ~/.cargo/git
58- key : ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
77+ - name : Install Rust
78+ if : steps.should-run.outputs.skip != 'true'
79+ uses : dtolnay/rust-toolchain@stable
5980
60- - name : Cache cargo build
61- uses : actions/cache@v4
81+ - name : Rust Cache
82+ if : steps.should-run.outputs.skip != 'true'
83+ uses : Swatinem/rust-cache@v2
6284 with :
63- path : target
64- key : ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
85+ shared-key : ${{ matrix.os }}-${{ matrix.rust }}
6586
6687 - name : Build
88+ if : steps.should-run.outputs.skip != 'true'
6789 run : cargo build --verbose
6890
6991 - name : Run tests
92+ if : steps.should-run.outputs.skip != 'true'
7093 run : cargo test --verbose
7194
7295 coverage :
7396 name : Code Coverage
7497 runs-on : ubuntu-latest
98+ # Only run coverage on push to main branch
99+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
75100 continue-on-error : true
76101 steps :
77102 - uses : actions/checkout@v4
78103
79104 - name : Install Rust
80105 uses : dtolnay/rust-toolchain@stable
81106
107+ - name : Rust Cache
108+ uses : Swatinem/rust-cache@v2
109+
110+ - name : Cache tarpaulin binary
111+ id : cache-tarpaulin
112+ uses : actions/cache@v4
113+ with :
114+ path : ~/.cargo/bin/cargo-tarpaulin
115+ key : tarpaulin-${{ runner.os }}-0.31.2
116+
82117 - name : Install tarpaulin
83- run : cargo install cargo-tarpaulin
118+ if : steps.cache-tarpaulin.outputs.cache-hit != 'true'
119+ run : cargo install cargo-tarpaulin --version 0.31.2
84120
85121 - name : Run tarpaulin
86122 run : cargo tarpaulin --verbose --all-features --workspace --timeout 120 --out xml
0 commit comments