Skip to content

Commit 60ce4fc

Browse files
authored
chore: validate examples workflow (#268)
1 parent 07ee1d0 commit 60ce4fc

File tree

7 files changed

+135
-4
lines changed

7 files changed

+135
-4
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Validate Examples
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
env:
10+
# When getting Rust dependencies, retry on network error:
11+
CARGO_NET_RETRY: 10
12+
# Use the local .curlrc
13+
CURL_HOME: .
14+
15+
jobs:
16+
validate-examples:
17+
name: Validate Examples on ${{ matrix.os }}
18+
runs-on: ${{ matrix.os }}
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
os: [ubuntu-latest]
24+
25+
steps:
26+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
27+
28+
- name: Setup image (Linux)
29+
if: ${{ contains(matrix.os, 'ubuntu') }}
30+
run: ./.github/scripts/provision-linux-build.sh
31+
32+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
33+
with:
34+
path: |
35+
~/.rustup/
36+
~/.cargo/bin/
37+
~/.cargo/registry/index/
38+
~/.cargo/registry/cache/
39+
~/.cargo/git/db/
40+
target/
41+
key: ${{ matrix.os }}-cargo-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}
42+
43+
- name: Build icp CLI
44+
run: cargo build
45+
46+
- name: Validate examples
47+
run: ./scripts/validate-examples.sh
48+
49+
aggregate:
50+
name: validate-examples:required
51+
if: ${{ always() }}
52+
runs-on: ubuntu-latest
53+
needs: [validate-examples]
54+
steps:
55+
- name: check result
56+
if: ${{ needs.validate-examples.result != 'success' }}
57+
run: exit 1

examples/icp-recipe-registry-official/icp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ canisters:
1717

1818
- name: my-canister-with-version
1919
recipe:
20-
type: "@dfinity/prebuilt@v1.0.5"
20+
type: "@dfinity/prebuilt@v2.0.0"
2121
configuration:
2222
path: ../icp-pre-built/dist/hello_world.wasm
2323
sha256: 17a05e36278cd04c7ae6d3d3226c136267b9df7525a0657521405e22ec96be7a

examples/icp-recipe-remote-url-official/icp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
canisters:
44
- name: my-canister
55
recipe:
6-
type: https://github.com/rikonor/icp-recipes/releases/download/prebuilt-v0.1.2/recipe.hbs
6+
type: https://github.com/dfinity/icp-cli-recipes/releases/download/prebuilt-v2.0.0/recipe.hbs
77
configuration:
88
path: ../icp-pre-built/dist/hello_world.wasm
99
sha256: 17a05e36278cd04c7ae6d3d3226c136267b9df7525a0657521405e22ec96be7a
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Start the HTTP server in the background
6+
python3 -m http.server 8080 &
7+
SERVER_PID=$!
8+
9+
# Give the server a moment to start
10+
sleep 1
11+
12+
# Function to cleanup server on exit
13+
cleanup() {
14+
echo "Stopping HTTP server (PID: $SERVER_PID)"
15+
kill $SERVER_PID 2>/dev/null || true
16+
wait $SERVER_PID 2>/dev/null || true
17+
}
18+
19+
# Ensure cleanup happens on script exit
20+
trap cleanup EXIT
21+
22+
# Run icp project show
23+
icp project show

examples/icp-wasm-metadata-recipe/icp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
canisters:
44
- name: my-canister
55
recipe:
6-
type: prebuilt
6+
type: "@dfinity/prebuilt"
77
configuration:
88
path: ../icp-pre-built/dist/hello_world.wasm
99
sha256: 17a05e36278cd04c7ae6d3d3226c136267b9df7525a0657521405e22ec96be7a

examples/icp-wasm-optimization-recipe/icp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
canisters:
44
- name: my-canister
55
recipe:
6-
type: prebuilt
6+
type: "@dfinity/prebuilt"
77
configuration:
88
path: ../icp-pre-built/dist/hello_world.wasm
99
sha256: 17a05e36278cd04c7ae6d3d3226c136267b9df7525a0657521405e22ec96be7a

scripts/validate-examples.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Script to validate all examples in the examples/ directory
5+
# This script can be run locally or in CI
6+
7+
# Add icp binary to PATH (assumes it's in target/debug)
8+
export PATH="$(pwd)/target/debug:$PATH"
9+
echo "icp version: $(icp --version)"
10+
echo "icp path: $(which icp)"
11+
12+
# Get all example directories
13+
for example_dir in examples/*/; do
14+
# Skip if not a directory
15+
if [ ! -d "$example_dir" ]; then
16+
continue
17+
fi
18+
19+
example_name=$(basename "$example_dir")
20+
echo ""
21+
echo "=========================================="
22+
echo "Validating example: $example_name"
23+
echo "=========================================="
24+
25+
pushd "$example_dir"
26+
27+
# Check if test.sh exists
28+
if [ -f "test.sh" ]; then
29+
echo "Found test.sh, running it..."
30+
if ! bash test.sh; then
31+
echo "❌ test.sh failed in $example_name"
32+
exit 1
33+
fi
34+
echo "✅ test.sh passed for $example_name"
35+
else
36+
# Run icp project show to validate the project
37+
echo "Running: icp project show"
38+
if ! icp project show; then
39+
echo "❌ Failed to validate project in $example_name"
40+
exit 1
41+
fi
42+
echo "✅ Project validation successful for $example_name"
43+
fi
44+
45+
popd
46+
done
47+
48+
echo ""
49+
echo "=========================================="
50+
echo "✅ All examples validated successfully!"
51+
echo "=========================================="

0 commit comments

Comments
 (0)