Skip to content

Commit da4f759

Browse files
authored
feat(ci): parallelize jobs (#141)
* feat(ci): parallelize jobs * fix wasm * centralize lists * fix browser-chat wasm build * uhh * fix * fix
1 parent d511afe commit da4f759

File tree

3 files changed

+162
-77
lines changed

3 files changed

+162
-77
lines changed

.github/workflows/ci.yml

Lines changed: 160 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,173 @@ 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"
16+
# NOTE: When adding a new example, add it here AND to the test matrix below (because we cannot create matrix entries dynamically)
17+
RS_EXAMPLES_LIST: "browser-chat browser-chat/cli browser-echo custom-router dumbpipe-web framed-messages frosty iroh-automerge iroh-automerge-repo iroh-gateway extism/host extism/plugin extism/iroh-extism-host-functions"
18+
WASM_EXAMPLES_LIST: "browser-chat browser-echo"
1819
IROH_FORCE_STAGING_RELAYS: "1"
1920

2021
jobs:
21-
build_and_test_nix:
22-
timeout-minutes: 30
23-
name: Build and test (Nix)
24-
runs-on: ${{ matrix.runner }}
22+
# Prepare dependencies and cache them for all other jobs
23+
prepare:
24+
name: Prepare dependencies
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 20
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
submodules: recursive
32+
33+
- name: Install Rust toolchain
34+
uses: dtolnay/rust-toolchain@stable
35+
with:
36+
components: clippy,rustfmt
37+
38+
- name: Add wasm target
39+
run: rustup target add wasm32-unknown-unknown
40+
41+
- name: Setup Rust cache
42+
uses: Swatinem/rust-cache@v2
43+
with:
44+
shared-key: "iroh-examples-shared"
45+
cache-all-crates: true
46+
47+
- name: Fetch dependencies
48+
run: |
49+
for example in $RS_EXAMPLES_LIST; do
50+
if [ -f "$example/Cargo.toml" ]; then
51+
echo "Fetching dependencies for $example"
52+
cargo fetch --manifest-path "$example/Cargo.toml" --locked 2>/dev/null || cargo fetch --manifest-path "$example/Cargo.toml"
53+
fi
54+
done
55+
56+
# Check formatting for all examples in a single job (fast)
57+
fmt:
58+
name: Format check
59+
runs-on: ubuntu-latest
60+
timeout-minutes: 10
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v4
64+
with:
65+
submodules: recursive
66+
67+
- name: Install Rust toolchain
68+
uses: dtolnay/rust-toolchain@stable
69+
with:
70+
components: rustfmt
71+
72+
- name: Check formatting
73+
run: |
74+
for example in $RS_EXAMPLES_LIST; do
75+
if [ -f "$example/Cargo.toml" ]; then
76+
echo "Checking format: $example"
77+
cargo fmt --manifest-path "$example/Cargo.toml" --all -- --check
78+
fi
79+
done
80+
81+
# Build WASM examples
82+
wasm:
83+
name: WASM build
84+
runs-on: ubuntu-latest
85+
timeout-minutes: 20
86+
needs: prepare
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v4
90+
with:
91+
submodules: recursive
92+
93+
- name: Install Rust toolchain
94+
uses: dtolnay/rust-toolchain@stable
95+
96+
- name: Add wasm target
97+
run: rustup target add wasm32-unknown-unknown
98+
99+
- name: Setup Rust cache
100+
uses: Swatinem/rust-cache@v2
101+
with:
102+
shared-key: "iroh-examples-shared"
103+
104+
- name: Build WASM examples
105+
run: |
106+
for example in $WASM_EXAMPLES_LIST; do
107+
echo "Building WASM for $example"
108+
cd "$example"
109+
case "$example" in
110+
browser-echo)
111+
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown --lib
112+
;;
113+
browser-chat)
114+
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown -p chat-browser
115+
;;
116+
*)
117+
echo "Unknown WASM example: $example"
118+
exit 1
119+
;;
120+
esac
121+
cd ..
122+
done
123+
env:
124+
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
125+
126+
# Parallel testing matrix for all examples
127+
test:
128+
name: Test ${{ matrix.example }}
129+
runs-on: ubuntu-latest
130+
timeout-minutes: 20
131+
needs: prepare
25132
strategy:
26133
fail-fast: false
27134
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"
135+
example:
136+
- browser-chat
137+
- browser-chat/cli
138+
- browser-echo
139+
- custom-router
140+
- dumbpipe-web
141+
- framed-messages
142+
- frosty
143+
- iroh-automerge
144+
- iroh-automerge-repo
145+
- iroh-gateway
146+
- extism/host
147+
- extism/plugin
148+
- extism/iroh-extism-host-functions
39149
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:
150+
- name: Checkout
151+
uses: actions/checkout@v4
152+
with:
153+
submodules: recursive
154+
155+
- name: Install Rust toolchain
156+
uses: dtolnay/rust-toolchain@stable
157+
with:
158+
components: clippy
159+
160+
- name: Setup Rust cache
161+
uses: Swatinem/rust-cache@v2
162+
with:
163+
shared-key: "iroh-examples-shared"
164+
workspaces: ${{ matrix.example }}
165+
166+
- name: Check
167+
run: |
168+
echo "Checking ${{ matrix.example }}"
169+
cargo check --manifest-path "${{ matrix.example }}/Cargo.toml" --all-features
170+
env:
91171
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
92172

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:
173+
- name: Clippy
174+
run: |
175+
echo "Running clippy on ${{ matrix.example }}"
176+
cargo clippy --manifest-path "${{ matrix.example }}/Cargo.toml" --all-features
177+
env:
178+
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}
179+
180+
- name: Test
181+
run: |
182+
echo "Testing ${{ matrix.example }}"
183+
cargo test --manifest-path "${{ matrix.example }}/Cargo.toml" --all-features
184+
env:
101185
RUST_LOG: ${{ runner.debug && 'DEBUG' || 'INFO'}}

browser-chat/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
resolver = "2"
33
members = ["shared", "cli", "browser-wasm"]
4+
default-members = ["shared", "browser-wasm"]
45

56
[workspace.dependencies]
67
# we define iroh dependencies here to make upgrading easier.

browser-chat/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ iroh = { workspace = true, default-features = false }
1010
n0-future = "0.3"
1111
rand = "0.9.2"
1212
chat-shared = { version = "0.1.0", path = "../shared" }
13-
tokio = { version = "1.43.0", features = ["rt", "macros"] }
1413
tracing-subscriber = "0.3.19"
1514
data-encoding = "2.9"
15+
tokio = { version = "1.43.0", features = ["rt-multi-thread", "macros", "io-std"] }

0 commit comments

Comments
 (0)