name: Release CLI
on:
push:
tags:
- "cli-v*"
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g., 0.1.0)"
required: true
env:
CARGO_TERM_COLOR: always
BINARY_NAME: statespace
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { target: x86_64-apple-darwin, os: macos-14 }
- { target: aarch64-apple-darwin, os: macos-14 }
- { target: x86_64-unknown-linux-gnu, os: blacksmith-4vcpu-ubuntu-2204 }
- { target: aarch64-unknown-linux-gnu, os: blacksmith-4vcpu-ubuntu-2204, cross: true }
- { target: x86_64-unknown-linux-musl, os: blacksmith-4vcpu-ubuntu-2204 }
- { target: aarch64-unknown-linux-musl, os: blacksmith-4vcpu-ubuntu-2204, cross: true }
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Install musl tools
if: contains(matrix.target, 'musl') && !matrix.cross
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Build binary
run: |
if [ "${{ matrix.cross }}" = "true" ]; then
cross build --release --target ${{ matrix.target }} -p statespace-cli
else
cargo build --release --target ${{ matrix.target }} -p statespace-cli
fi
- name: Package binary
run: |
VERSION="${GITHUB_REF_NAME#cli-v}"
[ -n "${{ inputs.version }}" ] && VERSION="${{ inputs.version }}"
ARCHIVE="${BINARY_NAME}-v${VERSION}-${{ matrix.target }}"
mkdir -p "dist/${ARCHIVE}"
cp "target/${{ matrix.target }}/release/${BINARY_NAME}" "dist/${ARCHIVE}/"
cd dist
tar -czvf "${ARCHIVE}.tar.gz" "${ARCHIVE}"
if command -v sha256sum &>/dev/null; then
sha256sum "${ARCHIVE}.tar.gz" > "${ARCHIVE}.tar.gz.sha256"
else
shasum -a 256 "${ARCHIVE}.tar.gz" > "${ARCHIVE}.tar.gz.sha256"
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist/*.tar.gz*
release:
name: Create Release
needs: build
runs-on: blacksmith-4vcpu-ubuntu-2204
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release
find artifacts -name "*.tar.gz*" -exec mv {} release/ \;
- name: Generate manifest
run: |
VERSION="${GITHUB_REF_NAME#cli-v}"
[ -n "${{ inputs.version }}" ] && VERSION="${{ inputs.version }}"
cd release
echo "{\"version\":\"${VERSION}\",\"binaries\":{" > manifest.json
first=true
for sha_file in *.sha256; do
[ "$first" = false ] && echo "," >> manifest.json
first=false
archive="${sha_file%.sha256}"
checksum=$(cut -d' ' -f1 "$sha_file")
target="${archive#statespace-v${VERSION}-}"
target="${target%.tar.gz}"
printf '"%s":{"archive":"%s","sha256":"%s"}' "$target" "$archive" "$checksum" >> manifest.json
done
echo "}}" >> manifest.json
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: release/*
generate_release_notes: true
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}