1 name: Release SDK npm
2
3 on:
4 push:
5 tags:
6 - "[0-9]+.[0-9]+.[0-9]+"
7 workflow_dispatch:
8
9 permissions:
10 contents: read
11
12 jobs:
13 # Cheap ubuntu gate: version agreement, crates.io publishability, tag match.
14 # Blocks the expensive job below so a metadata fault never costs runner time.
15 preflight:
16 uses: ./.github/workflows/release-preflight.yml
17 with:
18 tag: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
19
20 # ── Validate (every run) ──────────────────────────────────────────────────
21 validate:
22 needs: preflight
23 name: Validate
24 runs-on: ubuntu-latest
25
26 outputs:
27 version: ${{ steps.meta.outputs.version }}
28
29 env:
30 GRESIQ_API_KEY_DEV: ${{ secrets.GRESIQ_API_KEY_DEV }}
31 GRESIQ_API_SECRET_DEV: ${{ secrets.GRESIQ_API_SECRET_DEV }}
32 GRESIQ_API_KEY_PRODUCTION: ${{ secrets.GRESIQ_API_KEY_PRODUCTION }}
33 GRESIQ_API_SECRET_PRODUCTION: ${{ secrets.GRESIQ_API_SECRET_PRODUCTION }}
34 HF_TOKEN: ${{ secrets.HF_TOKEN }}
35 steps:
36 - name: Checkout
37 uses: actions/checkout@v6
38
39 - name: Install node
40 uses: actions/setup-node@v4
41 with:
42 node-version: 22
43 registry-url: "https://registry.npmjs.org"
44
45 # ── Read version ───────────────────────────────────────────────────────
46
47 - name: Read version from package.json
48 id: meta
49 working-directory: sdk/react-native
50 run: |
51 VERSION=$(node -p "require('./package.json').version")
52 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
53 echo "npm SDK version: $VERSION"
54
55 # ── Validate tag = package.json version (tag push only) ────────────────
56
57 - name: Validate tag matches package.json version
58 if: startsWith(github.ref, 'refs/tags/')
59 env:
60 PKG_VERSION: ${{ steps.meta.outputs.version }}
61 TAG: ${{ github.ref_name }}
62 run: |
63 if [ "$TAG" != "$PKG_VERSION" ]; then
64 echo "::error::Tag '$TAG' does not match package.json version '$PKG_VERSION'. Update package.json or re-tag."
65 exit 1
66 fi
67 echo "Version check passed: $PKG_VERSION"
68
69 # ── Build & dry-run ────────────────────────────────────────────────────
70
71 - name: Install dependencies
72 working-directory: sdk/react-native
73 run: npm install
74
75 - name: Build TypeScript
76 working-directory: sdk/react-native
77 run: npm run build
78
79 - name: Dry-run package
80 working-directory: sdk/react-native
81 run: npm pack --dry-run
82
83 # ── Publish to npm (tag push only) ────────────────────────────────────────
84 publish:
85 name: Publish to npm
86 needs: validate
87 runs-on: ubuntu-latest
88 if: startsWith(github.ref, 'refs/tags/')
89
90 env:
91 GRESIQ_API_KEY_DEV: ${{ secrets.GRESIQ_API_KEY_DEV }}
92 GRESIQ_API_SECRET_DEV: ${{ secrets.GRESIQ_API_SECRET_DEV }}
93 GRESIQ_API_KEY_PRODUCTION: ${{ secrets.GRESIQ_API_KEY_PRODUCTION }}
94 GRESIQ_API_SECRET_PRODUCTION: ${{ secrets.GRESIQ_API_SECRET_PRODUCTION }}
95 HF_TOKEN: ${{ secrets.HF_TOKEN }}
96 steps:
97 - name: Checkout
98 uses: actions/checkout@v6
99
100 - name: Install node
101 uses: actions/setup-node@v4
102 with:
103 node-version: 22
104 registry-url: "https://registry.npmjs.org"
105
106 - name: Install dependencies
107 working-directory: sdk/react-native
108 run: npm install
109
110 - name: Build TypeScript
111 working-directory: sdk/react-native
112 run: npm run build
113
114 # ── Publish ────────────────────────────────────────────────────────────
115 # NPM_TOKEN must be a repository secret containing an npm access token
116 # with publish permissions for the @ondeinference scope.
117 #
118 # To obtain the token:
119 # 1. Log in to https://www.npmjs.com as a member of the @ondeinference org.
120 # 2. Go to Access Tokens → Generate New Token → Granular Access Token.
121 # 3. Scope it to the @ondeinference org with read+write packages.
122 # 4. Add it as a repository secret named NPM_TOKEN on the onde repo.
123 - name: Publish @ondeinference/react-native to npm
124 working-directory: sdk/react-native
125 env:
126 NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
127 run: |
128 npm_package_name=$(node -p "require('./package.json').name")
129 npm_package_version=$(node -p "require('./package.json').version")
130
131 if npm view "${npm_package_name}@${npm_package_version}" version >/dev/null 2>&1; then
132 echo "${npm_package_name}@${npm_package_version} already exists on npm, skipping publish"
133 exit 0
134 fi
135
136 npm publish --access public