Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 190 additions & 0 deletions .github/workflows/build-test-publish-superscript-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
name: Build, Test, and Publish Superscript NPM Package

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: write
packages: write

jobs:
build-test-publish:
runs-on: ubuntu-latest

steps:
# Setup environment
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
override: true

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# Build WASM module
- name: Make build_wasm.sh executable
run: chmod +x build_wasm.sh

- name: Build WASM module
run: |
set -e
./build_wasm.sh
if [ $? -ne 0 ]; then
echo "WASM build failed"
exit 1
fi

# Node.js example tests
- name: Install dependencies for Node example
run: |
set -e
cd wasm/example/node
npm install
npm install ../../target/node

- name: Build TypeScript example
run: |
set -e
cd wasm/example/node
npm run build
if [ ! -f dist/test_node.js ]; then
echo "TypeScript build failed - dist/test_node.js not found"
exit 1
fi

- name: Run JavaScript example
run: |
set -e
cd wasm/example/node
# Run the original JavaScript example
echo "Running JavaScript example (test_node_javascript.js)..."
node test_node_javascript.js
if [ $? -ne 0 ]; then
echo "JavaScript example execution failed"
exit 1
fi
echo "JavaScript example executed successfully"

- name: Run TypeScript compiled example
run: |
set -e
cd wasm/example/node
# Run the compiled TypeScript example
echo "Running compiled TypeScript example (dist/test_node.js)..."
node dist/test_node.js
if [ $? -ne 0 ]; then
echo "TypeScript compiled example execution failed"
exit 1
fi
echo "TypeScript compiled example executed successfully"

# Run Superscript tests
- name: Run Superscript tests
run: |
set -e
cd wasm/example/node
echo "Running Superscript tests..."
npm run test
if [ $? -ne 0 ]; then
echo "Superscript tests failed"
exit 1
fi
echo "Superscript tests completed successfully"

# Browser example test
- name: Install dependencies for Browser example
run: |
set -e
cd wasm/example/browser
npm install
npm install ../../target/browser

- name: Build Browser example
run: |
set -e
cd wasm/example/browser
CI=false npm run build
if [ ! -d build ]; then
echo "Browser example build failed - build directory not found"
exit 1
fi
echo "Browser example built successfully"

# Summarize test results
- name: Summarize test results
run: |
echo "✅ All tests passed successfully!"
echo "✓ WASM module built successfully"
echo "✓ Node.js JavaScript example ran successfully"
echo "✓ Node.js TypeScript example ran successfully"
echo "✓ Superscript tests completed successfully"
echo "✓ Browser example built successfully"

# Version management and publishing
- name: Check for version changes
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: version_check
run: |
cd wasm
# Get the current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"

# Check if this version already exists on npm
if npm view @superwall/superscript@$CURRENT_VERSION version &>/dev/null; then
echo "Version $CURRENT_VERSION already exists on npm. Incrementing patch version."
# Increment patch version
NEW_VERSION=$(node -p "const [major, minor, patch] = '$CURRENT_VERSION'.split('.'); \`\${major}.\${minor}.\${parseInt(patch) + 1}\`")
echo "New version: $NEW_VERSION"

# Update package.json with new version
npm version $NEW_VERSION --no-git-tag-version
echo "version_changed=true" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
else
echo "Version $CURRENT_VERSION does not exist on npm. No need to bump version."
echo "version_changed=false" >> $GITHUB_OUTPUT
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
fi

- name: Prepare for NPM publish
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
cd wasm
# Check if all required files exist
if [ ! -d "./target/node" ] || [ ! -d "./target/browser" ] || [ ! -d "./types" ]; then
echo "Missing required directories for npm publish"
exit 1
fi

- name: Publish to NPM
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
cd wasm
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Commit version change
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.version_check.outputs.version_changed == 'true'
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
git add wasm/package.json
git commit -m "Bump version to ${{ steps.version_check.outputs.new_version }} [skip ci]"
git push
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**/.so
**/.kt
/target
/wasm/dist
# Created by https://www.toptal.com/developers/gitignore/api/intellij,rust
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,rust

Expand Down Expand Up @@ -138,3 +139,7 @@ Cargo.lock
*.pdb

# End of https://www.toptal.com/developers/gitignore/api/intellij,rust
**.SYMDEF

**/*.d.ts
**/dist/**
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.2.0
- Add typescript wrapper for the JS library
- Add aarch64 support for Android

## 0.1.16

- Bumped version for iOS cocoapods fix.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cel-eval"
version = "0.1.18"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.htmlž
Expand Down
3 changes: 2 additions & 1 deletion build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ echo "Copying results to target/android/jniLibs"
target_dir="target/android"
jniLibs_dir="${target_dir}/jniLibs"

mkdir -p "${jniLibs_dir}"/{arm64-v8a,armeabi-v7a,x86_64,x86}
mkdir -p "${jniLibs_dir}"/{arm64-v8a,armeabi-v7a,x86_64,x86,aarch64}

cp target/aarch64-linux-android/release/libcel_eval.so "${jniLibs_dir}/arm64-v8a/libuniffi_cel.so"
cp target/aarch64-linux-android/release/libcel_eval.so "${jniLibs_dir}/aarch64/libuniffi_cel.so"
cp target/armv7-linux-androideabi/release/libcel_eval.so "${jniLibs_dir}/armeabi-v7a/libuniffi_cel.so"
cp target/x86_64-linux-android/release/libcel_eval.so "${jniLibs_dir}/x86_64/libuniffi_cel.so"
cp target/i686-linux-android/release/libcel_eval.so "${jniLibs_dir}/x86/libuniffi_cel.so"
Expand Down
65 changes: 65 additions & 0 deletions check_build_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# Function to print section sizes for a binary
analyze_binary() {
local file=$1
echo "=== Analysis for: $file ==="
echo "Basic file info:"
file "$file"
echo

echo "Overall file size:"
ls -lh "$file"
echo

echo "Architectures:"
if [[ "$file" == *.a ]]; then
# For .a files, we need to check the objects inside
for obj in $(ar t "$file"); do
echo "Object: $obj"
ar x "$file" "$obj" 2>/dev/null
if [ -f "$obj" ]; then
lipo -info "$obj" 2>/dev/null || echo "Not a Mach-O file"
rm "$obj"
fi
done
else
lipo -info "$file"
fi
echo

echo "Section sizes:"
size -m "$file" 2>/dev/null || echo "size command failed"
echo

echo "Symbol count:"
if [[ "$file" == *.a ]]; then
nm "$file" 2>/dev/null | wc -l
else
nm "$file" 2>/dev/null | wc -l
fi
echo

echo "Largest symbols (top 10):"
if [[ "$file" == *.a ]]; then
nm --size-sort "$file" 2>/dev/null | tail -n 10
else
nm --size-sort "$file" 2>/dev/null | tail -n 10
fi
echo "----------------------------------------"
}

# Check if any files were provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <binary_files...>"
exit 1
fi

# Analyze each provided file
for file in "$@"; do
if [ -f "$file" ]; then
analyze_binary "$file"
else
echo "File not found: $file"
fi
done
32 changes: 31 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,37 @@ mod tests {
assert_eq!(res, "{\"Err\":\"No such key: should_display\"}");
}

#[tokio::test]
async fn test_execution_with_null() {
let ctx = Arc::new(TestContext {
map: HashMap::new(),
});
let res = evaluate_with_context(
r#"
{
"variables": {
"map": {
"user": {
"type": "map",
"value": {
"some_value": {
"type": "Null",
"value": null
}
}
}
}
},
"expression": "user.should_display == true && user.some_value > 12"
}

"#
.to_string(),
ctx,
);
println!("{}", res.clone());
assert_eq!(res, "{\"Err\":\"No such key: should_display\"}");
}
#[tokio::test]
async fn test_execution_with_platform_computed_reference() {
let days_since = PassableValue::UInt(7);
Expand Down Expand Up @@ -739,7 +769,7 @@ mod tests {
}
}
},
"expression": "device.minutesSince('app_launch') == device.trial_days",
"expression": "computed.minutesSince('app_launch') == device.trial_days",
"computed": {
"daysSince": [
{
Expand Down
2 changes: 1 addition & 1 deletion wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "superscript"
version = "0.1.19"
version = "0.2.0"
edition = "2021"
publish = false

Expand Down
3 changes: 2 additions & 1 deletion wasm/example/browser/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module.exports = function override(config, env) {
config.experiments = {
...config.experiments,
asyncWebAssembly: true,
syncWebAssembly: true
};

// Resolve WASM files
// Add .wasm to the list of extensions
config.resolve.extensions.push('.wasm');

// Add rule for WASM files
Expand Down
Loading