Skip to content

CI / Release

CI / Release #138

Workflow file for this run

name: CI / Release
on:
push:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g. 1.3.0 or 1.3.0-beta.0)'
required: true
type: string
jobs:
cancel-previous-runs:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@d07a454dad7609a92316b57b23c9ccfd4f59af66 # 0.13.1
with:
access_token: ${{ github.token }}
build_linux-x64-musl:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: x86_64-unknown-linux-musl
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
- name: Download x86_64-linux-musl-cross toolchain
run: curl -O -L -C - https://github.com/musl-cc/musl.cc/releases/download/v0.0.1/x86_64-linux-musl-cross.tgz
- name: Install x86_64-linux-musl-cross toolchain
run: tar xf x86_64-linux-musl-cross.tgz
- name: Configure linux-x64-musl cross compile
run: |
echo "CC_x86_64_unknown_linux_musl=$(pwd)/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc" >> $GITHUB_ENV
echo "CXX_x86_64_unknown_linux_musl=$(pwd)/x86_64-linux-musl-cross/bin/x86_64-linux-musl--g++" >> $GITHUB_ENV
echo "AR_x86_64_unknown_linux_musl=$(pwd)/x86_64-linux-musl-cross/bin/x86_64-linux-musl-ar" >> $GITHUB_ENV
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=$(pwd)/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc" >> $GITHUB_ENV
echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_AR=$(pwd)/x86_64-linux-musl-cross/bin/x86_64-linux-musl-ar" >> $GITHUB_ENV
echo "TARGET_PLATFORM=linux" >> $GITHUB_ENV
echo "TARGET_ARCH=x64" >> $GITHUB_ENV
echo "TARGET_LIBC=musl" >> $GITHUB_ENV
- name: npm i
run: npm i
- name: Build
run: npm run build:cargo
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: linux-x64-musl
path: native/linux-x64-musl.node
if-no-files-found: error
build_linux-arm64-musl:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: aarch64-unknown-linux-musl
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
- name: Download aarch64-linux-musl-cross toolchain
run: curl -O -L -C - https://github.com/musl-cc/musl.cc/releases/download/v0.0.1/aarch64-linux-musl-cross.tgz
- name: Install aarch64-linux-musl-cross toolchain
run: tar xf aarch64-linux-musl-cross.tgz
- name: Configure linux-arm64-musl cross compile
run: |
echo "CC_aarch64_unknown_linux_musl=$(pwd)/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_musl=$(pwd)/aarch64-linux-musl-cross/bin/aarch64-linux-musl--g++" >> $GITHUB_ENV
echo "AR_aarch64_unknown_linux_musl=$(pwd)/aarch64-linux-musl-cross/bin/aarch64-linux-musl-ar" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=$(pwd)/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_AR=$(pwd)/aarch64-linux-musl-cross/bin/aarch64-linux-musl-ar" >> $GITHUB_ENV
echo "TARGET_PLATFORM=linux" >> $GITHUB_ENV
echo "TARGET_ARCH=arm64" >> $GITHUB_ENV
echo "TARGET_LIBC=musl" >> $GITHUB_ENV
- name: npm i
run: npm i
- name: Build
run: npm run build:cargo
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: linux-arm64-musl
path: native/linux-arm64-musl.node
if-no-files-found: error
build_linux-x64-glibc:
runs-on: ubuntu-latest
container:
image: rust
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: x86_64-unknown-linux-gnu
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
- name: npm i
run: npm i
- name: Build
run: npm run build:cargo
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: linux-x64-glibc
path: native/linux-x64-glibc.node
if-no-files-found: error
build_linux-arm64-glibc:
runs-on: ubuntu-latest
container:
image: rust
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: aarch64-unknown-linux-gnu
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
- name: Install cross compile deps
run: |
apt-get update && apt-get install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross gcc-aarch64-linux-gnu qemu-user
- name: Configure linux-arm64 cross compile
run: |
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu"' >> $GITHUB_ENV
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "TARGET_ARCH=arm64" >> $GITHUB_ENV
- name: npm i
run: npm i
- name: Build
run: npm run build:cargo
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: linux-arm64-glibc
path: native/linux-arm64-glibc.node
if-no-files-found: error
build_win-x64:
runs-on: windows-2022
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: x86_64-pc-windows-msvc
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
- name: npm i
run: npm i
- name: Build
run: npm run build:cargo
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: win32-x64
path: native/win32-x64.node
if-no-files-found: error
# build_darwin-x64:
# if: ${{ false }}
# runs-on: macos-14
# steps:
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# - uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
# with:
# targets: x86_64-apple-darwin
# - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
# with:
# node-version-file: .nvmrc
# - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
# - name: npm i
# run: npm i
# - name: Build
# run: npm run build:cargo
# - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
# with:
# name: darwin-x64
# path: native/darwin-x64.node
# if-no-files-found: error
build_darwin-arm64:
runs-on: macos-14
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
targets: aarch64-apple-darwin
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
# `cache-bin: false` avoids restoring a broken `~/.cargo/bin/` over the
# rustup proxies on macOS. See https://github.com/Swatinem/rust-cache/issues/341
# and https://github.com/actions/runner-images/issues/14097
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2.9.1
with:
cache-bin: 'false'
- name: Configure macos-arm64 cross compile
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
echo "TARGET_ARCH=arm64" >> $GITHUB_ENV
- name: npm i
run: npm i
- name: Build
run: npm run build:cargo
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: darwin-arm64
path: native/darwin-arm64.node
if-no-files-found: error
test_linux-arm64-glibc:
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- build_linux-arm64-glibc
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: linux-arm64-glibc
path: native
- name: npm i
run: npm i
- name: Build js
run: npm run build:ts
- uses: uraimo/run-on-arch-action@ac33288c3728ca72563c97b8b88dda5a65a84448 # v2.8.1
name: Run on arch
with:
arch: aarch64
distro: ubuntu_latest
githubToken: ${{ github.token }}
install: |
apt-get update && apt-get install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y --no-install-recommends nodejs
run: |
npm run test:js
test_linux-arm64-musl:
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- build_linux-arm64-musl
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: linux-arm64-musl
path: native
- name: npm i
run: npm i
- name: Build js
run: npm run build:ts
- uses: uraimo/run-on-arch-action@ac33288c3728ca72563c97b8b88dda5a65a84448 # v2.8.1
name: Run on arch
with:
arch: aarch64
distro: alpine_latest
githubToken: ${{ github.token }}
install: |
apk add nodejs npm
run: |
npm run test:js
test_linux-x64-glibc:
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: read
container:
image: node:20-bookworm
needs:
- build_linux-x64-glibc
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: linux-x64-glibc
path: native
- name: npm i
run: npm i
- name: Build js
run: npm run build:ts
- name: Test js
run: npm run test:js
- name: Test examples
working-directory: examples
run: npm i && npm test
test_linux-x64-musl:
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: read
container:
image: node:20-alpine
needs:
- build_linux-x64-musl
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: linux-x64-musl
path: native
- name: npm i
run: npm i
- name: Build js
run: npm run build:ts
- name: Test js
run: npm run test:js
- name: Test examples
working-directory: examples
run: npm i && npm test
test_win-x64:
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: windows-2022
permissions:
contents: read
needs:
- build_win-x64
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .nvmrc
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: win32-x64
path: native
- name: npm i
run: npm i
- name: Build js
run: npm run build:ts
- name: Test js
run: npm run test:js
- name: Test examples
working-directory: examples
run: npm i && npm test
# test_darwin-x64:
# if: ${{ false && github.event_name != 'workflow_dispatch' }}
# runs-on: macos-14
# permissions:
# contents: read
# needs:
# - build_darwin-x64
# steps:
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
# - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
# with:
# name: darwin-x64
# path: native
# - name: npm i
# run: npm i
# - name: Build js
# run: npm run build:ts
# - name: Test js
# run: npm run test:js
# - name: Test examples
# working-directory: examples
# run: npm i && npm test
publish-npm:
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
needs:
- build_linux-arm64-glibc
- build_linux-arm64-musl
- build_linux-x64-glibc
- build_linux-x64-musl
- build_win-x64
# - build_darwin-x64
- build_darwin-arm64
permissions:
contents: read
id-token: write
steps:
- name: Checkout tag
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: v${{ inputs.version }}
- name: Use Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
- name: Upgrade npm
run: npm install -g npm@~11.10.0
- name: Install deps
run: npm ci --audit=false
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: native
- name: Position downloaded artifacts
run: |
mkdir -p ./native
find ./native -mindepth 2 -type f -exec mv -t ./native -i '{}' +
find ./native -mindepth 1 -type d -empty -delete
ls -R ./native
- name: Publish to npm
run: |
VERSION="${{ inputs.version }}"
if [[ "$VERSION" == *-* ]]; then
# Extract the prerelease identifier (e.g. "next" from "9.0.0-next.30")
TAG="${VERSION#*-}"
TAG="${TAG%%.*}"
npm publish --provenance --access public --tag "$TAG"
else
npm publish --provenance --access public
fi
github-release:
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
needs:
- publish-npm
permissions:
contents: write
steps:
- name: Checkout tag
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: v${{ inputs.version }}
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PRERELEASE_FLAG=""
if echo "${{ inputs.version }}" | grep -q "-"; then
PRERELEASE_FLAG="--prerelease"
fi
gh release create "v${{ inputs.version }}" \
--generate-notes \
$PRERELEASE_FLAG