name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
container: rockylinux:9
steps:
- name: Install system dependencies
run: dnf install -y gcc pkg-config systemd-devel jq git
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Verify tag matches Cargo.toml version
run: |
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} does not match Cargo.toml version ${CARGO_VERSION}. Bump Cargo.toml before tagging."
exit 1
fi
- name: Install cargo-deb and cargo-generate-rpm
run: |
cargo install cargo-deb
cargo install cargo-generate-rpm
- name: Build release binary
run: cargo build --release --locked
- name: Build Debian package
run: cargo deb
- name: Build RPM package
run: cargo generate-rpm
- name: Collect artifacts and generate checksums
run: |
mkdir -p dist/rgm artifacts
cp target/release/rgm LICENSE-MIT LICENSE-APACHE README.md dist/rgm/
tar -czf artifacts/rgm-linux-x86_64.tar.gz -C dist rgm
cp target/debian/*.deb target/generate-rpm/*.rpm artifacts/
cd artifacts && sha256sum * > SHA256SUMS
- name: Create Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
name: RGM ${{ github.ref_name }}
body_path: .github/release-template.md
generate_release_notes: true
files: artifacts/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "::warning::CARGO_REGISTRY_TOKEN is not set; skipping crates.io publish"
exit 0
fi
cargo publish --locked