|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + run-tests: |
| 7 | + description: 'Whether to run tests after build' |
| 8 | + required: false |
| 9 | + type: boolean |
| 10 | + default: true |
| 11 | + |
| 12 | +env: |
| 13 | + DEBUG: napi:* |
| 14 | + APP_NAME: python-node |
| 15 | + MACOSX_DEPLOYMENT_TARGET: '10.13' |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-wasm: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + sparse-checkout: | |
| 24 | + fix-python-soname |
| 25 | + fix-python-soname.js |
| 26 | + sparse-checkout-cone-mode: false |
| 27 | + - name: Install Rust toolchain |
| 28 | + uses: dtolnay/rust-toolchain@stable |
| 29 | + with: |
| 30 | + targets: wasm32-wasip1 |
| 31 | + - name: Cache cargo |
| 32 | + uses: actions/cache@v4 |
| 33 | + with: |
| 34 | + path: | |
| 35 | + ~/.cargo/registry/index/ |
| 36 | + ~/.cargo/registry/cache/ |
| 37 | + ~/.cargo/git/db/ |
| 38 | + .cargo-cache |
| 39 | + target/ |
| 40 | + key: wasm-cargo-cache-${{ hashFiles('**/Cargo.lock') }} |
| 41 | + - name: Build WASM |
| 42 | + working-directory: fix-python-soname |
| 43 | + run: | |
| 44 | + cargo build --target wasm32-wasip1 --release |
| 45 | + cp target/wasm32-wasip1/release/fix-python-soname.wasm ../fix-python-soname.wasm |
| 46 | + - name: Upload WASM artifacts |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: wasm-bindings |
| 50 | + path: | |
| 51 | + fix-python-soname.wasm |
| 52 | + fix-python-soname.js |
| 53 | +
|
| 54 | + build: |
| 55 | + needs: build-wasm |
| 56 | + strategy: |
| 57 | + fail-fast: false |
| 58 | + matrix: |
| 59 | + settings: |
| 60 | + - host: macos-latest |
| 61 | + target: aarch64-apple-darwin |
| 62 | + npm_dir: darwin-arm64 |
| 63 | + build: pnpm run build --target aarch64-apple-darwin |
| 64 | + - host: ubuntu-latest |
| 65 | + target: x86_64-unknown-linux-gnu |
| 66 | + npm_dir: linux-x64-gnu |
| 67 | + docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian |
| 68 | + build: pnpm run build --target x86_64-unknown-linux-gnu |
| 69 | + name: stable - ${{ matrix.settings.target }} - node@20 |
| 70 | + runs-on: ${{ matrix.settings.host }} |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + - name: Download WASM artifact |
| 74 | + uses: actions/download-artifact@v4 |
| 75 | + with: |
| 76 | + name: wasm-bindings |
| 77 | + path: npm/${{ matrix.settings.npm_dir }} |
| 78 | + - uses: pnpm/action-setup@v4 |
| 79 | + with: |
| 80 | + version: latest |
| 81 | + - uses: actions/setup-node@v4 |
| 82 | + if: ${{ !matrix.settings.docker }} |
| 83 | + with: |
| 84 | + node-version: 24 |
| 85 | + - uses: dtolnay/rust-toolchain@stable |
| 86 | + if: ${{ !matrix.settings.docker }} |
| 87 | + with: |
| 88 | + toolchain: stable |
| 89 | + targets: ${{ matrix.settings.target }} |
| 90 | + - uses: actions/cache@v4 |
| 91 | + with: |
| 92 | + path: | |
| 93 | + ~/.cargo/registry/index/ |
| 94 | + ~/.cargo/registry/cache/ |
| 95 | + ~/.cargo/git/db/ |
| 96 | + .cargo-cache |
| 97 | + target/ |
| 98 | + key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} |
| 99 | + - uses: goto-bus-stop/setup-zig@v2 |
| 100 | + if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' || matrix.settings.target == 'armv7-unknown-linux-musleabihf' }} |
| 101 | + with: |
| 102 | + version: 0.13.0 |
| 103 | + - name: Setup toolchain |
| 104 | + run: ${{ matrix.settings.setup }} |
| 105 | + if: ${{ matrix.settings.setup }} |
| 106 | + shell: bash |
| 107 | + - name: Install dependencies |
| 108 | + run: pnpm install |
| 109 | + - name: Build in docker |
| 110 | + uses: addnab/docker-run-action@v3 |
| 111 | + if: ${{ matrix.settings.docker }} |
| 112 | + with: |
| 113 | + image: ${{ matrix.settings.docker }} |
| 114 | + options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build' |
| 115 | + run: | |
| 116 | + set -x |
| 117 | +
|
| 118 | + # Install apt dependencies |
| 119 | + apt-get update -y |
| 120 | + apt-get install -y openssh-client python3 python3-dev |
| 121 | +
|
| 122 | + # Setup pnpm |
| 123 | + corepack disable |
| 124 | + npm i -gf pnpm |
| 125 | +
|
| 126 | + ${{ matrix.settings.build }} |
| 127 | + - name: Build |
| 128 | + run: ${{ matrix.settings.build }} |
| 129 | + if: ${{ !matrix.settings.docker }} |
| 130 | + shell: bash |
| 131 | + - name: Prepare npm package |
| 132 | + run: | |
| 133 | + mkdir -p artifacts |
| 134 | + mv ${{ env.APP_NAME }}.*.node artifacts/ |
| 135 | + pnpm artifacts |
| 136 | + shell: bash |
| 137 | + |
| 138 | + - name: Upload npm package artifact |
| 139 | + uses: actions/upload-artifact@v4 |
| 140 | + with: |
| 141 | + name: npm-${{ matrix.settings.npm_dir }} |
| 142 | + path: npm/${{ matrix.settings.npm_dir }} |
| 143 | + if-no-files-found: error |
| 144 | + |
| 145 | + - name: Upload entrypoints artifact |
| 146 | + uses: actions/upload-artifact@v4 |
| 147 | + with: |
| 148 | + name: entrypoints |
| 149 | + path: | |
| 150 | + index.d.ts |
| 151 | + index.js |
| 152 | + overwrite: true |
| 153 | + if-no-files-found: error |
| 154 | + |
| 155 | + bundle: |
| 156 | + name: Bundle release artifacts |
| 157 | + needs: build |
| 158 | + runs-on: ubuntu-latest |
| 159 | + steps: |
| 160 | + - uses: actions/checkout@v4 |
| 161 | + |
| 162 | + - name: Download all npm package artifacts |
| 163 | + uses: actions/download-artifact@v4 |
| 164 | + with: |
| 165 | + pattern: npm-* |
| 166 | + path: npm-artifacts |
| 167 | + |
| 168 | + - name: Download entrypoints artifact |
| 169 | + uses: actions/download-artifact@v4 |
| 170 | + with: |
| 171 | + name: entrypoints |
| 172 | + path: . |
| 173 | + |
| 174 | + - name: Organize npm packages |
| 175 | + run: | |
| 176 | + for dir in npm-artifacts/npm-*/; do |
| 177 | + platform=$(basename "$dir" | sed 's/^npm-//') |
| 178 | + echo "Moving $dir to npm/$platform/" |
| 179 | + mv "$dir"/* "npm/$platform/" |
| 180 | + done |
| 181 | + rm -rf npm-artifacts |
| 182 | + shell: bash |
| 183 | + |
| 184 | + - name: List release bundle contents |
| 185 | + run: | |
| 186 | + echo "=== Root entrypoints ===" |
| 187 | + ls -la index.js index.d.ts |
| 188 | + echo "" |
| 189 | + echo "=== npm package directories ===" |
| 190 | + for dir in npm/*/; do |
| 191 | + echo "--- $dir ---" |
| 192 | + ls -la "$dir" |
| 193 | + done |
| 194 | + shell: bash |
| 195 | + |
| 196 | + - name: Upload release bundle |
| 197 | + uses: actions/upload-artifact@v4 |
| 198 | + with: |
| 199 | + name: release-bundle |
| 200 | + path: | |
| 201 | + npm/ |
| 202 | + index.js |
| 203 | + index.d.ts |
| 204 | + if-no-files-found: error |
| 205 | + |
| 206 | + test-macOS-binding: |
| 207 | + name: Test ${{ matrix.settings.target }} - node@${{ matrix.node }} + python@${{ matrix.python }} |
| 208 | + if: ${{ inputs.run-tests }} |
| 209 | + needs: |
| 210 | + - build |
| 211 | + strategy: |
| 212 | + fail-fast: false |
| 213 | + matrix: |
| 214 | + settings: |
| 215 | + - host: macos-latest |
| 216 | + target: aarch64-apple-darwin |
| 217 | + architecture: arm64 |
| 218 | + npm_dir: darwin-arm64 |
| 219 | + node: |
| 220 | + - '20' |
| 221 | + - '22' |
| 222 | + - '24' |
| 223 | + python: |
| 224 | + - '3.8' |
| 225 | + - '3.9' |
| 226 | + - '3.10' |
| 227 | + - '3.11' |
| 228 | + - '3.12' |
| 229 | + - '3.13' |
| 230 | + runs-on: ${{ matrix.settings.host }} |
| 231 | + steps: |
| 232 | + - uses: actions/checkout@v4 |
| 233 | + - uses: pnpm/action-setup@v4 |
| 234 | + with: |
| 235 | + version: latest |
| 236 | + - uses: actions/setup-node@v4 |
| 237 | + with: |
| 238 | + node-version: ${{ matrix.node }} |
| 239 | + architecture: ${{ matrix.settings.architecture }} |
| 240 | + cache: pnpm |
| 241 | + - uses: actions/setup-python@v6 |
| 242 | + with: |
| 243 | + python-version: ${{ matrix.python }} |
| 244 | + architecture: ${{ matrix.settings.architecture }} |
| 245 | + - run: pnpm install |
| 246 | + - name: Download npm package artifact |
| 247 | + uses: actions/download-artifact@v4 |
| 248 | + with: |
| 249 | + name: npm-${{ matrix.settings.npm_dir }} |
| 250 | + path: npm/${{ matrix.settings.npm_dir }} |
| 251 | + - name: Download entrypoints artifact |
| 252 | + uses: actions/download-artifact@v4 |
| 253 | + with: |
| 254 | + name: entrypoints |
| 255 | + path: . |
| 256 | + - name: Link npm package for testing |
| 257 | + run: pnpm link ./npm/${{ matrix.settings.npm_dir }} |
| 258 | + - run: cargo test |
| 259 | + - run: pnpm test |
| 260 | + |
| 261 | + test-linux-binding: |
| 262 | + name: Test ${{ matrix.settings.target }} - node@${{ matrix.node }} + python@${{ matrix.python }} |
| 263 | + if: ${{ inputs.run-tests }} |
| 264 | + needs: |
| 265 | + - build |
| 266 | + strategy: |
| 267 | + fail-fast: false |
| 268 | + matrix: |
| 269 | + settings: |
| 270 | + - host: ubuntu-22.04 |
| 271 | + target: x86_64-unknown-linux-gnu |
| 272 | + architecture: x64 |
| 273 | + npm_dir: linux-x64-gnu |
| 274 | + node: |
| 275 | + - '20' |
| 276 | + - '22' |
| 277 | + - '24' |
| 278 | + python: |
| 279 | + - '3.8' |
| 280 | + - '3.9' |
| 281 | + - '3.10' |
| 282 | + - '3.11' |
| 283 | + - '3.12' |
| 284 | + - '3.13' |
| 285 | + runs-on: ${{ matrix.settings.host }} |
| 286 | + steps: |
| 287 | + - uses: actions/checkout@v4 |
| 288 | + - uses: pnpm/action-setup@v4 |
| 289 | + with: |
| 290 | + version: latest |
| 291 | + - name: Setup node |
| 292 | + uses: actions/setup-node@v4 |
| 293 | + with: |
| 294 | + node-version: ${{ matrix.node }} |
| 295 | + architecture: ${{ matrix.settings.architecture }} |
| 296 | + cache: pnpm |
| 297 | + - uses: actions/setup-python@v6 |
| 298 | + with: |
| 299 | + python-version: ${{ matrix.python }} |
| 300 | + architecture: ${{ matrix.settings.architecture }} |
| 301 | + - name: Install dependencies |
| 302 | + run: pnpm install |
| 303 | + - name: Download npm package artifact |
| 304 | + uses: actions/download-artifact@v4 |
| 305 | + with: |
| 306 | + name: npm-${{ matrix.settings.npm_dir }} |
| 307 | + path: npm/${{ matrix.settings.npm_dir }} |
| 308 | + - name: Download entrypoints artifact |
| 309 | + uses: actions/download-artifact@v4 |
| 310 | + with: |
| 311 | + name: entrypoints |
| 312 | + path: . |
| 313 | + - name: Output docker params |
| 314 | + id: docker |
| 315 | + run: | |
| 316 | + node -e " |
| 317 | + if ('${{ matrix.settings.target }}'.startsWith('aarch64')) { |
| 318 | + console.log('PLATFORM=linux/arm64') |
| 319 | + } else if ('${{ matrix.settings.target }}'.startsWith('armv7')) { |
| 320 | + console.log('PLATFORM=linux/arm/v7') |
| 321 | + } else { |
| 322 | + console.log('PLATFORM=linux/amd64') |
| 323 | + } |
| 324 | + " >> $GITHUB_OUTPUT |
| 325 | + node -e " |
| 326 | + if ('${{ matrix.settings.target }}'.endsWith('-musl')) { |
| 327 | + console.log('IMAGE=node:${{ matrix.node }}-alpine') |
| 328 | + } else { |
| 329 | + console.log('IMAGE=node:${{ matrix.node }}-slim') |
| 330 | + } |
| 331 | + " >> $GITHUB_OUTPUT |
| 332 | + echo "PNPM_STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT |
| 333 | + - name: Test crates |
| 334 | + uses: addnab/docker-run-action@v3 |
| 335 | + with: |
| 336 | + image: ${{ steps.docker.outputs.IMAGE }} |
| 337 | + options: -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }} |
| 338 | + run: | |
| 339 | + set -x |
| 340 | +
|
| 341 | + # Install apt dependencies |
| 342 | + apt-get update -y |
| 343 | + apt-get install -y openssh-client curl git build-essential python3 python3-dev |
| 344 | +
|
| 345 | + # Install rust toolchain |
| 346 | + curl https://sh.rustup.rs -sSf | bash -s -- -y -t ${{ matrix.settings.target }} |
| 347 | + . "$HOME/.cargo/env" |
| 348 | +
|
| 349 | + cargo test --target ${{ matrix.settings.target }} |
| 350 | + - name: Test bindings |
| 351 | + uses: addnab/docker-run-action@v3 |
| 352 | + with: |
| 353 | + image: ${{ steps.docker.outputs.IMAGE }} |
| 354 | + options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }} -e CI=true -e GITHUB_ACTIONS=true |
| 355 | + run: | |
| 356 | + # Install Python 3.x |
| 357 | + apt-get update -y |
| 358 | + apt-get install -y python3 python3-dev patchelf |
| 359 | +
|
| 360 | + corepack disable |
| 361 | + npm i -gf pnpm |
| 362 | + pnpm install --prefer-offline |
| 363 | + pnpm link ./npm/${{ matrix.settings.npm_dir }} |
| 364 | + # Run fix-python-soname.js from the npm package directory to patch that binary |
| 365 | + node npm/${{ matrix.settings.npm_dir }}/fix-python-soname.js |
| 366 | + pnpm test |
0 commit comments