Skip to content

Release

Release #14

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
release_notes:
description: "Release notes"
required: false
default: "New release"
publish_to_crates_io:
description: "Publish to crates.io"
required: true
default: true
type: boolean
jobs:
release:
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.get_next_release.outputs.next_release }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.update_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Get next release number
id: get_next_release
run: |
# Get the latest tag or start with 0 if no tags exist
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0")
latest_num=${latest_tag#v}
next_num=$((latest_num + 1))
echo "next_release=v$next_num" >> $GITHUB_OUTPUT
- name: Update version in Cargo.toml
id: update_version
run: |
# Extract version without 'v' prefix for semantic versioning
version="${{ steps.get_next_release.outputs.next_release }}"
version_number="${version#v}"
# Format as proper semantic version x.0.0
semver_version="$version_number.0.0"
# Update version in Cargo.toml
sed -i "s/^version = \".*\"/version = \"$semver_version\"/" Cargo.toml
echo "version=$semver_version" >> $GITHUB_OUTPUT
# Configure git for commit
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Commit the version change
git add Cargo.toml
git commit -m "Bump version to $semver_version for release"
# Use RELEASE_TOKEN for push
git remote set-url origin https://x-access-token:${{ secrets.RELEASE_TOKEN }}@github.com/${{ github.repository }}
git push
- name: Get binary name from Cargo.toml
id: get_binary_name
run: |
binary_name=$(grep -m 1 "name" Cargo.toml | cut -d '"' -f 2)
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
tag_name: ${{ steps.get_next_release.outputs.next_release }}
release_name: Release ${{ steps.get_next_release.outputs.next_release }}
body: ${{ github.event.inputs.release_notes }}
draft: false
prerelease: false
publish-to-crates-io:
needs: release
if: ${{ github.event.inputs.publish_to_crates_io == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main # Ensure we have the latest commit with version update
token: ${{ secrets.RELEASE_TOKEN }}
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Login to crates.io
uses: actions-rs/cargo@v1
with:
command: login
args: ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: --allow-dirty
build-and-upload:
needs: release
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: linux-amd64
binary_extension: ""
- os: macos-latest
target: x86_64-apple-darwin
name: macos-intel
binary_extension: ""
- os: macos-latest
target: aarch64-apple-darwin
name: macos-arm
binary_extension: ""
- os: windows-latest
target: x86_64-pc-windows-msvc
name: windows-amd64
binary_extension: ".exe"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: main # Ensure we have the latest commit with version update
token: ${{ secrets.RELEASE_TOKEN }}
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Get binary name from Cargo.toml
id: get_binary_name
run: |
binary_name=$(grep -m 1 "name" Cargo.toml | cut -d '"' -f 2)
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
shell: bash
- name: Build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./target/${{ matrix.target }}/release/${{ steps.get_binary_name.outputs.binary_name }}${{ matrix.binary_extension }}
asset_name: ${{ steps.get_binary_name.outputs.binary_name }}-${{ needs.release.outputs.release_tag }}-${{ matrix.name }}${{ matrix.binary_extension }}
asset_content_type: application/octet-stream