name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Existing tag to release, e.g. v0.2.0"
required: true
type: string
permissions:
contents: write
env:
BIN_NAME: rkg
CARGO_TERM_COLOR: always
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: cargo test
build:
name: Build ${{ matrix.name }}
needs: test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive_ext: tar.gz
- name: macos-aarch64
os: macos-14
target: aarch64-apple-darwin
archive_ext: tar.gz
- name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
archive_ext: zip
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build release binary
run: cargo build --locked --release --target ${{ matrix.target }}
- name: Package archive (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
tag="${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}"
version="${tag#v}"
asset="${BIN_NAME}-${version}-${{ matrix.target }}"
mkdir -p dist
cp "target/${{ matrix.target }}/release/${BIN_NAME}" "dist/${BIN_NAME}"
tar -C dist -czf "${asset}.tar.gz" "${BIN_NAME}"
shasum -a 256 "${asset}.tar.gz" > "${asset}.tar.gz.sha256"
- name: Package archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$tag = "${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}"
$version = $tag.TrimStart('v')
$asset = "${env:BIN_NAME}-$version-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path dist | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${env:BIN_NAME}.exe" "dist/${env:BIN_NAME}.exe"
Compress-Archive -Path "dist/${env:BIN_NAME}.exe" -DestinationPath "$asset.zip" -Force
$hash = (Get-FileHash "$asset.zip" -Algorithm SHA256).Hash.ToLower()
"$hash $asset.zip" | Out-File "$asset.zip.sha256" -Encoding ascii
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: |
*.${{ matrix.archive_ext }}
*.${{ matrix.archive_ext }}.sha256
publish:
name: Publish Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Collect release files
shell: bash
run: |
set -euo pipefail
mkdir -p release-assets
find artifacts -type f -maxdepth 2 -exec cp {} release-assets/ \;
- name: Create or update release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
files: release-assets/*
generate_release_notes: true