Skip to content

Release

Release #15

Workflow file for this run

# Build cross-platform binaries + Windows MSI, publish to GitHub Releases.
# Trigger: push a tag like v0.1.0, or run manually via workflow_dispatch.
name: Release
on:
push:
tags: ['v[0-9]+.[0-9]+.[0-9]+*']
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v0.1.0)'
required: true
type: string
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BINARY_NAME: forgeStat
jobs:
build:
name: Build ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux x86_64
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- name: macOS x86_64
target: x86_64-apple-darwin
os: macos-latest
- name: macOS ARM64
target: aarch64-apple-darwin
os: macos-latest
- name: Windows x86_64
target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
- name: Determine version tag
id: meta
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package tar.gz (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
staging="${{ env.BINARY_NAME }}-${{ steps.meta.outputs.tag }}-${{ matrix.target }}"
mkdir "$staging"
cp "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}" "$staging/"
tar czf "$staging.tar.gz" "$staging"
- name: Package ZIP (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$staging = "${{ env.BINARY_NAME }}-${{ steps.meta.outputs.tag }}-${{ matrix.target }}"
New-Item -ItemType Directory -Path $staging | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" "$staging/"
Compress-Archive -Path "$staging/*" -DestinationPath "$staging.zip"
- name: Build MSI installer (Windows)
if: runner.os == 'Windows'
continue-on-error: true
shell: pwsh
run: |
cargo install cargo-wix
cargo wix --no-build --target ${{ matrix.target }} --output .
Get-ChildItem *.msi | ForEach-Object {
$newName = "${{ env.BINARY_NAME }}-${{ steps.meta.outputs.tag }}-${{ matrix.target }}.msi"
Rename-Item $_.FullName $newName
Write-Host "Created MSI: $newName"
}
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.target }}
path: |
*.tar.gz
*.zip
*.msi
if-no-files-found: error
publish:
name: Publish GitHub Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Determine version tag
id: meta
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
fi
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
path: dist/
pattern: release-*
merge-multiple: true
- name: Prepare release assets
shell: bash
run: |
cp scripts/install.sh dist/install.sh
cp scripts/install.ps1 dist/install.ps1
chmod +x dist/install.sh
cd dist && sha256sum *.tar.gz *.zip *.msi 2>/dev/null > SHA256SUMS.txt || true
echo "=== Release assets ==="
ls -lh dist/
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
tag="${{ steps.meta.outputs.tag }}"
if ! gh release view "$tag" &>/dev/null; then
gh release create "$tag" --title "forgeStat $tag" --generate-notes
fi
for f in dist/*; do
echo "Uploading $(basename "$f")..."
gh release upload "$tag" "$f" --clobber
done