name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag to build (e.g. v0.1.0)"
required: true
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BIN_NAME: responses-proxy
jobs:
build:
name: build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
- target: aarch64-pc-windows-msvc
os: windows-11-arm
archive: zip
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.ref }}
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: Show toolchain
run: rustc -V && cargo -V
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package (unix)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
tag="${GITHUB_REF_NAME:-${{ inputs.tag }}}"
name="${BIN_NAME}-${tag}-${{ matrix.target }}"
mkdir "$name"
cp "target/${{ matrix.target }}/release/${BIN_NAME}" "$name/"
cp README.md LICENSE config.yaml "$name/"
tar -czf "$name.tar.gz" "$name"
shasum -a 256 "$name.tar.gz" > "$name.tar.gz.sha256"
echo "ASSET=$name.tar.gz" >> "$GITHUB_ENV"
echo "ASSET_SHA=$name.tar.gz.sha256" >> "$GITHUB_ENV"
- name: Package (windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$tag = if ($env:GITHUB_REF_NAME) { $env:GITHUB_REF_NAME } else { "${{ inputs.tag }}" }
$name = "${env:BIN_NAME}-$tag-${{ matrix.target }}"
New-Item -ItemType Directory -Path $name | Out-Null
Copy-Item "target/${{ matrix.target }}/release/${env:BIN_NAME}.exe" "$name/"
Copy-Item README.md, LICENSE, config.yaml "$name/"
Compress-Archive -Path $name -DestinationPath "$name.zip"
(Get-FileHash "$name.zip" -Algorithm SHA256).Hash.ToLower() + " $name.zip" | Out-File -Encoding ascii "$name.zip.sha256"
"ASSET=$name.zip" | Out-File -Append -Encoding ascii $env:GITHUB_ENV
"ASSET_SHA=$name.zip.sha256" | Out-File -Append -Encoding ascii $env:GITHUB_ENV
- name: Upload to GitHub Release
if: startsWith(github.ref, 'refs/tags/v') || inputs.tag != ''
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.tag || github.ref_name }}
files: |
${{ env.ASSET }}
${{ env.ASSET_SHA }}