Skip to content

fix: update Rust action to use rust-toolchain for consistency #29

fix: update Rust action to use rust-toolchain for consistency

fix: update Rust action to use rust-toolchain for consistency #29

Workflow file for this run

name: Release
permissions:
contents: write
id-token: write
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
# Build native modules for all platforms
build-native:
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- run: pnpm install
- name: Build native module
run: |
cd native
pnpm napi build --platform --release --target ${{ matrix.target }}
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.target }}
path: native/*.node
if-no-files-found: error
# Publish platform-specific npm packages
publish-native:
needs: build-native
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
cache: pnpm
- run: pnpm install
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: native/artifacts
- name: Move artifacts
run: |
cd native
for dir in artifacts/bindings-*; do
cp "$dir"/*.node . 2>/dev/null || true
done
ls -la *.node
- name: Update native package version
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}" # Remove 'v' prefix
cd native
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '$VERSION';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
- name: Create npm packages
run: |
cd native
pnpm napi create-npm-dirs
- name: Determine npm tag
id: npm-tag
run: |
if [[ "${{ github.ref_name }}" == *"-beta"* ]] || [[ "${{ github.ref_name }}" == *"-rc"* ]] || [[ "${{ github.ref_name }}" == *"-alpha"* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish platform packages
run: |
cd native
for pkg in npm/*/; do
if [ -f "$pkg/package.json" ]; then
echo "Publishing $pkg"
cd "$pkg"
npm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} || true
cd ../..
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Publish main package (after native packages)
release:
needs: publish-native
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
cache: pnpm
- run: pnpm install
# Add optionalDependencies for platform-specific native packages
- name: Add native package dependencies
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}" # Remove 'v' prefix
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.optionalDependencies = {
'nitro-graphql-darwin-arm64': '$VERSION',
'nitro-graphql-darwin-x64': '$VERSION',
'nitro-graphql-linux-x64-gnu': '$VERSION',
'nitro-graphql-linux-arm64-gnu': '$VERSION',
'nitro-graphql-win32-x64-msvc': '$VERSION'
};
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
cat package.json | grep -A 10 optionalDependencies
# Skip native build - use JS-only build since native packages are separate
- run: pnpm tsdown
- name: Determine npm tag
id: npm-tag
run: |
if [[ "${{ github.ref_name }}" == *"-beta"* ]] || [[ "${{ github.ref_name }}" == *"-rc"* ]] || [[ "${{ github.ref_name }}" == *"-alpha"* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: pnpm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get previous tag
id: prev-tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
run: |
if [ -n "${{ steps.prev-tag.outputs.tag }}" ]; then
npx changelogithub --from ${{ steps.prev-tag.outputs.tag }}
else
npx changelogithub
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}