name: Publish c2patool binaries
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Build binary
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-latest
artifact_name: c2patool_mac_universal.zip
asset_name: ${{ github.ref_name }}-universal-apple-darwin.zip
sbom_asset_name: ${{ github.ref_name }}-universal-apple-darwin-sbom.json
- os: ubuntu-latest
artifact_name: c2patool_linux_intel.tar.gz
asset_name: ${{ github.ref_name }}-x86_64-unknown-linux-gnu.tar.gz
sbom_asset_name: ${{ github.ref_name }}-x86_64-unknown-linux-gnu-sbom.json
- os: windows-latest
artifact_name: c2patool_win_intel.zip
asset_name: ${{ github.ref_name }}-x86_64-pc-windows-msvc.zip
sbom_asset_name: ${{ github.ref_name }}-x86_64-pc-windows-msvc-sbom.json
steps:
- name: Checkout repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@d1031067263f94b142dd6c0ce24c5eb9d02d52a0 with:
toolchain: stable
components: llvm-tools-preview
- name: Install cargo-sbom
uses: baptiste0928/cargo-install@f204293d9709061b7bc1756fec3ec4e2cd57dec0 with:
crate: cargo-sbom
version: "0.9.1"
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4
- name: Run make release
run: make release
- name: Generate SBOM
run: cargo sbom > c2patool-sbom.json
- name: Stage named artifacts
shell: bash
run: |
mkdir -p dist
cp "target/${{ matrix.artifact_name }}" "dist/${{ matrix.asset_name }}"
cp "c2patool-sbom.json" "dist/${{ matrix.sbom_asset_name }}"
- name: Upload build artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with:
name: c2patool-${{ matrix.os }}
path: dist/
release:
name: Publish c2patool release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c with:
pattern: c2patool-*
path: dist
merge-multiple: true
- name: List artifacts
run: ls -lh dist
- name: Generate release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
TAG="${{ github.ref_name }}"
PREFIX="v"
repo="${{ github.repository }}"
matching=$(gh api --paginate "repos/$repo/git/matching-refs/tags/$PREFIX" \
--jq '.[].ref' | sed 's#refs/tags/##')
sorted=$(printf '%s\n%s\n' "$matching" "$TAG" | sort -V -u)
prev=$(printf '%s\n' "$sorted" | { grep -F -x -B1 -- "$TAG" || true; } | head -n1)
[ "$prev" = "$TAG" ] && prev=""
if [ -n "$prev" ]; then
echo "Previous $PREFIX tag: $prev"
gh api "repos/$repo/releases/generate-notes" \
-f tag_name="$TAG" -f previous_tag_name="$prev" --jq .body > release-notes.md
else
echo "No previous $PREFIX tag; letting GitHub choose the range."
gh api "repos/$repo/releases/generate-notes" \
-f tag_name="$TAG" --jq .body > release-notes.md
fi
echo "----- release notes -----"; cat release-notes.md
- name: Publish GitHub release
uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b with:
tag_name: ${{ github.ref_name }}
target_commitish: ${{ github.sha }}
body_path: release-notes.md
files: dist/*
draft: false
prerelease: ${{ contains(github.ref_name, '-rc.') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}