development
yml 219 lines 6.72 KB
Raw
1 name: NPM Release
2
3 # Dispatched by release-crates.yml once the crate publish succeeds.
4 on:
5 workflow_dispatch:
6 inputs:
7 tag:
8 description: "Release tag (e.g. v0.4.0)"
9 required: true
10
11 permissions:
12 id-token: write
13 contents: read
14
15 env:
16 CARGO_TERM_COLOR: always
17 ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
18 ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
19 GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
20 GRESIQ_API_SECRET: ${{ secrets.GRESIQ_API_SECRET }}
21 HF_TOKEN: ${{ secrets.HF_TOKEN }}
22
23 jobs:
24 publish-npm-binaries:
25 name: Publish NPM platform packages
26 runs-on: ${{ matrix.build.OS }}
27 strategy:
28 fail-fast: false
29 matrix:
30 build:
31 - {
32 NAME: linux-x64-glibc,
33 OS: ubuntu-latest,
34 TARGET: x86_64-unknown-linux-gnu,
35 }
36 - {
37 NAME: linux-arm64-glibc,
38 OS: ubuntu-24.04-arm,
39 TARGET: aarch64-unknown-linux-gnu,
40 }
41 - {
42 NAME: win32-x64-msvc,
43 OS: windows-2022,
44 TARGET: x86_64-pc-windows-msvc,
45 }
46 - {
47 NAME: win32-arm64-msvc,
48 OS: windows-2022,
49 TARGET: aarch64-pc-windows-msvc,
50 }
51 - {
52 NAME: darwin-x64,
53 OS: macos-26-intel,
54 TARGET: x86_64-apple-darwin,
55 }
56 - { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin }
57
58 steps:
59 - name: Checkout
60 uses: actions/checkout@v6
61 with:
62 ref: ${{ github.event.inputs.tag || github.ref }}
63
64 - name: Set the release version
65 shell: bash
66 run: |
67 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
68 release_version="${GITHUB_REF_NAME#v}"
69 else
70 release_version="${{ github.event.inputs.tag }}"
71 release_version="${release_version#v}"
72 fi
73 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
74
75 - name: Read Rust toolchain
76 shell: bash
77 run: |
78 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
79 if [ -z "$rust_toolchain" ]; then
80 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
81 exit 1
82 fi
83 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
84
85 - name: Install Rust toolchain
86 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
87 with:
88 toolchain: ${{ env.RUST_TOOLCHAIN }}
89
90 - name: Install Rust target
91 shell: bash
92 run: |
93 rustup target add ${{ matrix.build.TARGET }} --toolchain ${{ env.RUST_TOOLCHAIN }}
94 rustup target list --installed
95
96 - name: Setup Rust cache
97 uses: Swatinem/rust-cache@v2
98 with:
99 key: npm-${{ matrix.build.TARGET }}
100
101 - name: Build binary
102 shell: bash
103 run: cargo build --locked --release --target ${{ matrix.build.TARGET }}
104
105 - name: Install Node
106 uses: actions/setup-node@v6
107 with:
108 node-version-file: .nvmrc
109 registry-url: "https://registry.npmjs.org"
110
111 - name: Publish platform package to NPM
112 env:
113 NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
114 shell: bash
115 run: |
116 cd npm
117
118 # Binary name from Cargo.toml
119 cargo_bin="onde"
120
121 # Prefix used for optional dependency package names
122 node_pkg_prefix="cli"
123
124 # Derive OS and architecture from the build matrix name
125 # Matrix name format: <os>-<arch>[-<extra>]
126 node_os=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f1)
127 export node_os
128 node_arch=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f2)
129 export node_arch
130
131 # Set the version
132 export node_version="${{ env.RELEASE_VERSION }}"
133
134 # Build the platform package name; normalise win32 → windows
135 if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
136 export node_pkg="${node_pkg_prefix}-windows-${node_arch}"
137 else
138 export node_pkg="${node_pkg_prefix}-${node_os}-${node_arch}"
139 fi
140
141 # Create the package directory
142 mkdir -p "${node_pkg}/bin"
143
144 # Generate package.json + README for this platform slice
145 node ./scripts/render-platform-package.cjs \
146 "${node_pkg}" \
147 "${node_version}" \
148 "${node_os}" \
149 "${node_arch}"
150
151 # Windows binaries carry a .exe extension
152 if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
153 cargo_bin="${cargo_bin}.exe"
154 fi
155
156 cp "../target/${{ matrix.build.TARGET }}/release/${cargo_bin}" "${node_pkg}/bin"
157
158 cd "${node_pkg}"
159
160 npm_package_name="@ondeinference/${node_pkg}"
161 if npm view "${npm_package_name}@${node_version}" version >/dev/null 2>&1; then
162 echo "${npm_package_name}@${node_version} already exists on npm, skipping publish"
163 exit 0
164 fi
165
166 npm publish --access public --provenance
167
168 publish-npm-base:
169 name: Publish base NPM package (@ondeinference/cli)
170 needs: publish-npm-binaries
171 runs-on: ubuntu-latest
172
173 steps:
174 - name: Checkout
175 uses: actions/checkout@v6
176 with:
177 ref: ${{ github.event.inputs.tag || github.ref }}
178
179 - name: Set the release version
180 shell: bash
181 run: |
182 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
183 release_version="${GITHUB_REF_NAME#v}"
184 else
185 release_version="${{ github.event.inputs.tag }}"
186 release_version="${release_version#v}"
187 fi
188 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
189
190 - name: Install Node
191 uses: actions/setup-node@v6
192 with:
193 node-version-file: .nvmrc
194 registry-url: "https://registry.npmjs.org"
195
196 - name: Publish base package to NPM
197 env:
198 NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
199 shell: bash
200 run: |
201 cd npm/onde-cli
202
203 # Rewrite package.json with the correct release version and
204 # matching optionalDependency versions
205 node ../scripts/render-main-package.cjs \
206 "./package.json" \
207 "${{ env.RELEASE_VERSION }}"
208
209 npm_package_name="@ondeinference/cli"
210 npm_package_version="${{ env.RELEASE_VERSION }}"
211
212 if npm view "${npm_package_name}@${npm_package_version}" version >/dev/null 2>&1; then
213 echo "${npm_package_name}@${npm_package_version} already exists on npm, skipping publish"
214 exit 0
215 fi
216
217 npm install
218 npm run build
219 npm publish --access public --provenance