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