Skip to content

Commit 4c6480b

Browse files
authored
Merge pull request #18 from superwall/develop
0.2.0
2 parents b12debf + 0a0e9df commit 4c6480b

39 files changed

+10133
-4673
lines changed
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
name: Build, Test, and Publish Superscript NPM Package
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
packages: write
13+
14+
jobs:
15+
build-test-publish:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
# Setup environment
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: '18'
27+
registry-url: 'https://registry.npmjs.org'
28+
29+
- name: Setup Rust
30+
uses: actions-rs/toolchain@v1
31+
with:
32+
toolchain: stable
33+
target: wasm32-unknown-unknown
34+
override: true
35+
36+
- name: Install wasm-pack
37+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
38+
39+
# Build WASM module
40+
- name: Make build_wasm.sh executable
41+
run: chmod +x build_wasm.sh
42+
43+
- name: Build WASM module
44+
run: |
45+
set -e
46+
./build_wasm.sh
47+
if [ $? -ne 0 ]; then
48+
echo "WASM build failed"
49+
exit 1
50+
fi
51+
52+
# Node.js example tests
53+
- name: Install dependencies for Node example
54+
run: |
55+
set -e
56+
cd wasm/example/node
57+
npm install
58+
npm install ../../target/node
59+
60+
- name: Build TypeScript example
61+
run: |
62+
set -e
63+
cd wasm/example/node
64+
npm run build
65+
if [ ! -f dist/test_node.js ]; then
66+
echo "TypeScript build failed - dist/test_node.js not found"
67+
exit 1
68+
fi
69+
70+
- name: Run JavaScript example
71+
run: |
72+
set -e
73+
cd wasm/example/node
74+
# Run the original JavaScript example
75+
echo "Running JavaScript example (test_node_javascript.js)..."
76+
node test_node_javascript.js
77+
if [ $? -ne 0 ]; then
78+
echo "JavaScript example execution failed"
79+
exit 1
80+
fi
81+
echo "JavaScript example executed successfully"
82+
83+
- name: Run TypeScript compiled example
84+
run: |
85+
set -e
86+
cd wasm/example/node
87+
# Run the compiled TypeScript example
88+
echo "Running compiled TypeScript example (dist/test_node.js)..."
89+
node dist/test_node.js
90+
if [ $? -ne 0 ]; then
91+
echo "TypeScript compiled example execution failed"
92+
exit 1
93+
fi
94+
echo "TypeScript compiled example executed successfully"
95+
96+
# Run Superscript tests
97+
- name: Run Superscript tests
98+
run: |
99+
set -e
100+
cd wasm/example/node
101+
echo "Running Superscript tests..."
102+
npm run test
103+
if [ $? -ne 0 ]; then
104+
echo "Superscript tests failed"
105+
exit 1
106+
fi
107+
echo "Superscript tests completed successfully"
108+
109+
# Browser example test
110+
- name: Install dependencies for Browser example
111+
run: |
112+
set -e
113+
cd wasm/example/browser
114+
npm install
115+
npm install ../../target/browser
116+
117+
- name: Build Browser example
118+
run: |
119+
set -e
120+
cd wasm/example/browser
121+
CI=false npm run build
122+
if [ ! -d build ]; then
123+
echo "Browser example build failed - build directory not found"
124+
exit 1
125+
fi
126+
echo "Browser example built successfully"
127+
128+
# Summarize test results
129+
- name: Summarize test results
130+
run: |
131+
echo "✅ All tests passed successfully!"
132+
echo "✓ WASM module built successfully"
133+
echo "✓ Node.js JavaScript example ran successfully"
134+
echo "✓ Node.js TypeScript example ran successfully"
135+
echo "✓ Superscript tests completed successfully"
136+
echo "✓ Browser example built successfully"
137+
138+
# Version management and publishing
139+
- name: Check for version changes
140+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
141+
id: version_check
142+
run: |
143+
cd wasm
144+
# Get the current version from package.json
145+
CURRENT_VERSION=$(node -p "require('./package.json').version")
146+
echo "Current version: $CURRENT_VERSION"
147+
148+
# Check if this version already exists on npm
149+
if npm view @superwall/superscript@$CURRENT_VERSION version &>/dev/null; then
150+
echo "Version $CURRENT_VERSION already exists on npm. Incrementing patch version."
151+
# Increment patch version
152+
NEW_VERSION=$(node -p "const [major, minor, patch] = '$CURRENT_VERSION'.split('.'); \`\${major}.\${minor}.\${parseInt(patch) + 1}\`")
153+
echo "New version: $NEW_VERSION"
154+
155+
# Update package.json with new version
156+
npm version $NEW_VERSION --no-git-tag-version
157+
echo "version_changed=true" >> $GITHUB_OUTPUT
158+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
159+
else
160+
echo "Version $CURRENT_VERSION does not exist on npm. No need to bump version."
161+
echo "version_changed=false" >> $GITHUB_OUTPUT
162+
echo "new_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
163+
fi
164+
165+
- name: Prepare for NPM publish
166+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
167+
run: |
168+
cd wasm
169+
# Check if all required files exist
170+
if [ ! -d "./target/node" ] || [ ! -d "./target/browser" ] || [ ! -d "./types" ]; then
171+
echo "Missing required directories for npm publish"
172+
exit 1
173+
fi
174+
175+
- name: Publish to NPM
176+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
177+
run: |
178+
cd wasm
179+
npm publish --access public
180+
env:
181+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
182+
183+
- name: Commit version change
184+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.version_check.outputs.version_changed == 'true'
185+
run: |
186+
git config --global user.name 'GitHub Actions'
187+
git config --global user.email '[email protected]'
188+
git add wasm/package.json
189+
git commit -m "Bump version to ${{ steps.version_check.outputs.new_version }} [skip ci]"
190+
git push

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
**/.so
66
**/.kt
77
/target
8+
/wasm/dist
89
# Created by https://www.toptal.com/developers/gitignore/api/intellij,rust
910
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,rust
1011

@@ -138,3 +139,7 @@ Cargo.lock
138139
*.pdb
139140

140141
# End of https://www.toptal.com/developers/gitignore/api/intellij,rust
142+
**.SYMDEF
143+
144+
**/*.d.ts
145+
**/dist/**

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 0.2.0
4+
- Add typescript wrapper for the JS library
5+
- Add aarch64 support for Android
6+
37
## 0.1.16
48

59
- Bumped version for iOS cocoapods fix.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cel-eval"
3-
version = "0.1.18"
3+
version = "0.2.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.htmlž

build_android.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ echo "Copying results to target/android/jniLibs"
2525
target_dir="target/android"
2626
jniLibs_dir="${target_dir}/jniLibs"
2727

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

3030
cp target/aarch64-linux-android/release/libcel_eval.so "${jniLibs_dir}/arm64-v8a/libuniffi_cel.so"
31+
cp target/aarch64-linux-android/release/libcel_eval.so "${jniLibs_dir}/aarch64/libuniffi_cel.so"
3132
cp target/armv7-linux-androideabi/release/libcel_eval.so "${jniLibs_dir}/armeabi-v7a/libuniffi_cel.so"
3233
cp target/x86_64-linux-android/release/libcel_eval.so "${jniLibs_dir}/x86_64/libuniffi_cel.so"
3334
cp target/i686-linux-android/release/libcel_eval.so "${jniLibs_dir}/x86/libuniffi_cel.so"

check_build_size.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
3+
# Function to print section sizes for a binary
4+
analyze_binary() {
5+
local file=$1
6+
echo "=== Analysis for: $file ==="
7+
echo "Basic file info:"
8+
file "$file"
9+
echo
10+
11+
echo "Overall file size:"
12+
ls -lh "$file"
13+
echo
14+
15+
echo "Architectures:"
16+
if [[ "$file" == *.a ]]; then
17+
# For .a files, we need to check the objects inside
18+
for obj in $(ar t "$file"); do
19+
echo "Object: $obj"
20+
ar x "$file" "$obj" 2>/dev/null
21+
if [ -f "$obj" ]; then
22+
lipo -info "$obj" 2>/dev/null || echo "Not a Mach-O file"
23+
rm "$obj"
24+
fi
25+
done
26+
else
27+
lipo -info "$file"
28+
fi
29+
echo
30+
31+
echo "Section sizes:"
32+
size -m "$file" 2>/dev/null || echo "size command failed"
33+
echo
34+
35+
echo "Symbol count:"
36+
if [[ "$file" == *.a ]]; then
37+
nm "$file" 2>/dev/null | wc -l
38+
else
39+
nm "$file" 2>/dev/null | wc -l
40+
fi
41+
echo
42+
43+
echo "Largest symbols (top 10):"
44+
if [[ "$file" == *.a ]]; then
45+
nm --size-sort "$file" 2>/dev/null | tail -n 10
46+
else
47+
nm --size-sort "$file" 2>/dev/null | tail -n 10
48+
fi
49+
echo "----------------------------------------"
50+
}
51+
52+
# Check if any files were provided
53+
if [ $# -eq 0 ]; then
54+
echo "Usage: $0 <binary_files...>"
55+
exit 1
56+
fi
57+
58+
# Analyze each provided file
59+
for file in "$@"; do
60+
if [ -f "$file" ]; then
61+
analyze_binary "$file"
62+
else
63+
echo "File not found: $file"
64+
fi
65+
done

src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,37 @@ mod tests {
636636
assert_eq!(res, "{\"Err\":\"No such key: should_display\"}");
637637
}
638638

639+
#[tokio::test]
640+
async fn test_execution_with_null() {
641+
let ctx = Arc::new(TestContext {
642+
map: HashMap::new(),
643+
});
644+
let res = evaluate_with_context(
645+
r#"
646+
{
647+
"variables": {
648+
"map": {
649+
"user": {
650+
"type": "map",
651+
"value": {
652+
"some_value": {
653+
"type": "Null",
654+
"value": null
655+
}
656+
}
657+
}
658+
}
659+
},
660+
"expression": "user.should_display == true && user.some_value > 12"
661+
}
639662
663+
"#
664+
.to_string(),
665+
ctx,
666+
);
667+
println!("{}", res.clone());
668+
assert_eq!(res, "{\"Err\":\"No such key: should_display\"}");
669+
}
640670
#[tokio::test]
641671
async fn test_execution_with_platform_computed_reference() {
642672
let days_since = PassableValue::UInt(7);
@@ -739,7 +769,7 @@ mod tests {
739769
}
740770
}
741771
},
742-
"expression": "device.minutesSince('app_launch') == device.trial_days",
772+
"expression": "computed.minutesSince('app_launch') == device.trial_days",
743773
"computed": {
744774
"daysSince": [
745775
{

0 commit comments

Comments
 (0)