Skip to content

Merge pull request #2 from iscc/develop #1

Merge pull request #2 from iscc/develop

Merge pull request #2 from iscc/develop #1

Workflow file for this run

---
name: Release
on:
push:
tags: [v*.*.*]
workflow_dispatch:
inputs:
crates-io:
description: Publish iscc-lib to crates.io
type: boolean
default: false
pypi:
description: Publish iscc-lib to PyPI
type: boolean
default: false
npm:
description: Publish @iscc/lib and @iscc/wasm to npm
type: boolean
default: false
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false # Never cancel a release in progress
jobs:
# Publish Rust core crate to crates.io via OIDC trusted publishing
publish-crates-io:
name: Publish to crates.io
if: startsWith(github.ref, 'refs/tags/v') || inputs.crates-io
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Get workspace version
id: version
run: |
VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check version on registry
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
if cargo info iscc-lib 2>/dev/null | grep -q "version: $VERSION"; then
echo "Version $VERSION already published to crates.io, skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Run tests
if: steps.check.outputs.skip != 'true'
run: cargo test --workspace
- name: Authenticate with crates.io
if: steps.check.outputs.skip != 'true'
uses: rust-lang/crates-io-auth-action@v1
- name: Publish iscc-lib
if: steps.check.outputs.skip != 'true'
run: cargo publish -p iscc-lib
# Build cross-platform Python wheels using maturin
build-wheels:
name: Build wheels (${{ matrix.target }})
if: startsWith(github.ref, 'refs/tags/v') || inputs.pypi
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64
- os: ubuntu-latest
target: aarch64
- os: macos-14
target: universal2-apple-darwin
- os: windows-latest
target: x64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --manifest-path crates/iscc-py/Cargo.toml
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}-${{ matrix.target }}
path: dist
# Build source distribution
build-sdist:
name: Build sdist
if: startsWith(github.ref, 'refs/tags/v') || inputs.pypi
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist --manifest-path crates/iscc-py/Cargo.toml
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist
# Publish all wheels and sdist to PyPI via OIDC trusted publishing
publish-pypi:
name: Publish to PyPI
needs: [build-wheels, build-sdist]
if: startsWith(github.ref, 'refs/tags/v') || inputs.pypi
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Get workspace version
id: version
run: |
VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check version on registry
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
if curl -sf "https://pypi.org/pypi/iscc-lib/$VERSION/json" > /dev/null 2>&1; then
echo "Version $VERSION already published to PyPI, skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Download all artifacts
if: steps.check.outputs.skip != 'true'
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true
- name: Publish to PyPI
if: steps.check.outputs.skip != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
# Build napi-rs native addons for cross-platform npm publishing
build-napi:
name: Build napi (${{ matrix.target }})
if: startsWith(github.ref, 'refs/tags/v') || inputs.npm
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: macos-14
target: aarch64-apple-darwin
- os: macos-13
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Install npm dependencies
run: npm install
working-directory: crates/iscc-napi
- name: Install cross-compiler
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build native addon
run: npx napi build --platform --release --target ${{ matrix.target }}
working-directory: crates/iscc-napi
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: napi-${{ matrix.target }}
path: crates/iscc-napi/*.node
# Publish @iscc/lib to npm
publish-npm-lib:
name: Publish @iscc/lib to npm
needs: [build-napi]
if: startsWith(github.ref, 'refs/tags/v') || inputs.npm
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: https://registry.npmjs.org
- name: Install npm dependencies
run: npm install
working-directory: crates/iscc-napi
- name: Download all napi artifacts
uses: actions/download-artifact@v4
with:
pattern: napi-*
path: crates/iscc-napi
merge-multiple: true
- name: Prepare npm packages
run: npx napi prepublish -t npm
working-directory: crates/iscc-napi
- name: Get workspace version
id: version
run: |
VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check version on registry
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
if npm view "@iscc/lib@$VERSION" version 2>/dev/null; then
echo "Version $VERSION already published to npm, skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: steps.check.outputs.skip != 'true'
run: npm publish --provenance --access public
working-directory: crates/iscc-napi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Build WASM package for npm publishing
build-wasm:
name: Build WASM package
if: startsWith(github.ref, 'refs/tags/v') || inputs.npm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build WASM package
run: wasm-pack build --target web --release crates/iscc-wasm
- name: Set npm package name and version
run: |
node <<'SCRIPT'
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('crates/iscc-wasm/pkg/package.json', 'utf8'));
pkg.name = '@iscc/wasm';
const toml = fs.readFileSync('Cargo.toml', 'utf8');
const m = toml.match(/^version\s*=\s*"(.+?)"/m);
if (m) pkg.version = m[1];
fs.writeFileSync('crates/iscc-wasm/pkg/package.json', JSON.stringify(pkg, null, 2) + '\n');
SCRIPT
- name: Upload WASM package
uses: actions/upload-artifact@v4
with:
name: wasm-pkg
path: crates/iscc-wasm/pkg/
# Publish @iscc/wasm to npm
publish-npm-wasm:
name: Publish @iscc/wasm to npm
needs: [build-wasm]
if: startsWith(github.ref, 'refs/tags/v') || inputs.npm
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: https://registry.npmjs.org
- name: Download WASM package
uses: actions/download-artifact@v4
with:
name: wasm-pkg
path: pkg
- name: Get package version
id: version
run: |
VERSION=$(node -p "require('./pkg/package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check version on registry
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
if npm view "@iscc/wasm@$VERSION" version 2>/dev/null; then
echo "Version $VERSION already published to npm, skipping"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: steps.check.outputs.skip != 'true'
run: npm publish --provenance --access public
working-directory: pkg
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}