Skip to content

Release

Release #1

Workflow file for this run

name: Release
on:
workflow_run:
workflows: ["CI"]
types: [completed]
permissions:
contents: write
actions: read
jobs:
release:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
runs-on: ubuntu-latest
steps:
- name: Determine Release Tag From Commit Message
id: tag
shell: bash
run: |
set -euo pipefail
msg="$(jq -r '.workflow_run.head_commit.message // ""' "$GITHUB_EVENT_PATH")"
if [[ "$msg" =~ \[release[[:space:]]+v?([0-9]+\.[0-9]+\.[0-9]+)\] ]]; then
echo "release_tag=v${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
else
echo "No [release vX.Y.Z] token found; skipping release."
echo "release_tag=" >> "$GITHUB_OUTPUT"
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
- name: Checkout Repository
if: ${{ steps.tag.outputs.should_release == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download CI Artifacts
if: ${{ steps.tag.outputs.should_release == 'true' }}
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
path: release-assets
merge-multiple: true
- name: Create and Push Tag
if: ${{ steps.tag.outputs.should_release == 'true' }}
env:
RELEASE_TAG: ${{ steps.tag.outputs.release_tag }}
RELEASE_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
set -euo pipefail
git fetch --tags
if git rev-parse -q --verify "refs/tags/${RELEASE_TAG}" >/dev/null; then
echo "Tag ${RELEASE_TAG} already exists"
else
git tag -a "${RELEASE_TAG}" "${RELEASE_SHA}" -m "Release ${RELEASE_TAG}"
git push origin "${RELEASE_TAG}"
fi
- name: Create GitHub Release
if: ${{ steps.tag.outputs.should_release == 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
target_commitish: ${{ github.event.workflow_run.head_sha }}
generate_release_notes: true
files: release-assets/*.tar.gz