Skip to content

Commit 0841360

Browse files
Web3NLclaude
andcommitted
chore: speed up CI with caching, batch wasm builds, and dedup tests
- Add GitHub Actions caching for Rust target/, cargo registry, and PocketIC binary (shared-build.yml) - Batch-build all Rust canister wasm targets in a single cargo invocation instead of per-canister icp deploy (build-all-wasm.sh) - Use icp canister create + install --wasm with prebuilt wasms instead of icp deploy for Rust canisters (validate-and-test-all.sh) - Remove duplicate Rust tests: cargo test --workspace already runs in rust-lint-format.sh, so remove individual cargo test -p from run-test.sh - Remove redundant cargo check from rust-lint-format.sh (clippy is a superset) - Add --skip-build flag to setup-dashboard-dev-env.sh for CI use Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d2ef2a commit 0841360

6 files changed

Lines changed: 101 additions & 30 deletions

File tree

.github/workflows/shared-build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@ jobs:
2121
node-version: '22'
2222
cache: 'npm'
2323

24+
- name: Install Rust toolchain
25+
uses: dtolnay/rust-toolchain@master
26+
with:
27+
toolchain: '1.88.0'
28+
targets: wasm32-unknown-unknown
29+
components: rustfmt, clippy
30+
31+
- name: Cache Rust artifacts
32+
uses: actions/cache@v4
33+
with:
34+
path: |
35+
~/.cargo/registry/index/
36+
~/.cargo/registry/cache/
37+
~/.cargo/git/db/
38+
target/
39+
key: rust-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('Cargo.lock') }}
40+
restore-keys: |
41+
rust-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml') }}-
42+
43+
- name: Cache PocketIC binary
44+
uses: actions/cache@v4
45+
with:
46+
path: ~/.local/share/icp-cli/pkg/
47+
key: pocket-ic-${{ runner.os }}-v1
48+
2449
- name: Install icp-cli
2550
run: npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm
2651

scripts/build-all-wasm.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Batch-build all Rust canister wasm targets in a single cargo invocation,
5+
# then shrink and compress each for deployment.
6+
#
7+
# Prerequisites: all frontend assets that get embedded in Rust canisters
8+
# must be built before running this script.
9+
10+
echo "Building all Rust canister wasms..."
11+
cargo build --target wasm32-unknown-unknown --release \
12+
-p wasm-registry \
13+
-p my-hello-world \
14+
-p my-notepad
15+
16+
WASM_DIR="target/wasm32-unknown-unknown/release/deps"
17+
OUT_DIR="wasm"
18+
mkdir -p "$OUT_DIR"
19+
20+
# Process each wasm: cargo output name (underscore) → output name (hyphenated)
21+
shrink_and_compress() {
22+
local cargo_name="$1"
23+
local output_name="$2"
24+
echo "Shrinking and compressing ${output_name}..."
25+
local tmpdir
26+
tmpdir=$(mktemp -d)
27+
ic-wasm "${WASM_DIR}/${cargo_name}.wasm" -o "${tmpdir}/${output_name}.wasm" shrink
28+
gzip -9 "${tmpdir}/${output_name}.wasm"
29+
cp "${tmpdir}/${output_name}.wasm.gz" "${OUT_DIR}/${output_name}.wasm.gz"
30+
rm -rf "$tmpdir"
31+
}
32+
33+
shrink_and_compress "wasm_registry" "wasm-registry"
34+
shrink_and_compress "my_hello_world" "my-hello-world"
35+
shrink_and_compress "my_notepad" "my-notepad"
36+
37+
echo "All wasms built and compressed in ${OUT_DIR}/"

scripts/run-test.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ npm run test --workspace=canister-dashboard-frontend
1313
echo "Unit testing my-canister-app"
1414
npm run test --workspace=my-canister-app
1515

16-
echo "Unit testing my-canister-dashboard (Rust)"
17-
cargo test -p my-canister-dashboard
18-
19-
echo "Unit testing my-canister-frontend (Rust)"
20-
cargo test -p my-canister-frontend
21-
2216
echo "Acceptance testing my-hello-world"
2317
cargo run -p canister-dapp-test -- wasm/my-hello-world.wasm.gz
2418

scripts/rust-lint-format.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ set -euo pipefail
44
# Main workspace
55
cargo fmt
66
cargo clippy --all-targets --all-features -- -D warnings
7-
cargo check --all-targets --all-features
87
cargo test --workspace --exclude canister-dapp-test

scripts/setup-dashboard-dev-env.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ source "$(dirname "$0")/constants.sh"
77
# Ensure we're in the project root directory
88
cd "$REPO_ROOT"
99

10+
SKIP_BUILD=""
11+
for arg in "$@"; do
12+
case $arg in
13+
--skip-build) SKIP_BUILD="true" ;;
14+
esac
15+
done
16+
1017
echo "Setting up dashboard development environment..."
1118

12-
echo "Deploying $HELLO_WORLD_CANISTER canister..."
13-
./scripts/prebuild-mcd.sh
14-
# Build hello-world frontend with test env vars (identity provider URL)
15-
# before the Rust canister embeds it via include_dir!
16-
npm run build --workspace=my-hello-world-frontend
17-
icp deploy "$HELLO_WORLD_CANISTER" -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
18-
./scripts/copy-example-wasm.sh
19+
if [ "$SKIP_BUILD" != "true" ]; then
20+
echo "Deploying $HELLO_WORLD_CANISTER canister..."
21+
./scripts/prebuild-mcd.sh
22+
# Build hello-world frontend with test env vars (identity provider URL)
23+
# before the Rust canister embeds it via include_dir!
24+
npm run build --workspace=my-hello-world-frontend
25+
icp deploy "$HELLO_WORLD_CANISTER" -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
26+
./scripts/copy-example-wasm.sh
27+
fi
1928

2029
# Update test.env with the hello-world canister ID
2130
HELLO_WORLD_ID=$(icp canister status my-hello-world -e local --id-only)
@@ -50,4 +59,4 @@ icp canister settings update "$HELLO_WORLD_CANISTER" -e local --identity ident-1
5059
echo "Setting authorized Internet Identity principal (Vite origin for first e2e batch)..."
5160
icp canister call "$HELLO_WORLD_CANISTER" manage_ii_principal "(variant { Set = principal \"$PRINCIPAL_VITE\" })" -e local --identity ident-1
5261

53-
echo "Dashboard development environment setup complete"
62+
echo "Dashboard development environment setup complete"

validate-and-test-all.sh

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ for arg in "$@"; do
2222
--clean) CLEAN_FLAG="true" ;;
2323
--skip-checks) SKIP_CHECKS_FLAG="true" ;;
2424
--skip-bootstrap) SKIP_BOOTSTRAP_FLAG="true" ;;
25-
2625
--skip-e2e) SKIP_E2E_FLAG="true" ;;
2726
esac
2827
done
@@ -66,11 +65,28 @@ set -a
6665
source tests/test.env
6766
set +a
6867

69-
echo "Setting up dashboard dev environment..."
70-
./scripts/setup-dashboard-dev-env.sh
68+
# --- Phase 1: Build all frontend assets for Rust canister embedding ---
69+
echo "Building frontend assets..."
70+
./scripts/prebuild-mcd.sh
71+
npm run build --workspace=my-hello-world-frontend
72+
npm run build --workspace=my-notepad-frontend
73+
74+
# --- Phase 2: Batch-build all Rust canister wasms ---
75+
echo "Batch-building all canister wasms..."
76+
./scripts/build-all-wasm.sh
7177

78+
# --- Phase 3: Deploy canisters using prebuilt wasms ---
7279
echo "Deploying wasm-registry canister..."
73-
icp deploy wasm-registry -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
80+
icp canister create wasm-registry -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
81+
icp canister install wasm-registry --wasm wasm/wasm-registry.wasm.gz -e local --identity ident-1
82+
83+
echo "Deploying my-hello-world canister..."
84+
icp canister create my-hello-world -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
85+
icp canister install my-hello-world --wasm wasm/my-hello-world.wasm.gz -e local --identity ident-1
86+
87+
# --- Phase 4: Dashboard setup (II principals, controllers) ---
88+
echo "Setting up dashboard dev environment..."
89+
./scripts/setup-dashboard-dev-env.sh --skip-build
7490

7591
echo "Uploading my-hello-world WASM to registry..."
7692
./scripts/upload-wasm-to-registry.sh \
@@ -81,17 +97,8 @@ echo "Uploading my-hello-world WASM to registry..."
8197
-e local --identity ident-1
8298

8399
echo "Deploying my-notepad canister..."
84-
npm run build --workspace=my-notepad-frontend
85-
icp deploy my-notepad -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
86-
87-
echo "Copying my-notepad WASM to registry..."
88-
NOTEPAD_WASM="target/wasm32-unknown-unknown/release/deps/my_notepad.wasm"
89-
NOTEPAD_TMPDIR=$(mktemp -d)
90-
ic-wasm "$NOTEPAD_WASM" -o "$NOTEPAD_TMPDIR/my-notepad.wasm" shrink
91-
gzip -9 "$NOTEPAD_TMPDIR/my-notepad.wasm"
92-
mkdir -p wasm
93-
cp "$NOTEPAD_TMPDIR/my-notepad.wasm.gz" wasm/my-notepad.wasm.gz
94-
rm -rf "$NOTEPAD_TMPDIR"
100+
icp canister create my-notepad -e local --identity ident-1 --cycles "$CANISTER_INITIAL_CYCLES"
101+
icp canister install my-notepad --wasm wasm/my-notepad.wasm.gz -e local --identity ident-1
95102

96103
echo "Uploading my-notepad WASM to registry..."
97104
./scripts/upload-wasm-to-registry.sh \

0 commit comments

Comments
 (0)