name: Build and Publish Binaries
on:
workflow_dispatch:
inputs:
tag:
description: "Existing GitHub Release tag (for example v0.2.2)"
required: true
type: string
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
env:
RELEASE_TAG: ${{ inputs.tag }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
archive: tar.gz
- os: macos-14
target: aarch64-apple-darwin
archive: tar.gz
- os: macos-13
target: x86_64-apple-darwin
archive: tar.gz
- os: windows-2022
target: x86_64-pc-windows-msvc
archive: zip
steps:
- name: Check out release tag
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build release binary
run: cargo build --locked --release --target "${{ matrix.target }}"
- name: Package Unix binary
if: matrix.archive == 'tar.gz'
shell: bash
run: |
set -euo pipefail
version="${RELEASE_TAG#v}"
name="rload-${version}-${{ matrix.target }}"
mkdir "$name"
cp "target/${{ matrix.target }}/release/rload" "$name/rload"
cp README.md LICENSE-MIT LICENSE-APACHE "$name/"
tar -czf "$name.tar.gz" "$name"
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$name.tar.gz" > "$name.tar.gz.sha256"
else
shasum -a 256 "$name.tar.gz" > "$name.tar.gz.sha256"
fi
- name: Package Windows binary
if: matrix.archive == 'zip'
shell: pwsh
run: |
$version = $env:RELEASE_TAG.TrimStart('v')
$name = "rload-$version-${{ matrix.target }}"
New-Item -ItemType Directory -Path $name | Out-Null
Copy-Item "target/${{ matrix.target }}/release/rload.exe" "$name/rload.exe"
Copy-Item README.md,LICENSE-MIT,LICENSE-APACHE $name
Compress-Archive -Path $name -DestinationPath "$name.zip"
$hash = (Get-FileHash "$name.zip" -Algorithm SHA256).Hash.ToLower()
"$hash $name.zip" | Set-Content "$name.zip.sha256"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.target }}
path: |
*.tar.gz
*.tar.gz.sha256
*.zip
*.zip.sha256
publish:
name: Upload binaries to Release
needs: build
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ inputs.tag }}
steps:
- name: Verify target Release exists
env:
GH_TOKEN: ${{ github.token }}
run: gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*
path: dist
merge-multiple: true
- name: Upload precompiled binaries
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "$RELEASE_TAG" dist/* --repo "$GITHUB_REPOSITORY" --clobber