name: Build & Release
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: write
id-token: write
env:
REPO: zebflow/zebflow
jobs:
prepare:
name: Prepare version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Compute version
id: version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
VERSION="${GITHUB_REF_NAME}"
else
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
VERSION="v${CARGO_VERSION}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Version: ${VERSION}"
build:
name: Build ${{ matrix.name }}
needs: prepare
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-amd64
runner: ubuntu-latest
target: x86_64-unknown-linux-gnu
asset: zebflow-linux-amd64.tar.gz
binary: zebflow
- name: linux-arm64
runner: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
asset: zebflow-linux-arm64.tar.gz
binary: zebflow
- name: darwin-arm64
runner: macos-14
target: aarch64-apple-darwin
asset: zebflow-darwin-arm64.tar.gz
binary: zebflow
- name: windows-amd64
runner: windows-latest
target: x86_64-pc-windows-msvc
asset: zebflow-windows-amd64.zip
binary: zebflow.exe
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Build release binary
shell: bash
run: |
cargo build --release --bin zebflow
env:
BUILD_VERSION: ${{ needs.prepare.outputs.version }}
- name: Archive (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
cd target/release
tar -czf "../../${{ matrix.asset }}" "${{ matrix.binary }}"
- name: Archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Compress-Archive -Path "target/release/${{ matrix.binary }}" -DestinationPath "${{ matrix.asset }}"
- name: Generate checksum
shell: bash
run: |
if [[ "$RUNNER_OS" == "macOS" ]]; then
shasum -a 256 "${{ matrix.asset }}" > "${{ matrix.asset }}.sha256"
else
sha256sum "${{ matrix.asset }}" > "${{ matrix.asset }}.sha256"
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: |
${{ matrix.asset }}
${{ matrix.asset }}.sha256
if-no-files-found: error
release:
name: Publish release
needs: [prepare, build]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Create checksums file
shell: bash
run: |
cd artifacts
cat *.sha256 > zebflow-checksums.txt
cat zebflow-checksums.txt
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.prepare.outputs.version }}
name: Zebflow ${{ needs.prepare.outputs.version }}
generate_release_notes: true
files: |
artifacts/zebflow-linux-amd64.tar.gz
artifacts/zebflow-linux-arm64.tar.gz
artifacts/zebflow-darwin-arm64.tar.gz
artifacts/zebflow-windows-amd64.zip
artifacts/zebflow-checksums.txt
publish-crates:
name: Publish to crates.io
needs: [prepare, release]
runs-on: ubuntu-latest
environment:
name: release
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
publish-npm:
name: Publish to npm
needs: [prepare, release]
runs-on: ubuntu-latest
environment:
name: release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Sync version from tag
working-directory: npm
run: |
VERSION="${{ needs.prepare.outputs.version }}"
VERSION="${VERSION#v}"
npm version "$VERSION" --no-git-tag-version --allow-same-version
- name: Publish
working-directory: npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-pypi:
name: Publish to PyPI
needs: [prepare, release]
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Sync version from tag
working-directory: pip
run: |
VERSION="${{ needs.prepare.outputs.version }}"
VERSION="${VERSION#v}"
sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" zebflow/__init__.py
- name: Build sdist and wheel
working-directory: pip
run: |
pip install build
python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: pip/dist
skip-existing: true