Skip to content

Commit 8838c44

Browse files
committed
refactor
1 parent 442d06b commit 8838c44

5 files changed

Lines changed: 86 additions & 176 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Test Function Runner
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
paths:
7+
- "functions-*-rs/**"
8+
- ".github/workflows/test-function-runner.yml"
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
test-function-runner:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Step 1 - Install function-runner
20+
run: |
21+
echo "Installing function-runner..."
22+
cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked
23+
24+
- name: Step 2 - Test function-runner installation
25+
run: |
26+
echo "Testing function-runner installation..."
27+
function-runner --help
28+
29+
- name: Step 3 - Show available functions
30+
run: |
31+
echo "Available Rust functions:"
32+
ls -la functions-*-rs/ | head -5
33+
34+
- name: Step 4 - Expand liquid templates
35+
run: |
36+
echo "Expanding liquid templates..."
37+
yarn
38+
CI=1 yarn expand-liquid rust
39+
40+
- name: Step 5 - Build one function
41+
run: |
42+
echo "Building functions-cart-checkout-validation-rs..."
43+
cd functions-cart-checkout-validation-rs
44+
cargo build --target wasm32-wasip1 --profile=wasm --features trampoline
45+
46+
- name: Step 6 - Post-process with wasm-opt
47+
run: |
48+
echo "Installing wasm-opt..."
49+
cargo install wasm-opt --locked
50+
echo "Optimizing WASM..."
51+
wasm_file=$(find target/wasm32-wasip1/wasm -name "*.wasm" | head -1)
52+
if [ -f "$wasm_file" ]; then
53+
wasm-opt --enable-bulk-memory --strip-debug "$wasm_file" -o "${wasm_file%.wasm}-optimized.wasm"
54+
fi
55+
56+
- name: Step 7 - Find built WASM file
57+
run: |
58+
echo "Looking for built WASM file..."
59+
find . -name "*.wasm" -type f
60+
echo "Specifically looking in target/wasm32-wasip1/wasm/:"
61+
ls -la target/wasm32-wasip1/wasm/ || echo "wasm directory not found"
62+
63+
- name: Step 8 - Test with empty input
64+
run: |
65+
echo "Testing with empty input..."
66+
echo '{}' > empty_input.json
67+
wasm_file=$(find . -name "*.wasm" -type f | head -1)
68+
if [ -f "$wasm_file" ]; then
69+
echo "Found WASM file: $wasm_file"
70+
echo "Running function-runner..."
71+
function-runner -f "$wasm_file" -i empty_input.json || echo "Function runner failed, continuing..."
72+
else
73+
echo "No WASM file found"
74+
fi

.github/workflows/validate-js-functions.yml

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,3 @@ jobs:
2626
run: yarn js-typegen
2727
- name: Test
2828
run: yarn js-test
29-
- name: Install Javy (JavaScript to WASM compiler)
30-
run: |
31-
# Install javy from source using cargo
32-
cargo install --git https://github.com/bytecodealliance/javy.git --locked javy-cli
33-
# Copy to current directory
34-
cp ~/.cargo/bin/javy-cli ./javy
35-
36-
- name: Build JavaScript functions to WASM
37-
run: |
38-
for function_dir in functions-*-js; do
39-
if [ -d "$function_dir" ]; then
40-
echo "Building $function_dir"
41-
cd "$function_dir"
42-
43-
# Bundle the JavaScript code
44-
npx esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=bundled.js
45-
46-
# Compile to WASM using Javy
47-
../javy compile bundled.js -o function.wasm
48-
49-
# Create dist directory and move WASM file
50-
mkdir -p dist
51-
mv function.wasm dist/
52-
53-
cd ..
54-
fi
55-
done
56-
57-
- name: Install function-runner
58-
run: |
59-
# Install from source since binary releases have naming issues
60-
cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked
61-
# Move to current directory for easier access
62-
cp ~/.cargo/bin/function-runner .
63-
64-
- name: Run integration tests
65-
run: |
66-
# Create empty JSON input
67-
echo '{}' > empty_input.json
68-
69-
for function_dir in functions-*-js; do
70-
if [ -d "$function_dir" ]; then
71-
echo "Testing $function_dir"
72-
cd "$function_dir"
73-
74-
# Find the built wasm file
75-
wasm_file=$(find . -name "*.wasm" | head -1)
76-
77-
if [ -f "$wasm_file" ]; then
78-
echo "Running integration test for $function_dir"
79-
../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json
80-
81-
# Validate output is valid JSON
82-
if jq empty actual_output.json 2>/dev/null; then
83-
echo "✅ $function_dir produced valid JSON output"
84-
cat actual_output.json
85-
else
86-
echo "❌ $function_dir produced invalid JSON output"
87-
cat actual_output.json
88-
exit 1
89-
fi
90-
else
91-
echo "❌ No wasm file found for $function_dir"
92-
exit 1
93-
fi
94-
95-
cd ..
96-
fi
97-
done

.github/workflows/validate-rust-functions.yml

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,11 @@ jobs:
2929
- name: Run tests
3030
run: cargo test
3131
- name: Build with wasm32-wasip1 target
32-
run: cargo build --release --target wasm32-wasip1
33-
- name: Install function-runner
3432
run: |
35-
# Install from source since binary releases have naming issues
36-
cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked
37-
# Move to current directory for easier access
38-
cp ~/.cargo/bin/function-runner .
39-
- name: Run integration tests
40-
run: |
41-
# Create empty JSON input
42-
echo '{}' > empty_input.json
43-
44-
for function_dir in functions-*-rs; do
45-
if [ -d "$function_dir" ]; then
46-
echo "Testing $function_dir"
47-
cd "$function_dir"
48-
49-
# Find the built wasm file (look in root target directory)
50-
wasm_file=$(find ../target/wasm32-wasip1/release -name "*.wasm" | head -1)
51-
52-
if [ -f "$wasm_file" ]; then
53-
echo "Running integration test for $function_dir"
54-
../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json
55-
56-
# Validate output is valid JSON
57-
if jq empty actual_output.json 2>/dev/null; then
58-
echo "✅ $function_dir produced valid JSON output"
59-
cat actual_output.json
60-
else
61-
echo "❌ $function_dir produced invalid JSON output"
62-
cat actual_output.json
63-
exit 1
64-
fi
65-
else
66-
echo "❌ No wasm file found for $function_dir"
67-
exit 1
68-
fi
69-
70-
cd ..
33+
for dir in functions-*-rs; do
34+
if [ -d "$dir" ]; then
35+
package_name=$(grep "name = " "$dir/Cargo.toml" | cut -d'"' -f2)
36+
echo "Building package: $package_name"
37+
cargo build --release --target wasm32-wasip1 -p "$package_name"
7138
fi
7239
done

.github/workflows/validate-ts-functions.yml

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26,72 +26,3 @@ jobs:
2626
run: yarn js-typegen
2727
- name: Test
2828
run: yarn js-test
29-
- name: Install Javy (JavaScript to WASM compiler)
30-
run: |
31-
# Install javy from source using cargo
32-
cargo install --git https://github.com/bytecodealliance/javy.git --locked javy-cli
33-
# Copy to current directory
34-
cp ~/.cargo/bin/javy-cli ./javy
35-
36-
- name: Build TypeScript functions to WASM
37-
run: |
38-
for function_dir in functions-*-js; do
39-
if [ -d "$function_dir" ]; then
40-
echo "Building $function_dir"
41-
cd "$function_dir"
42-
43-
# Bundle the TypeScript code
44-
npx esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=bundled.js
45-
46-
# Compile to WASM using Javy
47-
../javy compile bundled.js -o function.wasm
48-
49-
# Create dist directory and move WASM file
50-
mkdir -p dist
51-
mv function.wasm dist/
52-
53-
cd ..
54-
fi
55-
done
56-
57-
- name: Install function-runner
58-
run: |
59-
# Install from source since binary releases have naming issues
60-
cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked
61-
# Move to current directory for easier access
62-
cp ~/.cargo/bin/function-runner .
63-
64-
- name: Run integration tests
65-
run: |
66-
# Create empty JSON input
67-
echo '{}' > empty_input.json
68-
69-
for function_dir in functions-*-js; do
70-
if [ -d "$function_dir" ]; then
71-
echo "Testing $function_dir"
72-
cd "$function_dir"
73-
74-
# Find the built wasm file
75-
wasm_file=$(find . -name "*.wasm" | head -1)
76-
77-
if [ -f "$wasm_file" ]; then
78-
echo "Running integration test for $function_dir"
79-
../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json
80-
81-
# Validate output is valid JSON
82-
if jq empty actual_output.json 2>/dev/null; then
83-
echo "✅ $function_dir produced valid JSON output"
84-
cat actual_output.json
85-
else
86-
echo "❌ $function_dir produced invalid JSON output"
87-
cat actual_output.json
88-
exit 1
89-
fi
90-
else
91-
echo "❌ No wasm file found for $function_dir"
92-
exit 1
93-
fi
94-
95-
cd ..
96-
fi
97-
done

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
members = [
33
"functions-*-rs"
44
]
5+
6+
[profile.wasm]
7+
inherits = "release"
8+
lto = true
9+
opt-level = 'z'
10+
strip = true
11+
panic = "abort"

0 commit comments

Comments
 (0)