Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
name: Publish npm packages

on:
release:
types: [published]
workflow_dispatch:
inputs:
release_tag:
description: Release tag to build from
required: false
type: string
workflow_call:
inputs:
release_tag:
description: Release tag to build from
required: true
type: string
secrets:
NPM_TOKEN:
description: npm token for publishing packages
required: true

permissions:
contents: read

concurrency:
group: npm-publish-${{ inputs.release_tag || github.event.release.tag_name || github.ref_name }}
cancel-in-progress: false

env:
CARGO_TERM_COLOR: always
RELEASE_TAG: ${{ inputs.release_tag || github.event.release.tag_name || github.ref_name }}

jobs:
build:
name: Build - ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.os }}
strategy:
fail-fast: false
matrix:
settings:
- target: x86_64-apple-darwin
os: macos-15-intel
- target: aarch64-apple-darwin
os: macos-14
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
cross: true
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
cross: true
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ env.RELEASE_TAG }}

- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: wasm32-wasip2,${{ matrix.settings.target }}

- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24

- name: Cache cargo
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1

- name: Install cargo-binstall
uses: cargo-bins/cargo-binstall@4852a15cf01e4f33958ce547326406fe78f27c38 # v1.19.0

- name: Install auditable build tool
run: cargo binstall cargo-auditable --force

- name: Install cross-compilation tools
if: matrix.settings.cross
uses: taiki-e/setup-cross-toolchain-action@129361238c06ff2cc1c4ca5c5d2217af441ffdf6 # v1.40.1
with:
target: ${{ matrix.settings.target }}

- name: Install musl tools
if: contains(matrix.settings.target, 'musl')
run: sudo apt-get install -y musl-tools

- name: Install npm dependencies
working-directory: npm
run: npm install

- name: Sync version from Cargo.toml
shell: bash
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
cd npm
npm version "$VERSION" --no-git-tag-version --allow-same-version

- name: Build napi binding
working-directory: npm
run: npx napi build --manifest-path ../napi/Cargo.toml --platform --target ${{ matrix.settings.target }} --js index.js --dts index.d.ts -o . --release
env:
COMPONENTIZE_QJS_RUNTIME_AUDITABLE: 1

- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: bindings-${{ matrix.settings.target }}
path: npm/*.node
if-no-files-found: error

- name: Upload generated JS bindings
if: matrix.settings.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: js-bindings
path: |
npm/index.js
npm/index.d.ts
if-no-files-found: error

publish:
name: Publish to npm
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ env.RELEASE_TAG }}

- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
registry-url: https://registry.npmjs.org

- name: Install npm dependencies
working-directory: npm
run: npm install

- name: Sync version from Cargo.toml
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
cd npm
npm version "$VERSION" --no-git-tag-version --allow-same-version

- name: Download all artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: npm/artifacts
merge-multiple: true

- name: Restore generated JS bindings
working-directory: npm
run: cp artifacts/index.js artifacts/index.d.ts .

- name: List artifacts
working-directory: npm
run: ls -la artifacts/*.node

- name: Prepare npm packages
working-directory: npm
run: |
npx napi create-npm-dirs --npm-dir npm
npx napi artifacts --output-dir artifacts --npm-dir npm
npx napi prepublish --skip-optional-publish --no-gh-release

- name: Check npm package contents
working-directory: npm
shell: bash
run: |
set -euo pipefail
for package_json in npm/*/package.json; do
package_dir="$(dirname "$package_json")"
(cd "$package_dir" && npm pack --dry-run)
done
npm pack --dry-run

- name: Publish platform packages
if: github.event_name != 'workflow_dispatch'
working-directory: npm
shell: bash
run: |
set -euo pipefail
for package_json in npm/*/package.json; do
package_dir="$(dirname "$package_json")"
(cd "$package_dir" && npm publish --provenance --access public)
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish main package
if: github.event_name != 'workflow_dispatch'
working-directory: npm
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
13 changes: 13 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ jobs:
with:
release_tag: ${{ needs.release-plz-release.outputs.release_tag }}

publish-npm:
name: Publish npm packages
needs: release-plz-release
if: needs.release-plz-release.outputs.releases_created == 'true' && needs.release-plz-release.outputs.release_tag != ''
permissions:
contents: read
id-token: write
uses: ./.github/workflows/npm-publish.yml
with:
release_tag: ${{ needs.release-plz-release.outputs.release_tag }}
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

release-plz-pr:
name: Release-plz PR
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/runtime-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable

- name: Install cargo-binstall
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
uses: cargo-bins/cargo-binstall@4852a15cf01e4f33958ce547326406fe78f27c38 # v1.19.0

- name: Install wkg
run: cargo binstall wkg --force
Expand Down
Loading
Loading