name: Action Release
on:
push:
tags:
- "v*.*"
release:
types: [published]
permissions:
contents: write
jobs:
release:
name: Maintain the action release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check the tag is an action release
id: check
run: |
manifest="$(grep -m1 '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')"
tag="${GITHUB_REF_NAME#v}"
if [ "$tag" = "$manifest" ]; then
echo "tag $GITHUB_REF_NAME is the crate version $manifest; the Release workflow owns it"
echo "action=false" >> "$GITHUB_OUTPUT"
else
echo "action=true" >> "$GITHUB_OUTPUT"
fi
- name: Create the release
if: github.event_name == 'push' && steps.check.outputs.action == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "${GITHUB_REF_NAME}" --verify-tag --generate-notes
- name: Move the major tag
if: steps.check.outputs.action == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
major="${GITHUB_REF_NAME#v}"
major="${major%%.*}"
url="repos/${GITHUB_REPOSITORY}/git/refs/tags/v${major}"
if gh api "$url" >/dev/null 2>&1; then
gh api "$url" -X PATCH -f "sha=${GITHUB_SHA}" -F "force=true"
else
gh api "repos/${GITHUB_REPOSITORY}/git/refs" -X POST -f "ref=refs/tags/v${major}" -f "sha=${GITHUB_SHA}"
fi