Skip to content

Commit 5c7ef58

Browse files
echobtfactorydroid
andauthored
perf(ci): optimize CI/CD for speed with shared caching and nightly toolchain (#224)
Changes: - Switch to Rust nightly toolchain for all jobs - Add -Zthreads=16 for multithreaded frontend compilation - Use sccache (mozilla-actions/sccache-action) for shared compilation cache - Add shared cache key generation for consistent caching across jobs - Use actions/cache@v4 for cargo registry, git db, and build artifacts - Add concurrency groups to cancel duplicate runs - Enable sparse registry protocol for faster index updates - Replace Swatinem/rust-cache with explicit GitHub Actions caching - Add npm/pnpm caching for GUI builds - Add cargo-audit caching for security checks - Add CI success aggregation job for branch protection Co-authored-by: Droid Agent <droid@factory.ai>
1 parent 52f82a4 commit 5c7ef58

2 files changed

Lines changed: 301 additions & 32 deletions

File tree

.github/workflows/ci.yml

Lines changed: 219 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,105 @@ on:
99
env:
1010
CARGO_TERM_COLOR: always
1111
RUST_BACKTRACE: 1
12+
# Nightly multithreaded frontend for faster compilation
13+
RUSTFLAGS: "-Zthreads=16"
14+
# Sparse registry for faster index updates
15+
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
16+
# Incremental compilation off for CI (more reproducible, better caching)
17+
CARGO_INCREMENTAL: 0
18+
# Use sccache for shared compilation cache
19+
SCCACHE_GHA_ENABLED: "true"
20+
RUSTC_WRAPPER: "sccache"
21+
22+
# Ensure only one CI run per branch at a time
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
1226

1327
jobs:
28+
# ==========================================================================
29+
# Setup job to prepare shared cache
30+
# ==========================================================================
31+
setup-cache:
32+
name: Setup Cache
33+
runs-on: ubuntu-latest
34+
outputs:
35+
cache-key: ${{ steps.cache-key.outputs.key }}
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Generate cache key
40+
id: cache-key
41+
run: |
42+
echo "key=rust-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}" >> $GITHUB_OUTPUT
43+
44+
# ==========================================================================
45+
# Fast checks (fmt, clippy) - Run in parallel
46+
# ==========================================================================
1447
fmt:
1548
name: Format
1649
runs-on: ubuntu-latest
1750
steps:
1851
- uses: actions/checkout@v4
19-
- uses: dtolnay/rust-toolchain@stable
52+
53+
- name: Install Rust nightly
54+
uses: dtolnay/rust-toolchain@nightly
2055
with:
2156
components: rustfmt
22-
- run: cargo fmt --all -- --check
57+
58+
- name: Check formatting
59+
run: cargo +nightly fmt --all -- --check
2360

2461
clippy:
2562
name: Clippy
2663
runs-on: ubuntu-latest
64+
needs: setup-cache
2765
steps:
2866
- uses: actions/checkout@v4
67+
2968
- name: Install Linux dependencies
3069
run: |
3170
sudo apt-get update
3271
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libglib2.0-dev
33-
- uses: dtolnay/rust-toolchain@stable
72+
73+
- name: Install Rust nightly
74+
uses: dtolnay/rust-toolchain@nightly
3475
with:
3576
components: clippy
36-
- uses: Swatinem/rust-cache@v2
37-
- run: cargo clippy --workspace --all-targets --all-features --exclude cortex-gui
77+
78+
- name: Setup sccache
79+
uses: mozilla-actions/sccache-action@v0.0.6
80+
81+
- name: Cache cargo registry & git
82+
uses: actions/cache@v4
83+
with:
84+
path: |
85+
~/.cargo/registry/index/
86+
~/.cargo/registry/cache/
87+
~/.cargo/git/db/
88+
key: cargo-registry-${{ needs.setup-cache.outputs.cache-key }}
89+
restore-keys: |
90+
cargo-registry-
91+
92+
- name: Cache cargo build
93+
uses: actions/cache@v4
94+
with:
95+
path: target/
96+
key: cargo-build-clippy-${{ runner.os }}-${{ needs.setup-cache.outputs.cache-key }}
97+
restore-keys: |
98+
cargo-build-clippy-${{ runner.os }}-
99+
cargo-build-${{ runner.os }}-
100+
101+
- name: Run clippy
102+
run: cargo +nightly clippy --workspace --all-targets --all-features --exclude cortex-gui -- -D warnings
38103

104+
# ==========================================================================
105+
# Test jobs - Matrix for all platforms
106+
# ==========================================================================
39107
test:
40108
name: Test (${{ matrix.name }})
41109
runs-on: ${{ matrix.runner }}
110+
needs: setup-cache
42111
strategy:
43112
fail-fast: false
44113
matrix:
@@ -51,21 +120,51 @@ jobs:
51120
runner: windows-latest
52121
steps:
53122
- uses: actions/checkout@v4
123+
54124
- name: Install Linux dependencies
55125
if: matrix.name == 'ubuntu'
56126
run: |
57127
sudo apt-get update
58128
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libglib2.0-dev
59-
- uses: dtolnay/rust-toolchain@stable
60-
- uses: Swatinem/rust-cache@v2
129+
130+
- name: Install Rust nightly
131+
uses: dtolnay/rust-toolchain@nightly
132+
133+
- name: Setup sccache
134+
uses: mozilla-actions/sccache-action@v0.0.6
135+
136+
- name: Cache cargo registry & git
137+
uses: actions/cache@v4
138+
with:
139+
path: |
140+
~/.cargo/registry/index/
141+
~/.cargo/registry/cache/
142+
~/.cargo/git/db/
143+
key: cargo-registry-${{ needs.setup-cache.outputs.cache-key }}
144+
restore-keys: |
145+
cargo-registry-
146+
147+
- name: Cache cargo build
148+
uses: actions/cache@v4
61149
with:
62-
key: ${{ matrix.name }}
150+
path: target/
151+
key: cargo-build-test-${{ matrix.name }}-${{ needs.setup-cache.outputs.cache-key }}
152+
restore-keys: |
153+
cargo-build-test-${{ matrix.name }}-
154+
cargo-build-${{ matrix.name }}-
155+
63156
- name: Run tests
64-
run: cargo test --workspace --all-features --exclude cortex-gui
157+
run: cargo +nightly test --workspace --all-features --exclude cortex-gui
158+
env:
159+
RUSTFLAGS: "-Zthreads=16"
65160

161+
# ==========================================================================
162+
# Build check - All platforms
163+
# ==========================================================================
66164
build-check:
67165
name: Build Check (${{ matrix.name }})
68166
runs-on: ${{ matrix.runner }}
167+
needs: setup-cache
69168
strategy:
70169
fail-fast: false
71170
matrix:
@@ -78,21 +177,51 @@ jobs:
78177
runner: windows-latest
79178
steps:
80179
- uses: actions/checkout@v4
180+
81181
- name: Install Linux dependencies
82182
if: matrix.name == 'ubuntu'
83183
run: |
84184
sudo apt-get update
85185
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libglib2.0-dev
86-
- uses: dtolnay/rust-toolchain@stable
87-
- uses: Swatinem/rust-cache@v2
186+
187+
- name: Install Rust nightly
188+
uses: dtolnay/rust-toolchain@nightly
189+
190+
- name: Setup sccache
191+
uses: mozilla-actions/sccache-action@v0.0.6
192+
193+
- name: Cache cargo registry & git
194+
uses: actions/cache@v4
88195
with:
89-
key: ${{ matrix.name }}
196+
path: |
197+
~/.cargo/registry/index/
198+
~/.cargo/registry/cache/
199+
~/.cargo/git/db/
200+
key: cargo-registry-${{ needs.setup-cache.outputs.cache-key }}
201+
restore-keys: |
202+
cargo-registry-
203+
204+
- name: Cache cargo build
205+
uses: actions/cache@v4
206+
with:
207+
path: target/
208+
key: cargo-build-check-${{ matrix.name }}-${{ needs.setup-cache.outputs.cache-key }}
209+
restore-keys: |
210+
cargo-build-check-${{ matrix.name }}-
211+
cargo-build-${{ matrix.name }}-
212+
90213
- name: Check build
91-
run: cargo check --workspace --all-features --exclude cortex-gui
214+
run: cargo +nightly check --workspace --all-features --exclude cortex-gui
215+
env:
216+
RUSTFLAGS: "-Zthreads=16"
92217

218+
# ==========================================================================
219+
# GUI Check - All platforms
220+
# ==========================================================================
93221
gui-check:
94222
name: GUI Check (${{ matrix.name }})
95223
runs-on: ${{ matrix.runner }}
224+
needs: setup-cache
96225
strategy:
97226
fail-fast: false
98227
matrix:
@@ -105,29 +234,71 @@ jobs:
105234
runner: windows-latest
106235
steps:
107236
- uses: actions/checkout@v4
237+
108238
- uses: actions/setup-node@v4
109239
with:
110240
node-version: "20"
111241
cache: "npm"
112242
cache-dependency-path: cortex-gui/package-lock.json
243+
113244
- name: Install Linux dependencies
114245
if: matrix.name == 'ubuntu'
115246
run: |
116247
sudo apt-get update
117248
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libglib2.0-dev
249+
250+
- name: Cache npm
251+
uses: actions/cache@v4
252+
with:
253+
path: |
254+
cortex-gui/node_modules
255+
~/.npm
256+
key: npm-${{ matrix.name }}-${{ hashFiles('cortex-gui/package-lock.json') }}
257+
restore-keys: |
258+
npm-${{ matrix.name }}-
259+
118260
- name: Install frontend dependencies
119261
working-directory: cortex-gui
120262
run: npm ci
263+
121264
- name: Build frontend
122265
working-directory: cortex-gui
123266
run: npm run build
124-
- uses: dtolnay/rust-toolchain@stable
125-
- uses: Swatinem/rust-cache@v2
267+
268+
- name: Install Rust nightly
269+
uses: dtolnay/rust-toolchain@nightly
270+
271+
- name: Setup sccache
272+
uses: mozilla-actions/sccache-action@v0.0.6
273+
274+
- name: Cache cargo registry & git
275+
uses: actions/cache@v4
126276
with:
127-
key: gui-${{ matrix.name }}
277+
path: |
278+
~/.cargo/registry/index/
279+
~/.cargo/registry/cache/
280+
~/.cargo/git/db/
281+
key: cargo-registry-${{ needs.setup-cache.outputs.cache-key }}
282+
restore-keys: |
283+
cargo-registry-
284+
285+
- name: Cache cargo build (GUI)
286+
uses: actions/cache@v4
287+
with:
288+
path: target/
289+
key: cargo-build-gui-${{ matrix.name }}-${{ needs.setup-cache.outputs.cache-key }}
290+
restore-keys: |
291+
cargo-build-gui-${{ matrix.name }}-
292+
cargo-build-${{ matrix.name }}-
293+
128294
- name: Check GUI build
129-
run: cargo check -p cortex-gui
295+
run: cargo +nightly check -p cortex-gui
296+
env:
297+
RUSTFLAGS: "-Zthreads=16"
130298

299+
# ==========================================================================
300+
# Security Audit
301+
# ==========================================================================
131302
audit:
132303
name: Security Audit
133304
runs-on: ubuntu-latest
@@ -136,6 +307,37 @@ jobs:
136307
contents: read
137308
steps:
138309
- uses: actions/checkout@v4
310+
311+
- name: Cache cargo-audit
312+
uses: actions/cache@v4
313+
with:
314+
path: |
315+
~/.cargo/bin/cargo-audit
316+
~/.cargo/advisory-db
317+
key: cargo-audit-${{ runner.os }}
318+
139319
- uses: rustsec/audit-check@v2
140320
with:
141321
token: ${{ secrets.GITHUB_TOKEN }}
322+
323+
# ==========================================================================
324+
# Final status check (for branch protection)
325+
# ==========================================================================
326+
ci-success:
327+
name: CI Success
328+
runs-on: ubuntu-latest
329+
needs: [fmt, clippy, test, build-check, gui-check, audit]
330+
if: always()
331+
steps:
332+
- name: Check all jobs
333+
run: |
334+
if [[ "${{ needs.fmt.result }}" == "failure" || \
335+
"${{ needs.clippy.result }}" == "failure" || \
336+
"${{ needs.test.result }}" == "failure" || \
337+
"${{ needs.build-check.result }}" == "failure" || \
338+
"${{ needs.gui-check.result }}" == "failure" || \
339+
"${{ needs.audit.result }}" == "failure" ]]; then
340+
echo "One or more jobs failed"
341+
exit 1
342+
fi
343+
echo "All CI checks passed!"

0 commit comments

Comments
 (0)