Release #58
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Release | |
on: | |
workflow_dispatch: | |
env: | |
CARGO_TERM_COLOR: always | |
REGISTRY: crates.io | |
jobs: | |
github_release: | |
name: GitHub Release | |
runs-on: ubuntu-24.04 | |
permissions: | |
contents: write | |
issues: write | |
pull-requests: write | |
outputs: | |
new_release_version: ${{ steps.semantic.outputs.new_release_version }} | |
new_release_published: ${{ steps.semantic.outputs.new_release_published }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Configure Git signing | |
run: | | |
echo "${{ secrets.BOT_GPG_PRIVATE_KEY }}" | gpg --import | |
git config --global user.signingkey ${{ secrets.BOT_GPG_KEY_ID }} | |
git config --global commit.gpgsign true | |
git config --global commit.signoff true | |
git config --global user.name 'GitHub Actions Bot' | |
git config --global user.email '[email protected]' | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "lts/*" | |
- name: Install semantic release and plugins | |
run: | | |
npm install -g [email protected] \ | |
conventional-changelog-cli \ | |
conventional-changelog-conventionalcommits \ | |
@semantic-release/changelog \ | |
@semantic-release/exec \ | |
@semantic-release/git \ | |
@semantic-release/github | |
- name: Create a release if needed | |
id: semantic | |
env: | |
CI: true | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GIT_AUTHOR_NAME: "GitHub Actions Bot" | |
GIT_AUTHOR_EMAIL: "[email protected]" | |
GIT_COMMITTER_NAME: "GitHub Actions Bot" | |
GIT_COMMITTER_EMAIL: "[email protected]" | |
run: | | |
# Create first release if not exists using gh cli - Initial Release Version 0.1.0 | |
# This is an HACK because semantic release doesn't support versions under 1.0.0 | |
# But if we already have a release then it respects it and start to increment from there | |
if ! gh release view 0.1.0 >/dev/null 2>&1; then | |
gh release create 0.1.0 --title "Initial Release" --notes "Initial Release" --target main | |
fi | |
# Run semantic-release in dry-run first to capture version | |
DRY_OUTPUT=$(semantic-release --dry-run 2>&1 || true) | |
# Check if there are no changes | |
if $(echo "$DRY_OUTPUT" | grep -q "no new version is released"); then | |
echo "No new release needed" | |
echo "new_release_published=false" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
# Extract version from dry run output | |
VERSION=$(echo "$DRY_OUTPUT" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?" | cut -d ' ' -f6) | |
if [ -z "$VERSION" ]; then | |
echo "Error: Could not determine version" | |
exit 1 | |
fi | |
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT | |
# Run actual release | |
if semantic-release; then | |
echo "Successfully released version $VERSION" | |
echo "new_release_published=true" >> $GITHUB_OUTPUT | |
else | |
echo "Release failed" | |
exit 1 | |
fi | |
publish: | |
needs: github_release | |
runs-on: ubuntu-24.04 | |
if: needs.github_release.outputs.new_release_published == 'true' | |
name: Publish | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
- name: Cache dependencies | |
uses: Swatinem/rust-cache@v2 | |
- name: Update Cargo.toml version | |
run: | | |
echo "Updating to version ${{ needs.github_release.outputs.new_release_version }}" | |
sed -i "s/^version = .*/version = \"${{ needs.github_release.outputs.new_release_version }}\"/" Cargo.toml | |
- name: Build | |
run: cargo build --verbose --release | |
- name: Publish to crates.io | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
run: cargo publish |