name: Release on: push: branches: - main concurrency: group: ${{ github.workflow }}-${{ github.ref }} # A publish that has started must finish: cancelling can leave some packages # on npm and others missing. cancel-in-progress: false permissions: contents: read env: DEBUG: napi:* MACOSX_DEPLOYMENT_TARGET: '11.0' jobs: release: name: Version or prepare release runs-on: ubuntu-latest permissions: contents: write pull-requests: write outputs: publish: ${{ steps.package-version.outputs.publish }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # Changesets needs history for changelogs and the version PR branch. fetch-depth: 0 submodules: recursive - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: lts/* cache: pnpm - name: Install Rust toolchain uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable - name: Install cargo-binstall uses: taiki-e/install-action@a4d3f3f761dcd95cce1b72cb61cb6d1963438177 # v2.87.30 with: tool: cargo-binstall - name: Install cargo-edit run: cargo binstall --no-confirm cargo-edit - name: Install dependencies run: pnpm install --frozen-lockfile - name: Create or update release pull request id: changesets uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2 with: commit-message: 'chore: release tombit' pr-title: 'chore: release tombit' version-script: pnpm run version - name: Check package version on npm id: package-version if: steps.changesets.outputs.has-changesets == 'false' run: | set -euo pipefail name=$(jq -r .name package.json) version=$(jq -r .version package.json) encoded_name=${name//\//%2f} status=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 30 \ "https://registry.npmjs.org/${encoded_name}/${version}") case "$status" in 200) echo "${name}@${version} is already published." ;; 404) echo "publish=true" >> "$GITHUB_OUTPUT" echo "${name}@${version} is not published yet." ;; *) echo "npm registry answered ${status} for ${name}@${version}" >&2 exit 1 ;; esac # Every target needs its own build recipe: musl goes through zig, riscv64 and # loongarch64 need a cross gcc, and FreeBSD needs its own VM (see # `build-freebsd`). Modelled on unrs-resolver's `release-napi.yml`. # # `--features schema` compiles tombi's HTTP client, which needs `ring` and # therefore a supported C toolchain. It is enabled on linux/macOS/windows and # FreeBSD; the other targets ship the offline stub with the same API. # build: name: Build ${{ matrix.target }} needs: release if: needs.release.outputs.publish == 'true' runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: # Not built here: `x86_64-pc-windows-gnu` needs a `libnode.dll` for # napi-build to link against, which the Node Windows distribution does # not ship. `universal-apple-darwin` is dropped: both macOS arches are # published separately. include: - os: windows-latest target: x86_64-pc-windows-msvc build: pnpm build --features schema - os: windows-latest target: aarch64-pc-windows-msvc build: pnpm build --features schema - os: windows-latest target: i686-pc-windows-msvc build: pnpm build --features schema - os: ubuntu-latest target: x86_64-unknown-linux-gnu build: pnpm build --use-napi-cross --features schema - os: ubuntu-latest target: aarch64-unknown-linux-gnu build: export CFLAGS_aarch64_unknown_linux_gnu="-D__ARM_ARCH=8" && pnpm build --use-napi-cross --features schema - os: ubuntu-latest target: x86_64-unknown-linux-musl build: pnpm build -x --features schema - os: ubuntu-latest target: aarch64-unknown-linux-musl build: pnpm build -x --features schema - os: ubuntu-latest target: armv7-unknown-linux-gnueabihf build: pnpm build --use-napi-cross - os: ubuntu-latest target: armv7-unknown-linux-musleabihf build: pnpm build -x - os: ubuntu-latest target: powerpc64le-unknown-linux-gnu build: pnpm build --use-napi-cross - os: ubuntu-latest target: powerpc64le-unknown-linux-musl build: pnpm build -x - os: ubuntu-latest target: s390x-unknown-linux-gnu build: pnpm build --use-napi-cross - os: ubuntu-latest target: riscv64gc-unknown-linux-gnu build: |- sudo apt-get update && sudo apt-get install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu -y && export TARGET_CC=riscv64-linux-gnu-gcc && export CXX=riscv64-linux-gnu-g++ && pnpm build - os: ubuntu-latest target: riscv64gc-unknown-linux-musl build: pnpm build -x - os: ubuntu-latest target: loongarch64-unknown-linux-gnu build: |- sudo apt-get update && sudo apt-get install gcc-13-loongarch64-linux-gnu g++-13-loongarch64-linux-gnu -y && export CC_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-gcc-13 && export CXX_loongarch64_unknown_linux_gnu=loongarch64-linux-gnu-g++-13 && export CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER=loongarch64-linux-gnu-gcc-13 && pnpm build - os: ubuntu-latest target: loongarch64-unknown-linux-musl build: pnpm build -x - os: ubuntu-latest target: aarch64-linux-android build: pnpm build - os: ubuntu-latest target: armv7-linux-androideabi architecture: x64 build: pnpm build - os: ubuntu-latest target: aarch64-unknown-linux-ohos build: pnpm build - os: ubuntu-latest target: x86_64-unknown-linux-ohos build: pnpm build - os: macos-latest target: x86_64-apple-darwin build: pnpm build --features schema - os: macos-latest target: aarch64-apple-darwin build: pnpm build --features schema - os: ubuntu-latest target: wasm32-wasip1-threads build: pnpm build:debug --release steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false submodules: recursive - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 cache: pnpm architecture: ${{ matrix.architecture }} - name: Install Rust toolchain uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable with: targets: ${{ matrix.target }} - name: Setup Zig if: contains(matrix.target, 'musl') || contains(matrix.target, 'windows-gnu') uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1 with: version: 0.14.0 - name: Setup OpenHarmony SDK if: contains(matrix.target, 'ohos') uses: Boshen/setup-ohos-sdk@edb865a89a712f1f15dbad932dfa9cfce849d95c # v1.0.0 - name: Cache Rust build uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 with: key: ${{ matrix.target }} - name: Install dependencies run: pnpm install --frozen-lockfile - name: Build run: ${{ matrix.build }} --target ${{ matrix.target }} shell: bash - name: Smoke-test the WASI loader if: matrix.target == 'wasm32-wasip1-threads' run: pnpm run test:wasi - name: Upload binding uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: bindings-${{ matrix.target }} path: | tombit.*.node tombit.*.wasm tombit.*.wasm.d.ts tombit.wasi* tombit.wasip1* wasi-worker*.mjs if-no-files-found: error - name: Upload generated loader if: matrix.target == 'x86_64-unknown-linux-gnu' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: js-binding path: | browser.js index.js index.d.ts if-no-files-found: error build-freebsd: name: Build x86_64-unknown-freebsd needs: release if: needs.release.outputs.publish == 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false submodules: recursive - name: Build uses: cross-platform-actions/action@e0b9770014ba65d5e0815f15b74031c3a635f641 # v1.6.0 env: DEBUG: napi:* RUSTUP_IO_THREADS: 1 with: operating_system: freebsd version: 14.2 memory: 8G cpu_count: 3 environment_variables: DEBUG RUSTUP_IO_THREADS shell: bash run: | sudo pkg install -y -f curl libnghttp2 node22 npm cmake curl https://sh.rustup.rs -sSf --output rustup.sh sh rustup.sh -y --profile minimal --default-toolchain stable source "$HOME/.cargo/env" node -v sudo corepack enable pnpm install pnpm build --target x86_64-unknown-freebsd --features schema rm -rf node_modules target - name: Upload binding uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: bindings-x86_64-unknown-freebsd path: tombit.*.node if-no-files-found: error # npm only lets a trusted publisher be configured for a package that already # exists, so the first release needs `0.0.0` placeholders for the platform # packages. See `docs/releasing.md`. publish: name: Publish to npm needs: - build - build-freebsd if: needs.build.result == 'success' && needs.build-freebsd.result == 'success' runs-on: ubuntu-latest permissions: contents: write id-token: write env: NPM_CONFIG_PROVENANCE: 'true' steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: submodules: recursive - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: lts/* cache: pnpm - name: Install dependencies run: pnpm install --frozen-lockfile - name: Download bindings uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: path: artifacts merge-multiple: true - name: Download generated loader uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: js-binding path: . - name: Assemble platform packages run: | pnpm napi create-npm-dirs pnpm napi artifacts --build-output-dir artifacts - name: Publish platform packages run: pnpm napi pre-publish --no-gh-release --tagstyle npm --npm-dir npm - name: Publish packages # The publish action runs `changeset publish` itself, pushes the tag, and # creates the GitHub release. Trusted publishing authenticates via OIDC. uses: changesets/action/publish@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2