name: Publish and tag
on:
workflow_run:
workflows: ["Build and test"]
branches: [main]
types:
- completed
env:
CARGO_TERM_COLOR: always
jobs:
push-tag:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-tags: true
- id: make_tag
name: Make tag
run: |
VERSION="$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')"
if [ -z "$(git tag -l "v$VERSION")" ]; then
echo "Making new tag"
git tag v$VERSION HEAD
git push --tags
echo "new_tag=1" >> "$GITHUB_OUTPUT"
fi
outputs:
new_tag: ${{ steps.make_tag.outputs.new_tag }}
release:
runs-on: ubuntu-latest
needs: push-tag
if: needs.push-tag.outputs.new_tag
steps:
- uses: actions/checkout@v6
- name: publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo publish --locked