From 4638048df02797737b21d4b3ef3b62297cd51686 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:04:32 -0400 Subject: [PATCH 1/9] test --- .github/workflows/validate-js-functions.yml | 68 +++++++++++++++++++ .github/workflows/validate-rust-functions.yml | 56 +++++++++++++++ .github/workflows/validate-ts-functions.yml | 68 +++++++++++++++++++ ...t-checkout-validation-expected-output.json | 8 +++ .../cart-checkout-validation-test-input.json | 9 +++ 5 files changed, 209 insertions(+) create mode 100644 integration-tests/cart-checkout-validation-expected-output.json create mode 100644 integration-tests/cart-checkout-validation-test-input.json diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index 059bc801..ee9c19cc 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -26,3 +26,71 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test + - name: Build JavaScript functions + run: | + for function_dir in functions-*-js; do + if [ -d "$function_dir" ]; then + echo "Building $function_dir" + cd "$function_dir" + if [ -f "package.json" ]; then + yarn build + fi + cd .. + fi + done + - name: Download function-runner + run: | + curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu + chmod +x function-runner + - name: Run integration tests + run: | + for function_dir in functions-*-js; do + if [ -d "$function_dir" ]; then + echo "Testing $function_dir" + cd "$function_dir" + + # Find the built wasm file + wasm_file=$(find . -name "*.wasm" | head -1) + + if [ -f "$wasm_file" ]; then + # Run function with test input + if [ -f "../integration-tests/cart-checkout-validation-test-input.json" ]; then + echo "Running integration test for $function_dir" + ../function-runner -f "$wasm_file" -i "../integration-tests/cart-checkout-validation-test-input.json" > actual_output.json + + # Validate output against expected result + if jq empty actual_output.json 2>/dev/null; then + echo "Function output:" + cat actual_output.json + + # Compare with expected output if available + if [ -f "../integration-tests/cart-checkout-validation-expected-output.json" ]; then + if jq --argjson actual "$(cat actual_output.json)" --argjson expected "$(cat ../integration-tests/cart-checkout-validation-expected-output.json)" -n '$actual == $expected'; then + echo "✅ $function_dir output matches expected result" + else + echo "❌ $function_dir output doesn't match expected result" + echo "Expected:" + cat ../integration-tests/cart-checkout-validation-expected-output.json + echo "Actual:" + cat actual_output.json + exit 1 + fi + else + echo "✅ $function_dir produced valid JSON output (no expected output to compare)" + fi + else + echo "❌ $function_dir produced invalid JSON output" + cat actual_output.json + exit 1 + fi + else + echo "⚠️ No test input found for $function_dir" + fi + else + echo "❌ No wasm file found for $function_dir" + exit 1 + fi + + cd .. + fi + done diff --git a/.github/workflows/validate-rust-functions.yml b/.github/workflows/validate-rust-functions.yml index b443b4bd..81e9b027 100644 --- a/.github/workflows/validate-rust-functions.yml +++ b/.github/workflows/validate-rust-functions.yml @@ -30,3 +30,59 @@ jobs: run: cargo test - name: Build with wasm32-wasip1 target run: cargo build --release --target wasm32-wasip1 + - name: Download function-runner + run: | + curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu + chmod +x function-runner + - name: Run integration tests + run: | + for function_dir in functions-*-rs; do + if [ -d "$function_dir" ]; then + echo "Testing $function_dir" + cd "$function_dir" + + # Find the built wasm file + wasm_file=$(find target/wasm32-wasip1/release -name "*.wasm" | head -1) + + if [ -f "$wasm_file" ]; then + # Run function with test input + if [ -f "../integration-tests/cart-checkout-validation-test-input.json" ]; then + echo "Running integration test for $function_dir" + ../function-runner -f "$wasm_file" -i "../integration-tests/cart-checkout-validation-test-input.json" > actual_output.json + + # Validate output against expected result + if jq empty actual_output.json 2>/dev/null; then + echo "Function output:" + cat actual_output.json + + # Compare with expected output if available + if [ -f "../integration-tests/cart-checkout-validation-expected-output.json" ]; then + if jq --argjson actual "$(cat actual_output.json)" --argjson expected "$(cat ../integration-tests/cart-checkout-validation-expected-output.json)" -n '$actual == $expected'; then + echo "✅ $function_dir output matches expected result" + else + echo "❌ $function_dir output doesn't match expected result" + echo "Expected:" + cat ../integration-tests/cart-checkout-validation-expected-output.json + echo "Actual:" + cat actual_output.json + exit 1 + fi + else + echo "✅ $function_dir produced valid JSON output (no expected output to compare)" + fi + else + echo "❌ $function_dir produced invalid JSON output" + cat actual_output.json + exit 1 + fi + else + echo "⚠️ No test input found for $function_dir" + fi + else + echo "❌ No wasm file found for $function_dir" + exit 1 + fi + + cd .. + fi + done diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index 8d362b10..2b6bb8b1 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -26,3 +26,71 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test + - name: Build TypeScript functions + run: | + for function_dir in functions-*-js; do + if [ -d "$function_dir" ]; then + echo "Building $function_dir" + cd "$function_dir" + if [ -f "package.json" ]; then + yarn build + fi + cd .. + fi + done + - name: Download function-runner + run: | + curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu + chmod +x function-runner + - name: Run integration tests + run: | + for function_dir in functions-*-js; do + if [ -d "$function_dir" ]; then + echo "Testing $function_dir" + cd "$function_dir" + + # Find the built wasm file + wasm_file=$(find . -name "*.wasm" | head -1) + + if [ -f "$wasm_file" ]; then + # Run function with test input + if [ -f "../integration-tests/cart-checkout-validation-test-input.json" ]; then + echo "Running integration test for $function_dir" + ../function-runner -f "$wasm_file" -i "../integration-tests/cart-checkout-validation-test-input.json" > actual_output.json + + # Validate output against expected result + if jq empty actual_output.json 2>/dev/null; then + echo "Function output:" + cat actual_output.json + + # Compare with expected output if available + if [ -f "../integration-tests/cart-checkout-validation-expected-output.json" ]; then + if jq --argjson actual "$(cat actual_output.json)" --argjson expected "$(cat ../integration-tests/cart-checkout-validation-expected-output.json)" -n '$actual == $expected'; then + echo "✅ $function_dir output matches expected result" + else + echo "❌ $function_dir output doesn't match expected result" + echo "Expected:" + cat ../integration-tests/cart-checkout-validation-expected-output.json + echo "Actual:" + cat actual_output.json + exit 1 + fi + else + echo "✅ $function_dir produced valid JSON output (no expected output to compare)" + fi + else + echo "❌ $function_dir produced invalid JSON output" + cat actual_output.json + exit 1 + fi + else + echo "⚠️ No test input found for $function_dir" + fi + else + echo "❌ No wasm file found for $function_dir" + exit 1 + fi + + cd .. + fi + done diff --git a/integration-tests/cart-checkout-validation-expected-output.json b/integration-tests/cart-checkout-validation-expected-output.json new file mode 100644 index 00000000..8aa1e06e --- /dev/null +++ b/integration-tests/cart-checkout-validation-expected-output.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "localizedMessage": "Not possible to order more than one of each", + "target": "$.cart" + } + ] +} \ No newline at end of file diff --git a/integration-tests/cart-checkout-validation-test-input.json b/integration-tests/cart-checkout-validation-test-input.json new file mode 100644 index 00000000..98aa1eae --- /dev/null +++ b/integration-tests/cart-checkout-validation-test-input.json @@ -0,0 +1,9 @@ +{ + "cart": { + "lines": [ + { + "quantity": 3 + } + ] + } +} \ No newline at end of file From 54f7e3a1804c35bdf3de8c71712eb23ba0c0332a Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:08:27 -0400 Subject: [PATCH 2/9] Test2 --- .github/workflows/validate-js-functions.yml | 56 +++++-------------- .github/workflows/validate-rust-functions.yml | 44 +++++---------- .github/workflows/validate-ts-functions.yml | 56 +++++-------------- ...t-checkout-validation-expected-output.json | 8 --- .../cart-checkout-validation-test-input.json | 9 --- 5 files changed, 39 insertions(+), 134 deletions(-) delete mode 100644 integration-tests/cart-checkout-validation-expected-output.json delete mode 100644 integration-tests/cart-checkout-validation-test-input.json diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index ee9c19cc..b68ee094 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -26,24 +26,15 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Build JavaScript functions - run: | - for function_dir in functions-*-js; do - if [ -d "$function_dir" ]; then - echo "Building $function_dir" - cd "$function_dir" - if [ -f "package.json" ]; then - yarn build - fi - cd .. - fi - done - name: Download function-runner run: | curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu chmod +x function-runner - name: Run integration tests run: | + # Create empty JSON input + echo '{}' > empty_input.json + for function_dir in functions-*-js; do if [ -d "$function_dir" ]; then echo "Testing $function_dir" @@ -53,38 +44,17 @@ jobs: wasm_file=$(find . -name "*.wasm" | head -1) if [ -f "$wasm_file" ]; then - # Run function with test input - if [ -f "../integration-tests/cart-checkout-validation-test-input.json" ]; then - echo "Running integration test for $function_dir" - ../function-runner -f "$wasm_file" -i "../integration-tests/cart-checkout-validation-test-input.json" > actual_output.json - - # Validate output against expected result - if jq empty actual_output.json 2>/dev/null; then - echo "Function output:" - cat actual_output.json - - # Compare with expected output if available - if [ -f "../integration-tests/cart-checkout-validation-expected-output.json" ]; then - if jq --argjson actual "$(cat actual_output.json)" --argjson expected "$(cat ../integration-tests/cart-checkout-validation-expected-output.json)" -n '$actual == $expected'; then - echo "✅ $function_dir output matches expected result" - else - echo "❌ $function_dir output doesn't match expected result" - echo "Expected:" - cat ../integration-tests/cart-checkout-validation-expected-output.json - echo "Actual:" - cat actual_output.json - exit 1 - fi - else - echo "✅ $function_dir produced valid JSON output (no expected output to compare)" - fi - else - echo "❌ $function_dir produced invalid JSON output" - cat actual_output.json - exit 1 - fi + echo "Running integration test for $function_dir" + ../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json + + # Validate output is valid JSON + if jq empty actual_output.json 2>/dev/null; then + echo "✅ $function_dir produced valid JSON output" + cat actual_output.json else - echo "⚠️ No test input found for $function_dir" + echo "❌ $function_dir produced invalid JSON output" + cat actual_output.json + exit 1 fi else echo "❌ No wasm file found for $function_dir" diff --git a/.github/workflows/validate-rust-functions.yml b/.github/workflows/validate-rust-functions.yml index 81e9b027..bd34a22f 100644 --- a/.github/workflows/validate-rust-functions.yml +++ b/.github/workflows/validate-rust-functions.yml @@ -36,6 +36,9 @@ jobs: chmod +x function-runner - name: Run integration tests run: | + # Create empty JSON input + echo '{}' > empty_input.json + for function_dir in functions-*-rs; do if [ -d "$function_dir" ]; then echo "Testing $function_dir" @@ -45,38 +48,17 @@ jobs: wasm_file=$(find target/wasm32-wasip1/release -name "*.wasm" | head -1) if [ -f "$wasm_file" ]; then - # Run function with test input - if [ -f "../integration-tests/cart-checkout-validation-test-input.json" ]; then - echo "Running integration test for $function_dir" - ../function-runner -f "$wasm_file" -i "../integration-tests/cart-checkout-validation-test-input.json" > actual_output.json - - # Validate output against expected result - if jq empty actual_output.json 2>/dev/null; then - echo "Function output:" - cat actual_output.json - - # Compare with expected output if available - if [ -f "../integration-tests/cart-checkout-validation-expected-output.json" ]; then - if jq --argjson actual "$(cat actual_output.json)" --argjson expected "$(cat ../integration-tests/cart-checkout-validation-expected-output.json)" -n '$actual == $expected'; then - echo "✅ $function_dir output matches expected result" - else - echo "❌ $function_dir output doesn't match expected result" - echo "Expected:" - cat ../integration-tests/cart-checkout-validation-expected-output.json - echo "Actual:" - cat actual_output.json - exit 1 - fi - else - echo "✅ $function_dir produced valid JSON output (no expected output to compare)" - fi - else - echo "❌ $function_dir produced invalid JSON output" - cat actual_output.json - exit 1 - fi + echo "Running integration test for $function_dir" + ../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json + + # Validate output is valid JSON + if jq empty actual_output.json 2>/dev/null; then + echo "✅ $function_dir produced valid JSON output" + cat actual_output.json else - echo "⚠️ No test input found for $function_dir" + echo "❌ $function_dir produced invalid JSON output" + cat actual_output.json + exit 1 fi else echo "❌ No wasm file found for $function_dir" diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index 2b6bb8b1..ec8f59f6 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -26,24 +26,15 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Build TypeScript functions - run: | - for function_dir in functions-*-js; do - if [ -d "$function_dir" ]; then - echo "Building $function_dir" - cd "$function_dir" - if [ -f "package.json" ]; then - yarn build - fi - cd .. - fi - done - name: Download function-runner run: | curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu chmod +x function-runner - name: Run integration tests run: | + # Create empty JSON input + echo '{}' > empty_input.json + for function_dir in functions-*-js; do if [ -d "$function_dir" ]; then echo "Testing $function_dir" @@ -53,38 +44,17 @@ jobs: wasm_file=$(find . -name "*.wasm" | head -1) if [ -f "$wasm_file" ]; then - # Run function with test input - if [ -f "../integration-tests/cart-checkout-validation-test-input.json" ]; then - echo "Running integration test for $function_dir" - ../function-runner -f "$wasm_file" -i "../integration-tests/cart-checkout-validation-test-input.json" > actual_output.json - - # Validate output against expected result - if jq empty actual_output.json 2>/dev/null; then - echo "Function output:" - cat actual_output.json - - # Compare with expected output if available - if [ -f "../integration-tests/cart-checkout-validation-expected-output.json" ]; then - if jq --argjson actual "$(cat actual_output.json)" --argjson expected "$(cat ../integration-tests/cart-checkout-validation-expected-output.json)" -n '$actual == $expected'; then - echo "✅ $function_dir output matches expected result" - else - echo "❌ $function_dir output doesn't match expected result" - echo "Expected:" - cat ../integration-tests/cart-checkout-validation-expected-output.json - echo "Actual:" - cat actual_output.json - exit 1 - fi - else - echo "✅ $function_dir produced valid JSON output (no expected output to compare)" - fi - else - echo "❌ $function_dir produced invalid JSON output" - cat actual_output.json - exit 1 - fi + echo "Running integration test for $function_dir" + ../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json + + # Validate output is valid JSON + if jq empty actual_output.json 2>/dev/null; then + echo "✅ $function_dir produced valid JSON output" + cat actual_output.json else - echo "⚠️ No test input found for $function_dir" + echo "❌ $function_dir produced invalid JSON output" + cat actual_output.json + exit 1 fi else echo "❌ No wasm file found for $function_dir" diff --git a/integration-tests/cart-checkout-validation-expected-output.json b/integration-tests/cart-checkout-validation-expected-output.json deleted file mode 100644 index 8aa1e06e..00000000 --- a/integration-tests/cart-checkout-validation-expected-output.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "errors": [ - { - "localizedMessage": "Not possible to order more than one of each", - "target": "$.cart" - } - ] -} \ No newline at end of file diff --git a/integration-tests/cart-checkout-validation-test-input.json b/integration-tests/cart-checkout-validation-test-input.json deleted file mode 100644 index 98aa1eae..00000000 --- a/integration-tests/cart-checkout-validation-test-input.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "cart": { - "lines": [ - { - "quantity": 3 - } - ] - } -} \ No newline at end of file From f8de062e56cd183551739c95aa1638c1ad2b40e0 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:12:11 -0400 Subject: [PATCH 3/9] rust update, go to correct location of wasm --- .github/workflows/validate-rust-functions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-rust-functions.yml b/.github/workflows/validate-rust-functions.yml index bd34a22f..d5679ae9 100644 --- a/.github/workflows/validate-rust-functions.yml +++ b/.github/workflows/validate-rust-functions.yml @@ -44,8 +44,8 @@ jobs: echo "Testing $function_dir" cd "$function_dir" - # Find the built wasm file - wasm_file=$(find target/wasm32-wasip1/release -name "*.wasm" | head -1) + # Find the built wasm file (look in root target directory) + wasm_file=$(find ../target/wasm32-wasip1/release -name "*.wasm" | head -1) if [ -f "$wasm_file" ]; then echo "Running integration test for $function_dir" From 920beb0dd6666c8aa079ce670fb3fc8f8ac730b4 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:16:50 -0400 Subject: [PATCH 4/9] update function-runner install --- .github/workflows/validate-js-functions.yml | 8 +++++--- .github/workflows/validate-rust-functions.yml | 8 +++++--- .github/workflows/validate-ts-functions.yml | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index b68ee094..5aa94dc2 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -26,10 +26,12 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Download function-runner + - name: Install function-runner run: | - curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu - chmod +x function-runner + # Install from source since binary releases have naming issues + cargo install --git https://github.com/Shopify/function-runner.git --locked + # Move to current directory for easier access + cp ~/.cargo/bin/function-runner . - name: Run integration tests run: | # Create empty JSON input diff --git a/.github/workflows/validate-rust-functions.yml b/.github/workflows/validate-rust-functions.yml index d5679ae9..ce54103c 100644 --- a/.github/workflows/validate-rust-functions.yml +++ b/.github/workflows/validate-rust-functions.yml @@ -30,10 +30,12 @@ jobs: run: cargo test - name: Build with wasm32-wasip1 target run: cargo build --release --target wasm32-wasip1 - - name: Download function-runner + - name: Install function-runner run: | - curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu - chmod +x function-runner + # Install from source since binary releases have naming issues + cargo install --git https://github.com/Shopify/function-runner.git --locked + # Move to current directory for easier access + cp ~/.cargo/bin/function-runner . - name: Run integration tests run: | # Create empty JSON input diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index ec8f59f6..6a70573e 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -26,10 +26,12 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Download function-runner + - name: Install function-runner run: | - curl -L -o function-runner https://github.com/Shopify/function-runner/releases/latest/download/function-runner-x86_64-unknown-linux-gnu - chmod +x function-runner + # Install from source since binary releases have naming issues + cargo install --git https://github.com/Shopify/function-runner.git --locked + # Move to current directory for easier access + cp ~/.cargo/bin/function-runner . - name: Run integration tests run: | # Create empty JSON input From f35997833f64f63a68a1f8707a127f4b12839361 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:19:46 -0400 Subject: [PATCH 5/9] update fr2 --- .github/workflows/validate-js-functions.yml | 2 +- .github/workflows/validate-rust-functions.yml | 2 +- .github/workflows/validate-ts-functions.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index 5aa94dc2..e0cb2dfa 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -29,7 +29,7 @@ jobs: - name: Install function-runner run: | # Install from source since binary releases have naming issues - cargo install --git https://github.com/Shopify/function-runner.git --locked + cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked # Move to current directory for easier access cp ~/.cargo/bin/function-runner . - name: Run integration tests diff --git a/.github/workflows/validate-rust-functions.yml b/.github/workflows/validate-rust-functions.yml index ce54103c..2c35458c 100644 --- a/.github/workflows/validate-rust-functions.yml +++ b/.github/workflows/validate-rust-functions.yml @@ -33,7 +33,7 @@ jobs: - name: Install function-runner run: | # Install from source since binary releases have naming issues - cargo install --git https://github.com/Shopify/function-runner.git --locked + cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked # Move to current directory for easier access cp ~/.cargo/bin/function-runner . - name: Run integration tests diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index 6a70573e..cf0ad30c 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -29,7 +29,7 @@ jobs: - name: Install function-runner run: | # Install from source since binary releases have naming issues - cargo install --git https://github.com/Shopify/function-runner.git --locked + cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked # Move to current directory for easier access cp ~/.cargo/bin/function-runner . - name: Run integration tests From 0aba4e4e140f897f27e7e67f49d62d6d30ccf07b Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:30:56 -0400 Subject: [PATCH 6/9] Ts/js changes --- .github/workflows/validate-js-functions.yml | 12 ++++++++++++ .github/workflows/validate-ts-functions.yml | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index e0cb2dfa..8621854f 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -26,6 +26,18 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test + - name: Build functions to WASM + run: | + for function_dir in functions-*-js; do + if [ -d "$function_dir" ]; then + echo "Building $function_dir" + cd "$function_dir" + if [ -f "package.json" ]; then + npm run build + fi + cd .. + fi + done - name: Install function-runner run: | # Install from source since binary releases have naming issues diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index cf0ad30c..e2dfad6a 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -26,6 +26,18 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test + - name: Build functions to WASM + run: | + for function_dir in functions-*-js; do + if [ -d "$function_dir" ]; then + echo "Building $function_dir" + cd "$function_dir" + if [ -f "package.json" ]; then + npm run build + fi + cd .. + fi + done - name: Install function-runner run: | # Install from source since binary releases have naming issues From 02ac7c247b9e668fb14d4ac0b7e5e5725ba8b117 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:44:06 -0400 Subject: [PATCH 7/9] use javy to compoile js --- .github/workflows/validate-js-functions.yml | 25 +++++++++++++++++---- .github/workflows/validate-ts-functions.yml | 25 +++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index 8621854f..66953ad7 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -26,24 +26,41 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Build functions to WASM + - name: Install Javy (JavaScript to WASM compiler) + run: | + # Install Javy for compiling JavaScript to WebAssembly + curl -L -o javy.tar.gz https://github.com/bytecodealliance/javy/releases/latest/download/javy-x86_64-linux-v2.2.0.tar.gz + tar -xzf javy.tar.gz + chmod +x javy + + - name: Build JavaScript functions to WASM run: | for function_dir in functions-*-js; do if [ -d "$function_dir" ]; then echo "Building $function_dir" cd "$function_dir" - if [ -f "package.json" ]; then - npm run build - fi + + # Bundle the JavaScript code + npx esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=bundled.js + + # Compile to WASM using Javy + ../javy compile bundled.js -o function.wasm + + # Create dist directory and move WASM file + mkdir -p dist + mv function.wasm dist/ + cd .. fi done + - name: Install function-runner run: | # Install from source since binary releases have naming issues cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked # Move to current directory for easier access cp ~/.cargo/bin/function-runner . + - name: Run integration tests run: | # Create empty JSON input diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index e2dfad6a..adfa14ec 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -26,24 +26,41 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Build functions to WASM + - name: Install Javy (JavaScript to WASM compiler) + run: | + # Install Javy for compiling JavaScript to WebAssembly + curl -L -o javy.tar.gz https://github.com/bytecodealliance/javy/releases/latest/download/javy-x86_64-linux-v2.2.0.tar.gz + tar -xzf javy.tar.gz + chmod +x javy + + - name: Build TypeScript functions to WASM run: | for function_dir in functions-*-js; do if [ -d "$function_dir" ]; then echo "Building $function_dir" cd "$function_dir" - if [ -f "package.json" ]; then - npm run build - fi + + # Bundle the TypeScript code + npx esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=bundled.js + + # Compile to WASM using Javy + ../javy compile bundled.js -o function.wasm + + # Create dist directory and move WASM file + mkdir -p dist + mv function.wasm dist/ + cd .. fi done + - name: Install function-runner run: | # Install from source since binary releases have naming issues cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked # Move to current directory for easier access cp ~/.cargo/bin/function-runner . + - name: Run integration tests run: | # Create empty JSON input From 442d06bc868ca9c0b0e1e75a99c178905ca1589e Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 10:47:15 -0400 Subject: [PATCH 8/9] follow function runner pattern --- .github/workflows/validate-js-functions.yml | 8 ++++---- .github/workflows/validate-ts-functions.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index 66953ad7..5c809943 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -28,10 +28,10 @@ jobs: run: yarn js-test - name: Install Javy (JavaScript to WASM compiler) run: | - # Install Javy for compiling JavaScript to WebAssembly - curl -L -o javy.tar.gz https://github.com/bytecodealliance/javy/releases/latest/download/javy-x86_64-linux-v2.2.0.tar.gz - tar -xzf javy.tar.gz - chmod +x javy + # Install javy from source using cargo + cargo install --git https://github.com/bytecodealliance/javy.git --locked javy-cli + # Copy to current directory + cp ~/.cargo/bin/javy-cli ./javy - name: Build JavaScript functions to WASM run: | diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index adfa14ec..d4c1cf08 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -28,10 +28,10 @@ jobs: run: yarn js-test - name: Install Javy (JavaScript to WASM compiler) run: | - # Install Javy for compiling JavaScript to WebAssembly - curl -L -o javy.tar.gz https://github.com/bytecodealliance/javy/releases/latest/download/javy-x86_64-linux-v2.2.0.tar.gz - tar -xzf javy.tar.gz - chmod +x javy + # Install javy from source using cargo + cargo install --git https://github.com/bytecodealliance/javy.git --locked javy-cli + # Copy to current directory + cp ~/.cargo/bin/javy-cli ./javy - name: Build TypeScript functions to WASM run: | From 8838c445f6cd8477a046273a62514480a69afa95 Mon Sep 17 00:00:00 2001 From: Mehdi Salemi Date: Tue, 15 Jul 2025 13:42:14 -0400 Subject: [PATCH 9/9] refactor --- .github/workflows/test-function-runner.yml | 74 +++++++++++++++++++ .github/workflows/validate-js-functions.yml | 69 ----------------- .github/workflows/validate-rust-functions.yml | 43 ++--------- .github/workflows/validate-ts-functions.yml | 69 ----------------- Cargo.toml | 7 ++ 5 files changed, 86 insertions(+), 176 deletions(-) create mode 100644 .github/workflows/test-function-runner.yml diff --git a/.github/workflows/test-function-runner.yml b/.github/workflows/test-function-runner.yml new file mode 100644 index 00000000..63c11235 --- /dev/null +++ b/.github/workflows/test-function-runner.yml @@ -0,0 +1,74 @@ +name: Test Function Runner + +on: + pull_request: + branches: ["main"] + paths: + - "functions-*-rs/**" + - ".github/workflows/test-function-runner.yml" + +env: + CARGO_TERM_COLOR: always + +jobs: + test-function-runner: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Step 1 - Install function-runner + run: | + echo "Installing function-runner..." + cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked + + - name: Step 2 - Test function-runner installation + run: | + echo "Testing function-runner installation..." + function-runner --help + + - name: Step 3 - Show available functions + run: | + echo "Available Rust functions:" + ls -la functions-*-rs/ | head -5 + + - name: Step 4 - Expand liquid templates + run: | + echo "Expanding liquid templates..." + yarn + CI=1 yarn expand-liquid rust + + - name: Step 5 - Build one function + run: | + echo "Building functions-cart-checkout-validation-rs..." + cd functions-cart-checkout-validation-rs + cargo build --target wasm32-wasip1 --profile=wasm --features trampoline + + - name: Step 6 - Post-process with wasm-opt + run: | + echo "Installing wasm-opt..." + cargo install wasm-opt --locked + echo "Optimizing WASM..." + wasm_file=$(find target/wasm32-wasip1/wasm -name "*.wasm" | head -1) + if [ -f "$wasm_file" ]; then + wasm-opt --enable-bulk-memory --strip-debug "$wasm_file" -o "${wasm_file%.wasm}-optimized.wasm" + fi + + - name: Step 7 - Find built WASM file + run: | + echo "Looking for built WASM file..." + find . -name "*.wasm" -type f + echo "Specifically looking in target/wasm32-wasip1/wasm/:" + ls -la target/wasm32-wasip1/wasm/ || echo "wasm directory not found" + + - name: Step 8 - Test with empty input + run: | + echo "Testing with empty input..." + echo '{}' > empty_input.json + wasm_file=$(find . -name "*.wasm" -type f | head -1) + if [ -f "$wasm_file" ]; then + echo "Found WASM file: $wasm_file" + echo "Running function-runner..." + function-runner -f "$wasm_file" -i empty_input.json || echo "Function runner failed, continuing..." + else + echo "No WASM file found" + fi \ No newline at end of file diff --git a/.github/workflows/validate-js-functions.yml b/.github/workflows/validate-js-functions.yml index 5c809943..059bc801 100644 --- a/.github/workflows/validate-js-functions.yml +++ b/.github/workflows/validate-js-functions.yml @@ -26,72 +26,3 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Install Javy (JavaScript to WASM compiler) - run: | - # Install javy from source using cargo - cargo install --git https://github.com/bytecodealliance/javy.git --locked javy-cli - # Copy to current directory - cp ~/.cargo/bin/javy-cli ./javy - - - name: Build JavaScript functions to WASM - run: | - for function_dir in functions-*-js; do - if [ -d "$function_dir" ]; then - echo "Building $function_dir" - cd "$function_dir" - - # Bundle the JavaScript code - npx esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=bundled.js - - # Compile to WASM using Javy - ../javy compile bundled.js -o function.wasm - - # Create dist directory and move WASM file - mkdir -p dist - mv function.wasm dist/ - - cd .. - fi - done - - - name: Install function-runner - run: | - # Install from source since binary releases have naming issues - cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked - # Move to current directory for easier access - cp ~/.cargo/bin/function-runner . - - - name: Run integration tests - run: | - # Create empty JSON input - echo '{}' > empty_input.json - - for function_dir in functions-*-js; do - if [ -d "$function_dir" ]; then - echo "Testing $function_dir" - cd "$function_dir" - - # Find the built wasm file - wasm_file=$(find . -name "*.wasm" | head -1) - - if [ -f "$wasm_file" ]; then - echo "Running integration test for $function_dir" - ../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json - - # Validate output is valid JSON - if jq empty actual_output.json 2>/dev/null; then - echo "✅ $function_dir produced valid JSON output" - cat actual_output.json - else - echo "❌ $function_dir produced invalid JSON output" - cat actual_output.json - exit 1 - fi - else - echo "❌ No wasm file found for $function_dir" - exit 1 - fi - - cd .. - fi - done diff --git a/.github/workflows/validate-rust-functions.yml b/.github/workflows/validate-rust-functions.yml index 2c35458c..8b908d33 100644 --- a/.github/workflows/validate-rust-functions.yml +++ b/.github/workflows/validate-rust-functions.yml @@ -29,44 +29,11 @@ jobs: - name: Run tests run: cargo test - name: Build with wasm32-wasip1 target - run: cargo build --release --target wasm32-wasip1 - - name: Install function-runner run: | - # Install from source since binary releases have naming issues - cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked - # Move to current directory for easier access - cp ~/.cargo/bin/function-runner . - - name: Run integration tests - run: | - # Create empty JSON input - echo '{}' > empty_input.json - - for function_dir in functions-*-rs; do - if [ -d "$function_dir" ]; then - echo "Testing $function_dir" - cd "$function_dir" - - # Find the built wasm file (look in root target directory) - wasm_file=$(find ../target/wasm32-wasip1/release -name "*.wasm" | head -1) - - if [ -f "$wasm_file" ]; then - echo "Running integration test for $function_dir" - ../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json - - # Validate output is valid JSON - if jq empty actual_output.json 2>/dev/null; then - echo "✅ $function_dir produced valid JSON output" - cat actual_output.json - else - echo "❌ $function_dir produced invalid JSON output" - cat actual_output.json - exit 1 - fi - else - echo "❌ No wasm file found for $function_dir" - exit 1 - fi - - cd .. + for dir in functions-*-rs; do + if [ -d "$dir" ]; then + package_name=$(grep "name = " "$dir/Cargo.toml" | cut -d'"' -f2) + echo "Building package: $package_name" + cargo build --release --target wasm32-wasip1 -p "$package_name" fi done diff --git a/.github/workflows/validate-ts-functions.yml b/.github/workflows/validate-ts-functions.yml index d4c1cf08..8d362b10 100644 --- a/.github/workflows/validate-ts-functions.yml +++ b/.github/workflows/validate-ts-functions.yml @@ -26,72 +26,3 @@ jobs: run: yarn js-typegen - name: Test run: yarn js-test - - name: Install Javy (JavaScript to WASM compiler) - run: | - # Install javy from source using cargo - cargo install --git https://github.com/bytecodealliance/javy.git --locked javy-cli - # Copy to current directory - cp ~/.cargo/bin/javy-cli ./javy - - - name: Build TypeScript functions to WASM - run: | - for function_dir in functions-*-js; do - if [ -d "$function_dir" ]; then - echo "Building $function_dir" - cd "$function_dir" - - # Bundle the TypeScript code - npx esbuild src/index.ts --bundle --platform=node --target=es2020 --outfile=bundled.js - - # Compile to WASM using Javy - ../javy compile bundled.js -o function.wasm - - # Create dist directory and move WASM file - mkdir -p dist - mv function.wasm dist/ - - cd .. - fi - done - - - name: Install function-runner - run: | - # Install from source since binary releases have naming issues - cargo install --git https://github.com/Shopify/function-runner.git function-runner --locked - # Move to current directory for easier access - cp ~/.cargo/bin/function-runner . - - - name: Run integration tests - run: | - # Create empty JSON input - echo '{}' > empty_input.json - - for function_dir in functions-*-js; do - if [ -d "$function_dir" ]; then - echo "Testing $function_dir" - cd "$function_dir" - - # Find the built wasm file - wasm_file=$(find . -name "*.wasm" | head -1) - - if [ -f "$wasm_file" ]; then - echo "Running integration test for $function_dir" - ../function-runner -f "$wasm_file" -i "../empty_input.json" > actual_output.json - - # Validate output is valid JSON - if jq empty actual_output.json 2>/dev/null; then - echo "✅ $function_dir produced valid JSON output" - cat actual_output.json - else - echo "❌ $function_dir produced invalid JSON output" - cat actual_output.json - exit 1 - fi - else - echo "❌ No wasm file found for $function_dir" - exit 1 - fi - - cd .. - fi - done diff --git a/Cargo.toml b/Cargo.toml index 41626cb5..b44071b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,3 +2,10 @@ members = [ "functions-*-rs" ] + +[profile.wasm] +inherits = "release" +lto = true +opt-level = 'z' +strip = true +panic = "abort"