name: Release
on:
push:
branches: [ main ]
tags: [ 'v*' ]
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v0.1.0)'
required: true
type: string
permissions:
contents: write
packages: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust (for manual releases)
if: github.event_name == 'workflow_dispatch'
uses: dtolnay/rust-toolchain@1.85.0
- name: Update Cargo.toml and Cargo.lock version (Manual Release)
if: github.event_name == 'workflow_dispatch'
run: |
NEW_VERSION="${VERSION#v}"
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
cargo update --workspace
env:
VERSION: ${{ github.event.inputs.version }}
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
- name: Generate changelog
run: |
VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}"
git-cliff --tag $VERSION_TAG -o CHANGELOG.md
- name: Get version
id: get_version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ steps.get_version.outputs.version }}
tag_name: ${{ steps.get_version.outputs.version }}
body_path: CHANGELOG.md
draft: false
prerelease: false
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: release
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@1.85.0
- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Verify package
run: cargo package --no-verify
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish