Skip to content

Commit dc56627

Browse files
committed
feat(ci): parallelize jobs
1 parent d511afe commit dc56627

File tree

1 file changed

+149
-76
lines changed

1 file changed

+149
-76
lines changed

.github/workflows/ci.yml

Lines changed: 149 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,162 @@ env:
1313
RUSTFLAGS: -Dwarnings
1414
RUSTDOCFLAGS: -Dwarnings
1515
MSRV: "1.85"
16-
RS_EXAMPLES_LIST: "dumbpipe-web,extism/host,extism/iroh-extism-host-functions,extism/plugin,iroh-automerge,iroh-automerge-repo,iroh-gateway,frosty,browser-echo,framed-messages,custom-router"
17-
WASM_EXAMPLES_LIST: "browser-echo"
1816
IROH_FORCE_STAGING_RELAYS: "1"
1917

2018
jobs:
21-
build_and_test_nix:
22-
timeout-minutes: 30
23-
name: Build and test (Nix)
24-
runs-on: ${{ matrix.runner }}
19+
# Prepare dependencies and cache them for all other jobs
20+
prepare:
21+
name: Prepare dependencies
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 20
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
submodules: recursive
29+
30+
- name: Install Rust toolchain
31+
uses: dtolnay/rust-toolchain@stable
32+
with:
33+
components: clippy,rustfmt
34+
35+
- name: Add wasm target
36+
run: rustup target add wasm32-unknown-unknown
37+
38+
- name: Setup Rust cache
39+
uses: Swatinem/rust-cache@v2
40+
with:
41+
shared-key: "iroh-examples-shared"
42+
cache-all-crates: true
43+
44+
- name: Fetch dependencies
45+
run: |
46+
for example in browser-chat browser-echo custom-router dumbpipe-web \
47+
framed-messages frosty iroh-automerge iroh-automerge-repo iroh-gateway \
48+
extism/host extism/plugin extism/iroh-extism-host-functions; do
49+
if [ -f "$example/Cargo.toml" ]; then
50+
echo "Fetching dependencies for $example"
51+
cargo fetch --manifest-path "$example/Cargo.toml" --locked 2>/dev/null || cargo fetch --manifest-path "$example/Cargo.toml"
52+
fi
53+
done
54+
55+
# Check formatting for all examples in a single job (fast)
56+
fmt:
57+
name: Format check
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 10
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
with:
64+
submodules: recursive
65+
66+
- name: Install Rust toolchain
67+
uses: dtolnay/rust-toolchain@stable
68+
with:
69+
components: rustfmt
70+
71+
- name: Check formatting
72+
run: |
73+
for example in browser-chat browser-echo custom-router dumbpipe-web \
74+
framed-messages frosty iroh-automerge iroh-automerge-repo iroh-gateway \
75+
extism/host extism/plugin extism/iroh-extism-host-functions; do
76+
if [ -f "$example/Cargo.toml" ]; then
77+
echo "Checking format: $example"
78+
cargo fmt --manifest-path "$example/Cargo.toml" --all -- --check
79+
fi
80+
done
81+
82+
# Build WASM examples
83+
wasm:
84+
name: WASM build
85+
runs-on: ubuntu-latest
86+
timeout-minutes: 20
87+
needs: prepare
88+
steps:
89+
- name: Checkout
90+
uses: actions/checkout@v4
91+
with:
92+
submodules: recursive
93+
94+
- name: Install Rust toolchain
95+
uses: dtolnay/rust-toolchain@stable
96+
97+
- name: Add wasm target
98+
run: rustup target add wasm32-unknown-unknown
99+
100+
- name: Setup Rust cache
101+
uses: Swatinem/rust-cache@v2
102+
with:
103+
shared-key: "iroh-examples-shared"
104+
105+
- name: Build WASM examples
106+
run: |
107+
for example in browser-echo; do
108+
echo "Building WASM: $example"
109+
cd "$example"
110+
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown --all-features
111+
cd ..
112+
done
113+
env:
114+
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
115+
116+
# Parallel testing matrix for all examples
117+
test:
118+
name: Test ${{ matrix.example }}
119+
runs-on: ubuntu-latest
120+
timeout-minutes: 20
121+
needs: prepare
25122
strategy:
26123
fail-fast: false
27124
matrix:
28-
name: [ubuntu-latest]
29-
rust: [stable]
30-
include:
31-
- name: ubuntu-latest
32-
os: ubuntu-latest
33-
release-os: linux
34-
release-arch: amd64
35-
runner: [self-hosted, linux, X64]
36-
env:
37-
SCCACHE_GHA_ENABLED: "true"
38-
RUSTC_WRAPPER: "sccache"
125+
example:
126+
- browser-chat
127+
- browser-echo
128+
- custom-router
129+
- dumbpipe-web
130+
- framed-messages
131+
- frosty
132+
- iroh-automerge
133+
- iroh-automerge-repo
134+
- iroh-gateway
135+
- extism/host
136+
- extism/plugin
137+
- extism/iroh-extism-host-functions
39138
steps:
40-
- name: Checkout
41-
uses: actions/checkout@v4
42-
with:
43-
submodules: recursive
44-
45-
- name: Install ${{ matrix.rust }}
46-
uses: dtolnay/rust-toolchain@master
47-
with:
48-
toolchain: ${{ matrix.rust }}
49-
components: clippy,rustfmt
50-
51-
- name: Add wasm target
52-
run: rustup target add wasm32-unknown-unknown
53-
54-
- name: Run sccache-cache
55-
uses: mozilla-actions/[email protected]
56-
57-
- name: check
58-
run: |
59-
for i in ${RS_EXAMPLES_LIST//,/ }
60-
do
61-
echo "Checking $i"
62-
cargo check --manifest-path $i/Cargo.toml --all-features
63-
done
64-
env:
65-
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
66-
67-
- name: wasm
68-
run: |
69-
for i in ${WASM_EXAMPLES_LIST//,/ }
70-
do
71-
echo "Checking wasm $i"
72-
cd $i
73-
# the rust flag should get picked up from the `config.toml` file
74-
# but cargo build seems to not be picking it up
75-
# this dependency exists for both `browser-chat` and `browser-echo`
76-
# so I'm adding the flag to the command
77-
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown
78-
cd ..
79-
done
80-
env:
81-
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
82-
83-
- name: fmt
84-
run: |
85-
for i in ${RS_EXAMPLES_LIST//,/ }
86-
do
87-
echo "Checking $i"
88-
cargo fmt --all --manifest-path $i/Cargo.toml -- --check
89-
done
90-
env:
139+
- name: Checkout
140+
uses: actions/checkout@v4
141+
with:
142+
submodules: recursive
143+
144+
- name: Install Rust toolchain
145+
uses: dtolnay/rust-toolchain@stable
146+
with:
147+
components: clippy
148+
149+
- name: Setup Rust cache
150+
uses: Swatinem/rust-cache@v2
151+
with:
152+
shared-key: "iroh-examples-shared"
153+
workspaces: ${{ matrix.example }}
154+
155+
- name: Check
156+
run: |
157+
echo "Checking ${{ matrix.example }}"
158+
cargo check --manifest-path "${{ matrix.example }}/Cargo.toml" --all-features
159+
env:
91160
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
92161

93-
- name: clippy
94-
run: |
95-
for i in ${RS_EXAMPLES_LIST//,/ }
96-
do
97-
echo "Checking $i"
98-
cargo clippy --manifest-path $i/Cargo.toml
99-
done
100-
env:
162+
- name: Clippy
163+
run: |
164+
echo "Running clippy on ${{ matrix.example }}"
165+
cargo clippy --manifest-path "${{ matrix.example }}/Cargo.toml" --all-features
166+
env:
167+
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
168+
169+
- name: Test
170+
run: |
171+
echo "Testing ${{ matrix.example }}"
172+
cargo test --manifest-path "${{ matrix.example }}/Cargo.toml" --all-features
173+
env:
101174
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}

0 commit comments

Comments
 (0)