Skip to content

Refactor release workflow to improve tag handling #2

Refactor release workflow to improve tag handling

Refactor release workflow to improve tag handling #2

name: Bump Version and Test
on:
push:
branches: [ "main" ]
workflow_dispatch:
inputs:
version:
required: true
type: string
description: 'Version to deploy (e.g., 1.0.0)'
env:
CARGO_TERM_COLOR: always
jobs:
update_version:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
previous_tag: ${{ steps.tag_version.outputs.previous_tag }}
changelog: ${{ steps.tag_version.outputs.changelog }}
steps:
- name: Validate Input Version
if: github.event_name == 'workflow_dispatch'
run: |
if [[ ! "${{ github.event.inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid format. Expected X.Y.Z"
exit 1
fi
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b
with:
dry_run: true
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ github.event.inputs.version }}
- name: Apply Updated Version to Cargo.toml
run: |
sed -i -r 's/^version = "[0-9]+.[0-9]+.[0-9]+"$/version = "${{ steps.tag_version.outputs.new_version }}"/' Cargo.toml
cat -e Cargo.toml
cargo publish --dry-run --allow-dirty
- uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
commit_message: "sync version in Cargo.toml to ${{ steps.tag_version.outputs.new_version }}"
build-and-test:
needs: update_version
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
- os: macos-15
target: aarch64-apple-darwin
- os: macos-15-intel
target: x86_64-apple-darwin
- os: windows-2025
target: x86_64-pc-windows-msvc
- os: windows-11-arm
target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ needs.update_version.outputs.new_tag }}
- name: Setup Rust Toolchain for GitHub CI
uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606
with:
# Comma-separated list of Rust toolchain specifications. Last version becomes the default. -- see https://rust-lang.github.io/rustup/concepts/toolchains.html#toolchain-specification
toolchain: # optional
target: ${{ matrix.target }} # optional
components: # optional
rustflags: # optional, default is -D warnings
# Setup the last installed toolchain as the default via `rustup override`
override: # optional, default is true
- name: Test
run: cargo test --verbose