name: Publish
on:
workflow_run:
workflows:
- "Build and Test"
types:
- completed
branches:
- main
env:
CARGO_REGISTRY_TOKEN: "${{ secrets.CARGO_REGISTRY_TOKEN }}"
jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: "Checkout files"
uses: "actions/checkout@v4"
with:
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}
- name: "Configure Git"
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: "Version bump, commit, tag, and publish"
run: |
# Get current version
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{$NF = $NF + 1; print}' OFS=.)
echo "Bumping from $CURRENT_VERSION to $NEW_VERSION"
# Update Cargo.toml
sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" Cargo.toml
cargo check --quiet
# Commit with [skip ci] to prevent loop
git add Cargo.toml Cargo.lock
git commit -m "Release $NEW_VERSION [skip ci]"
# Create and push tag
git tag "v$NEW_VERSION" -m "Release $NEW_VERSION"
git push origin main
git push origin "v$NEW_VERSION"
# Publish to crates.io
cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}