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
255 changes: 93 additions & 162 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,49 @@ name: CI

on:
push:
branches:
- "**"
branches: [main]
pull_request:
branches:
- "**"

permissions:
contents: read

jobs:
quality:
name: Check code quality on Node ${{ matrix.node }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node: [22, 24, 26]

steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: true

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check
run: pnpm check

build:
name: Build on ${{ matrix.os }}
name: Build on ${{ matrix.os }} with Node ${{ matrix.node }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node: [22, 24, 26]
os:
- macos-15-intel
- macos-15
Expand All @@ -31,55 +58,46 @@ jobs:
with:
submodules: true

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Enable Yarn Berry
run: |
corepack enable
yarn set version berry

- name: Cache Yarn dependencies
uses: actions/cache@v4
with:
path: |
.yarn/cache
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ github.ref }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ github.ref }}-
${{ runner.os }}-yarn-
node-version: ${{ matrix.node }}
cache: pnpm

- name: Install dependencies
run: yarn install --immutable
run: pnpm install --frozen-lockfile

- name: Build TypeScript artifacts
run: yarn build-tsup
- name: Build package artifacts
run: pnpm build-package

- name: Build N-API prebuilds
run: yarn prebuild
if: matrix.node == 24
run: pnpm prebuild

- name: Run tests
run: yarn test
run: pnpm test

- name: Archive prebuilds for ${{ matrix.os }}
if: matrix.node == 24
run: tar -czf prebuilds-${{ matrix.os }}.tar.gz -C prebuilds .

- name: Upload prebuilds artifact
if: matrix.node == 24
uses: actions/upload-artifact@v4
with:
name: prebuild-${{ matrix.os }}
path: prebuilds-${{ matrix.os }}.tar.gz

build_musl:
name: Build on Alpine Linux
name: Build on Alpine Linux with Node ${{ matrix.node }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node: [22] # you can add more if you really want, but N-API means one is enough
node: [22, 24, 26]

steps:
- name: Checkout repository
Expand All @@ -98,161 +116,74 @@ jobs:
sh -lc '
set -euo pipefail
apk add --no-cache python3 make g++ &&
npm install --global [email protected] &&
corepack enable &&
yarn install --immutable &&
yarn build-tsup &&
# Build N-API prebuilds for musl, tagging libc so node-gyp-build
# can prefer them on Alpine.
yarn prebuild &&
yarn test
pnpm install --frozen-lockfile &&
pnpm check &&
pnpm build-package &&
if [ "${{ matrix.node }}" = "24" ]; then
# Build N-API prebuilds for musl, tagging libc so node-gyp-build
# can prefer them on Alpine.
pnpm prebuild
fi &&
pnpm test
'

- name: Archive musl prebuilds
if: matrix.node == 24
run: tar -czf prebuilds-linux-musl-node${{ matrix.node }}.tar.gz -C prebuilds .

- name: Upload musl artifact
if: matrix.node == 24
uses: actions/upload-artifact@v4
with:
name: prebuild-musl-node${{ matrix.node }}
path: prebuilds-linux-musl-node${{ matrix.node }}.tar.gz

check-version:
name: Check version
build_openbsd:
name: Build on OpenBSD x86-64
runs-on: ubuntu-22.04
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
outputs:
publish: ${{ steps.check.outputs.publish }}
package_name: ${{ steps.check.outputs.package_name }}
package_version: ${{ steps.check.outputs.package_version }}
published_version: ${{ steps.check.outputs.published_version }}
release_tag: ${{ steps.check.outputs.release_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: true

- name: Setup Node.js
uses: actions/setup-node@v4
- name: Build on OpenBSD
uses: cross-platform-actions/[email protected]
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
with:
node-version: 20

- name: Determine publish requirement
id: check
run: |
set -euo pipefail
PACKAGE_NAME=$(node -p "require('./package.json').name")
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if PUBLISHED_VERSION=$(npm view "$PACKAGE_NAME" version 2>/dev/null); then
echo "Found published version $PUBLISHED_VERSION"
else
PUBLISHED_VERSION=""
echo "Package $PACKAGE_NAME not found on npm or version lookup failed"
fi
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
echo "published_version=$PUBLISHED_VERSION" >> "$GITHUB_OUTPUT"
echo "release_tag=v$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
if [ "$PACKAGE_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "Version $PACKAGE_VERSION already published, skipping" >> "$GITHUB_STEP_SUMMARY"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "Will publish $PACKAGE_VERSION (latest npm: ${PUBLISHED_VERSION:-none})" >> "$GITHUB_STEP_SUMMARY"
fi
operating_system: openbsd
version: "7.8"
architecture: x86-64
environment_variables: ELECTRON_SKIP_BINARY_DOWNLOAD
run: |
set -euo pipefail
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
sudo pkg_add node npm
sudo npm install --global [email protected]
sudo corepack enable
pnpm install --frozen-lockfile
# vite-plus does not ship an OpenBSD binding. Quality checks and
# package builds run in the platform-native jobs above; this job
# verifies the OpenBSD prebuild itself.
pnpm prebuild
LIBOPUS_TEST_NATIVE=1 node src/tests/test.js

- name: Archive OpenBSD prebuilds
run: tar -czf prebuilds-openbsd-x64.tar.gz -C prebuilds .

- name: Upload OpenBSD artifact
uses: actions/upload-artifact@v4
with:
name: prebuild-openbsd-x64
path: prebuilds-openbsd-x64.tar.gz

publish:
name: Publish to npm
runs-on: ubuntu-22.04
needs: [quality, build, build_musl, build_openbsd]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: ./.github/workflows/publish.yml
permissions:
contents: write
id-token: write
needs:
- build
- build_musl
- check-version
if: needs.check-version.result == 'success' && needs.check-version.outputs.publish == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: true

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Enable Yarn Berry
run: |
corepack enable
yarn set version berry

- name: Cache Yarn dependencies
uses: actions/cache@v4
with:
path: |
.yarn/cache
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ github.ref }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ github.ref }}-
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn install --immutable

- name: Build TypeScript artifacts
run: yarn build-tsup

- name: Remove unneeded build artifacts
run: rm -rf build

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: prebuild-*
merge-multiple: true
path: artifacts/builds

- name: Download musl artifacts
uses: actions/download-artifact@v4
with:
pattern: prebuild-musl-*
merge-multiple: true
path: artifacts/musl

- name: Expand prebuild archives
run: |
set -euo pipefail
shopt -s nullglob
mkdir -p prebuilds
found=false
for archive in artifacts/**/*.tar.gz; do
found=true
tar -xzf "$archive" -C prebuilds
rm -f "$archive"
done
if [ "$found" = false ]; then
echo "No prebuild archives were downloaded." >&2
exit 1
fi

# IMPORTANT: npm >= 11.5.1 and npm publish, not yarn npm publish
- name: Ensure recent npm for trusted publishing
run: npm install -g npm@latest

- name: Verify npm version
run: npm --version

- name: Publish to npm via trusted publisher
run: npm publish --provenance --access public

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-version.outputs.release_tag }}
name: ${{ needs.check-version.outputs.release_tag }}
draft: false
prerelease: false
generate_release_notes: true
Loading
Loading