Skip to content

Commit 7ef8d0c

Browse files
authored
js sdk publish
js sdk publish
2 parents cfffc01 + 8964086 commit 7ef8d0c

5 files changed

Lines changed: 608 additions & 5 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: Build and Publish Node SDK
2+
3+
on:
4+
push:
5+
branches:
6+
- "js-sdk-*"
7+
tags:
8+
- "v*"
9+
workflow_dispatch:
10+
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
jobs:
16+
build:
17+
name: Build and Test Package
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
22+
- uses: actions/checkout@v6
23+
24+
- name: Verify Cargo and package.json versions match
25+
working-directory: sdk/js/actra
26+
run: |
27+
JS_VERSION=$(node -p "require('./package.json').version")
28+
CARGO_VERSION=$(grep '^version' ../../../Cargo.toml | head -n1 | cut -d '"' -f2)
29+
30+
echo "JS version: $JS_VERSION"
31+
echo "Cargo version: $CARGO_VERSION"
32+
33+
test "$JS_VERSION" = "$CARGO_VERSION"
34+
35+
- name: Setup pnpm
36+
uses: pnpm/action-setup@v5
37+
with:
38+
version: 9
39+
40+
- name: Setup Node
41+
uses: actions/setup-node@v6
42+
with:
43+
node-version: 20
44+
45+
- name: Install Rust
46+
uses: dtolnay/rust-toolchain@stable
47+
48+
- name: Cache Rust
49+
uses: Swatinem/rust-cache@v2
50+
51+
- name: Add WASM target
52+
run: rustup target add wasm32-unknown-unknown
53+
54+
- name: Install dependencies
55+
run: pnpm install
56+
working-directory: sdk/js/actra
57+
58+
- name: Build
59+
run: pnpm build
60+
working-directory: sdk/js/actra
61+
62+
- name: Verify WASM exists before packing
63+
working-directory: sdk/js/actra
64+
run: |
65+
test -f dist/actra_wasm.wasm || (echo "WASM missing before pack" && exit 1)
66+
67+
- name: Pack package (simulate publish)
68+
run: pnpm pack
69+
working-directory: sdk/js/actra
70+
71+
- name: Verify WASM included in package
72+
working-directory: sdk/js/actra
73+
run: |
74+
FILE=$(ls *.tgz | head -n 1)
75+
echo "Checking package: $FILE"
76+
tar -tf "$FILE" | grep -q "dist/actra_wasm.wasm" || (echo "Expected WASM not found in dist/" && exit 1)
77+
echo "WASM file found in package"
78+
79+
- name: Test install from tarball
80+
working-directory: sdk/js/actra
81+
run: |
82+
mkdir test-install
83+
cd test-install
84+
npm init -y
85+
npm install ../*.tgz
86+
node -e "require('@getactra/actra')"
87+
88+
- name: Upload package artifact
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: package-tgz
92+
path: sdk/js/actra/*.tgz
93+
94+
publish_test:
95+
name: Publish to npm (beta)
96+
if: ${{ github.event_name == 'workflow_dispatch' }}
97+
needs: build
98+
runs-on: ubuntu-latest
99+
100+
steps:
101+
- uses: actions/checkout@v6
102+
103+
- name: Setup pnpm
104+
uses: pnpm/action-setup@v5
105+
with:
106+
version: 9
107+
108+
- name: Setup Node with npm registry
109+
uses: actions/setup-node@v6
110+
with:
111+
node-version: 20
112+
registry-url: https://registry.npmjs.org/
113+
114+
- name: Download package artifact
115+
uses: actions/download-artifact@v8
116+
with:
117+
name: package-tgz
118+
path: sdk/js/actra
119+
120+
- name: Dry run publish
121+
run: pnpm publish *.tgz --dry-run
122+
working-directory: sdk/js/actra
123+
124+
- name: Publish to npm (beta tag)
125+
run: pnpm publish *.tgz --tag beta --access public --ignore-scripts
126+
working-directory: sdk/js/actra
127+
128+
publish:
129+
name: Publish to npm (production)
130+
if: startsWith(github.ref, 'refs/tags/v')
131+
needs: build
132+
runs-on: ubuntu-latest
133+
134+
steps:
135+
- uses: actions/checkout@v6
136+
137+
- name: Setup pnpm
138+
uses: pnpm/action-setup@v5
139+
with:
140+
version: 9
141+
142+
- name: Setup Node with npm registry
143+
uses: actions/setup-node@v6
144+
with:
145+
node-version: 20
146+
registry-url: https://registry.npmjs.org/
147+
148+
- name: Download package artifact
149+
uses: actions/download-artifact@v8
150+
with:
151+
name: package-tgz
152+
path: sdk/js/actra
153+
154+
- name: Verify tag matches package.json version
155+
working-directory: sdk/js/actra
156+
run: |
157+
TAG=${GITHUB_REF#refs/tags/v}
158+
VERSION=$(node -p "require('./package.json').version")
159+
echo "Tag: $TAG"
160+
echo "Package version: $VERSION"
161+
test "$TAG" = "$VERSION"
162+
163+
- name: Dry run publish
164+
run: pnpm publish *.tgz --dry-run --ignore-scripts
165+
166+
- name: Publish to npm
167+
run: pnpm publish *.tgz --access public --ignore-scripts
168+
working-directory: sdk/js/actra

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
resolver = "2"
1010

1111
[workspace.package]
12-
version = "0.7.3"
12+
version = "0.7.4"
1313
edition = "2021"
1414
license = "Apache-2.0"
1515
authors = ["Amit Saxena"]

scripts/sync-version.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
const ROOT = process.cwd();
5+
6+
const cargoTomlPath = path.resolve(ROOT, "Cargo.toml");
7+
8+
const packages = [
9+
"sdk/js/actra/package.json",
10+
];
11+
12+
const cargoToml = fs.readFileSync(cargoTomlPath, "utf-8");
13+
14+
const match = cargoToml.match(/^version\s*=\s*"(.*)"/m);
15+
if (!match) {
16+
console.error("Could not find version in Cargo.toml");
17+
process.exit(1);
18+
}
19+
20+
const version = match[1];
21+
22+
console.log(`Syncing version: ${version}`);
23+
24+
for (const pkgPath of packages) {
25+
const fullPath = path.resolve(ROOT, pkgPath);
26+
27+
if (!fs.existsSync(fullPath)) {
28+
console.warn(`Skipping missing package: ${pkgPath}`);
29+
continue;
30+
}
31+
32+
const pkg = JSON.parse(fs.readFileSync(fullPath, "utf-8"));
33+
pkg.version = version;
34+
35+
fs.writeFileSync(fullPath, JSON.stringify(pkg, null, 2) + "\n");
36+
37+
console.log(`Updated: ${pkgPath}`);
38+
}
39+
40+
console.log("Version sync complete");

0 commit comments

Comments
 (0)