name: Publish to PyPI
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
jobs:
build-wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Setup Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
env:
PYO3_USE_ABI3_FORWARD_COMPATIBILITY: "1"
with:
command: build
args: --release --features python -o dist ${{ matrix.os == 'ubuntu-latest' && '--sdist' || '' }}
rust-toolchain: stable
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: dist
release:
name: Release to PyPI
runs-on: ubuntu-latest
needs: build-wheels
steps:
- name: Download all wheels
uses: actions/download-artifact@v4
with:
path: dist
pattern: wheels-*
merge-multiple: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
build-node:
name: Build Node addon on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Build node module
run: npx napi build --platform --release --features nodejs
- name: Upload node binding
uses: actions/upload-artifact@v4
with:
name: node-${{ matrix.os }}
path: "*.node"
release-npm:
name: Release to NPM
runs-on: ubuntu-latest
needs: build-node
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- name: Download all bindings
uses: actions/download-artifact@v4
with:
path: .
pattern: node-*
merge-multiple: true
- name: Generate JS Loader
run: |
cat << 'EOF' > index.js
const { platform, arch } = process;
let nativeBinding = null;
try {
if (platform === 'win32') { nativeBinding = require('./triviumdb.win32-x64-msvc.node'); }
else if (platform === 'darwin' && arch === 'arm64') { nativeBinding = require('./triviumdb.darwin-arm64.node'); }
else if (platform === 'darwin') { nativeBinding = require('./triviumdb.darwin-x64.node'); }
else if (platform === 'linux' && arch === 'arm64') { nativeBinding = require('./triviumdb.linux-arm64-gnu.node'); }
else { nativeBinding = require('./triviumdb.linux-x64-gnu.node'); }
} catch (e) {
console.error(`TriviumDB failed to load native binding for ${platform} ${arch}`, e);
throw e;
}
module.exports = nativeBinding;
EOF
- name: Publish to NPM
run: |
npm install
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}