|
| 1 | +name: Node |
| 2 | +env: |
| 3 | + DEBUG: napi:* |
| 4 | + APP_NAME: node |
| 5 | + MACOSX_DEPLOYMENT_TARGET: "10.13" |
| 6 | + CARGO_INCREMENTAL: "1" |
| 7 | +"on": |
| 8 | + workflow_dispatch: |
| 9 | + pull_request: |
| 10 | + paths: |
| 11 | + - "crates/node/**" |
| 12 | + - "crates/lib/**" |
| 13 | + - "**/mise.toml" |
| 14 | + - "mise.toml" |
| 15 | + - "examples/**" |
| 16 | + push: |
| 17 | + branches: |
| 18 | + - main |
| 19 | + tags: |
| 20 | + - "node**" |
| 21 | +concurrency: |
| 22 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + settings: |
| 30 | + - host: macos-latest |
| 31 | + target: x86_64-apple-darwin |
| 32 | + build: mise run //crates/node:build:node --target x86_64-apple-darwin |
| 33 | + - host: windows-latest |
| 34 | + build: mise run //crates/node:build:node --target x86_64-pc-windows-msvc |
| 35 | + target: x86_64-pc-windows-msvc |
| 36 | + - host: windows-latest |
| 37 | + build: mise run //crates/node:build:node --target i686-pc-windows-msvc |
| 38 | + target: i686-pc-windows-msvc |
| 39 | + - host: ubuntu-latest |
| 40 | + target: x86_64-unknown-linux-gnu |
| 41 | + build: mise run //crates/node:build:node --target x86_64-unknown-linux-gnu --use-napi-cross |
| 42 | + - host: ubuntu-latest |
| 43 | + target: x86_64-unknown-linux-musl |
| 44 | + build: mise run //crates/node:build:node --target x86_64-unknown-linux-musl -x |
| 45 | + - host: macos-latest |
| 46 | + target: aarch64-apple-darwin |
| 47 | + build: mise run //crates/node:build:node --target aarch64-apple-darwin |
| 48 | + - host: ubuntu-latest |
| 49 | + target: aarch64-unknown-linux-gnu |
| 50 | + build: mise run //crates/node:build:node --target aarch64-unknown-linux-gnu --use-napi-cross |
| 51 | + - host: ubuntu-latest |
| 52 | + target: armv7-unknown-linux-gnueabihf |
| 53 | + build: mise run //crates/node:build:node --target armv7-unknown-linux-gnueabihf --use-napi-cross |
| 54 | + - host: ubuntu-latest |
| 55 | + target: aarch64-linux-android |
| 56 | + build: mise run //crates/node:build:node --target aarch64-linux-android |
| 57 | + - host: ubuntu-latest |
| 58 | + target: armv7-linux-androideabi |
| 59 | + build: mise run //crates/node:build:node --target armv7-linux-androideabi |
| 60 | + - host: ubuntu-latest |
| 61 | + target: aarch64-unknown-linux-musl |
| 62 | + build: mise run //crates/node:build:node --target aarch64-unknown-linux-musl -x |
| 63 | + - host: windows-latest |
| 64 | + target: aarch64-pc-windows-msvc |
| 65 | + build: mise run //crates/node:build:node --target aarch64-pc-windows-msvc |
| 66 | + - host: ubuntu-latest |
| 67 | + target: wasm32-wasip1-threads |
| 68 | + setup: | |
| 69 | + wget -q https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz |
| 70 | + tar -xf wasi-sdk-22.0-linux.tar.gz |
| 71 | + build: | |
| 72 | + export WASI_SDK_PATH="${GITHUB_WORKSPACE}/wasi-sdk-22.0" |
| 73 | + export CC="${WASI_SDK_PATH}/bin/clang" |
| 74 | + export AR="${WASI_SDK_PATH}/bin/llvm-ar" |
| 75 | + export CMAKE_BUILD_PARALLEL_LEVEL=2 |
| 76 | + mise run //crates/node:build:wasm |
| 77 | + name: stable - ${{ matrix.settings.target }} - node@24 |
| 78 | + runs-on: ${{ matrix.settings.host }} |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v6 |
| 81 | + - name: Setup mise |
| 82 | + uses: jdx/mise-action@v4 |
| 83 | + with: |
| 84 | + install: true |
| 85 | + cache: true |
| 86 | + working_directory: crates/node |
| 87 | + - name: Add Rust target |
| 88 | + run: rustup target add ${{ matrix.settings.target }} |
| 89 | + - name: Cache cargo |
| 90 | + uses: actions/cache@v5 |
| 91 | + with: |
| 92 | + path: | |
| 93 | + ~/.cargo/registry/index/ |
| 94 | + ~/.cargo/registry/cache/ |
| 95 | + ~/.cargo/git/db/ |
| 96 | + .napi-rs |
| 97 | + .cargo-cache |
| 98 | + target/ |
| 99 | + key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} |
| 100 | + - uses: mlugg/setup-zig@v2 |
| 101 | + if: ${{ contains(matrix.settings.target, 'musl') }} |
| 102 | + with: |
| 103 | + version: 0.14.1 |
| 104 | + - name: Install cargo-zigbuild |
| 105 | + uses: taiki-e/install-action@v2 |
| 106 | + if: ${{ contains(matrix.settings.target, 'musl') }} |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ github.token }} |
| 109 | + with: |
| 110 | + tool: cargo-zigbuild |
| 111 | + - name: Setup toolchain |
| 112 | + run: ${{ matrix.settings.setup }} |
| 113 | + if: ${{ matrix.settings.setup }} |
| 114 | + shell: bash |
| 115 | + - name: Build |
| 116 | + env: |
| 117 | + CFLAGS_aarch64_unknown_linux_gnu: ${{ matrix.settings.target == 'aarch64-unknown-linux-gnu' && '-D__ARM_ARCH=8' || '' }} |
| 118 | + run: ${{ matrix.settings.build }} |
| 119 | + shell: bash |
| 120 | + - name: Upload artifact |
| 121 | + uses: actions/upload-artifact@v7 |
| 122 | + with: |
| 123 | + name: bindings-${{ matrix.settings.target }} |
| 124 | + path: | |
| 125 | + ./crates/node/${{ env.APP_NAME }}.*.node |
| 126 | + ./crates/node/${{ env.APP_NAME }}.*.wasm |
| 127 | + if-no-files-found: error |
| 128 | + build-freebsd: |
| 129 | + runs-on: ubuntu-latest |
| 130 | + name: Build FreeBSD |
| 131 | + steps: |
| 132 | + - uses: actions/checkout@v6 |
| 133 | + - name: Build |
| 134 | + id: build |
| 135 | + uses: cross-platform-actions/action@v0.32.0 |
| 136 | + env: |
| 137 | + DEBUG: napi:* |
| 138 | + RUSTUP_IO_THREADS: 1 |
| 139 | + with: |
| 140 | + operating_system: freebsd |
| 141 | + version: "15.0" |
| 142 | + memory: 8G |
| 143 | + cpu_count: 3 |
| 144 | + environment_variables: DEBUG RUSTUP_IO_THREADS |
| 145 | + shell: bash |
| 146 | + run: | |
| 147 | + sudo pkg install -y -f curl node libnghttp2 npm cmake |
| 148 | + sudo npm install -g yarn --ignore-scripts |
| 149 | + curl https://sh.rustup.rs -sSf --output rustup.sh |
| 150 | + sh rustup.sh -y --profile minimal --default-toolchain stable |
| 151 | + source "$HOME/.cargo/env" |
| 152 | + echo "~~~~ rustc --version ~~~~" |
| 153 | + rustc --version |
| 154 | + echo "~~~~ node -v ~~~~" |
| 155 | + node -v |
| 156 | + echo "~~~~ yarn --version ~~~~" |
| 157 | + yarn --version |
| 158 | + pwd |
| 159 | + ls -lah |
| 160 | + whoami |
| 161 | + env |
| 162 | + freebsd-version |
| 163 | + sudo corepack enable |
| 164 | + cd crates/node |
| 165 | + yarn install |
| 166 | + yarn build:node |
| 167 | + rm -rf node_modules |
| 168 | + rm -rf target |
| 169 | + rm -rf .yarn/cache |
| 170 | + - name: Upload artifact |
| 171 | + uses: actions/upload-artifact@v7 |
| 172 | + with: |
| 173 | + name: bindings-freebsd |
| 174 | + path: ./crates/node/${{ env.APP_NAME }}.*.node |
| 175 | + if-no-files-found: error |
| 176 | + test-macOS-windows-binding: |
| 177 | + name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }} |
| 178 | + needs: |
| 179 | + - build |
| 180 | + strategy: |
| 181 | + fail-fast: false |
| 182 | + matrix: |
| 183 | + settings: |
| 184 | + - host: windows-latest |
| 185 | + target: x86_64-pc-windows-msvc |
| 186 | + architecture: x64 |
| 187 | + - host: windows-11-arm |
| 188 | + target: aarch64-pc-windows-msvc |
| 189 | + architecture: arm64 |
| 190 | + - host: macos-latest |
| 191 | + target: aarch64-apple-darwin |
| 192 | + architecture: arm64 |
| 193 | + - host: macos-latest |
| 194 | + target: x86_64-apple-darwin |
| 195 | + architecture: x64 |
| 196 | + node: |
| 197 | + - "20" |
| 198 | + - "22" |
| 199 | + runs-on: ${{ matrix.settings.host }} |
| 200 | + steps: |
| 201 | + - uses: actions/checkout@v6 |
| 202 | + - name: Setup mise |
| 203 | + uses: jdx/mise-action@v4 |
| 204 | + with: |
| 205 | + install: true |
| 206 | + cache: true |
| 207 | + working_directory: crates/node |
| 208 | + env: |
| 209 | + MISE_NODE_VERSION: ${{ matrix.node }} |
| 210 | + - name: Download artifacts |
| 211 | + uses: actions/download-artifact@v8 |
| 212 | + with: |
| 213 | + name: bindings-${{ matrix.settings.target }} |
| 214 | + path: ./crates/node |
| 215 | + - name: List packages |
| 216 | + run: ls -R . |
| 217 | + shell: bash |
| 218 | + - name: Test bindings |
| 219 | + run: mise run //crates/node:test |
| 220 | + test-linux-binding: |
| 221 | + name: Test ${{ matrix.target }} - node@${{ matrix.node }} |
| 222 | + needs: |
| 223 | + - build |
| 224 | + strategy: |
| 225 | + fail-fast: false |
| 226 | + matrix: |
| 227 | + target: |
| 228 | + - x86_64-unknown-linux-gnu |
| 229 | + - x86_64-unknown-linux-musl |
| 230 | + - aarch64-unknown-linux-gnu |
| 231 | + - aarch64-unknown-linux-musl |
| 232 | + - armv7-unknown-linux-gnueabihf |
| 233 | + node: |
| 234 | + - "20" |
| 235 | + - "22" |
| 236 | + runs-on: ${{ contains(matrix.target, 'aarch64') && 'ubuntu-24.04-arm' || 'ubuntu-latest' }} |
| 237 | + steps: |
| 238 | + - uses: actions/checkout@v6 |
| 239 | + - name: Setup mise |
| 240 | + uses: jdx/mise-action@v4 |
| 241 | + with: |
| 242 | + install: true |
| 243 | + cache: true |
| 244 | + env: |
| 245 | + MISE_NODE_VERSION: ${{ matrix.node }} |
| 246 | + - name: Output docker params |
| 247 | + id: docker |
| 248 | + run: | |
| 249 | + node -e " |
| 250 | + if ('${{ matrix.target }}'.startsWith('aarch64')) { |
| 251 | + console.log('PLATFORM=linux/arm64') |
| 252 | + } else if ('${{ matrix.target }}'.startsWith('armv7')) { |
| 253 | + console.log('PLATFORM=linux/arm/v7') |
| 254 | + } else { |
| 255 | + console.log('PLATFORM=linux/amd64') |
| 256 | + } |
| 257 | + " >> $GITHUB_OUTPUT |
| 258 | + node -e " |
| 259 | + if ('${{ matrix.target }}'.endsWith('-musl')) { |
| 260 | + console.log('IMAGE=node:${{ matrix.node }}-alpine') |
| 261 | + } else { |
| 262 | + console.log('IMAGE=node:${{ matrix.node }}-slim') |
| 263 | + } |
| 264 | + " >> $GITHUB_OUTPUT |
| 265 | + - name: Configure yarn architectures |
| 266 | + working-directory: crates/node |
| 267 | + run: | |
| 268 | + mise x -- yarn config set --json supportedArchitectures.cpu '["current", "arm64", "x64", "arm"]' |
| 269 | + mise x -- yarn config set --json supportedArchitectures.libc '["current", "musl", "gnu"]' |
| 270 | + - name: Download artifacts |
| 271 | + uses: actions/download-artifact@v8 |
| 272 | + with: |
| 273 | + name: bindings-${{ matrix.target }} |
| 274 | + path: ./crates/node |
| 275 | + - name: List packages |
| 276 | + run: ls -R . |
| 277 | + shell: bash |
| 278 | + - name: Set up QEMU |
| 279 | + uses: docker/setup-qemu-action@v4 |
| 280 | + if: ${{ contains(matrix.target, 'armv7') }} |
| 281 | + with: |
| 282 | + platforms: all |
| 283 | + - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes |
| 284 | + if: ${{ contains(matrix.target, 'armv7') }} |
| 285 | + - name: Test bindings |
| 286 | + uses: tj-actions/docker-run@v2 |
| 287 | + with: |
| 288 | + image: ${{ steps.docker.outputs.IMAGE }} |
| 289 | + name: test-bindings-${{ matrix.target }} |
| 290 | + options: -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }}/crates/node --platform ${{ steps.docker.outputs.PLATFORM }} |
| 291 | + args: sh -c "mise x -- corepack enable && mise x -- yarn test" |
| 292 | + test-wasi: |
| 293 | + name: Test WASI target |
| 294 | + needs: |
| 295 | + - build |
| 296 | + runs-on: ubuntu-latest |
| 297 | + steps: |
| 298 | + - uses: actions/checkout@v6 |
| 299 | + - name: Setup mise |
| 300 | + uses: jdx/mise-action@v4 |
| 301 | + with: |
| 302 | + install: true |
| 303 | + cache: true |
| 304 | + - name: Configure yarn for wasm32 |
| 305 | + working-directory: crates/node |
| 306 | + run: mise x -- yarn config set supportedArchitectures.cpu "wasm32" |
| 307 | + - name: Download artifacts |
| 308 | + uses: actions/download-artifact@v8 |
| 309 | + with: |
| 310 | + name: bindings-wasm32-wasip1-threads |
| 311 | + path: ./crates/node |
| 312 | + - name: List packages |
| 313 | + run: ls -R . |
| 314 | + shell: bash |
| 315 | + - name: Test bindings |
| 316 | + run: mise run //crates/node:test |
| 317 | + env: |
| 318 | + NAPI_RS_FORCE_WASI: 1 |
| 319 | + publish: |
| 320 | + name: Publish |
| 321 | + runs-on: ubuntu-latest |
| 322 | + permissions: |
| 323 | + contents: write |
| 324 | + id-token: write |
| 325 | + needs: |
| 326 | + - build-freebsd |
| 327 | + - test-macOS-windows-binding |
| 328 | + - test-linux-binding |
| 329 | + - test-wasi |
| 330 | + steps: |
| 331 | + - uses: actions/checkout@v6 |
| 332 | + - name: Setup mise |
| 333 | + uses: jdx/mise-action@v4 |
| 334 | + with: |
| 335 | + install: true |
| 336 | + cache: true |
| 337 | + - name: create npm dirs |
| 338 | + run: mise run //crates/node:create-dirs |
| 339 | + - name: Download all artifacts |
| 340 | + uses: actions/download-artifact@v8 |
| 341 | + with: |
| 342 | + path: ./crates/node/artifacts |
| 343 | + - name: Move artifacts |
| 344 | + run: mise run //crates/node:artifacts |
| 345 | + - name: List packages |
| 346 | + run: ls -R ./crates/node/npm |
| 347 | + shell: bash |
| 348 | + - name: Publish |
| 349 | + if: ${{ github.event_name != 'workflow_dispatch' }} |
| 350 | + working-directory: crates/node |
| 351 | + run: | |
| 352 | + npm config set provenance true |
| 353 | + if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; |
| 354 | + then |
| 355 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 356 | + npm publish --access public |
| 357 | + elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+"; |
| 358 | + then |
| 359 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 360 | + npm publish --tag next --access public |
| 361 | + else |
| 362 | + echo "Not a release, skipping publish" |
| 363 | + fi |
| 364 | + env: |
| 365 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 366 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 367 | + - name: Publish |
| 368 | + shell: bash |
| 369 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 370 | + working-directory: crates/node |
| 371 | + run: | |
| 372 | + npm config set provenance true |
| 373 | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc |
| 374 | + npm publish --no-git-checks --access public |
| 375 | + env: |
| 376 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 377 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments