Skip to content

Semantic Release

Semantic Release #17

Workflow file for this run

name: Semantic Release
on:
workflow_dispatch:
inputs:
release_type:
description: "Version bump strategy"
required: true
default: auto
type: choice
options:
- auto
- patch
- minor
- major
permissions:
contents: write
actions: write
concurrency:
group: semantic-release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Log trigger context
run: |
echo "event=${GITHUB_EVENT_NAME}"
echo "ref=${GITHUB_REF}"
echo "actor=${GITHUB_ACTOR}"
echo "default_branch=${{ github.event.repository.default_branch }}"
echo "release_type=${{ github.event.inputs.release_type || 'auto' }}"
- uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0
submodules: recursive
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: astral-sh/setup-uv@v5
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Capture release baseline
id: baseline
run: |
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "tag=$(git describe --tags --abbrev=0 2>/dev/null || true)" >> "$GITHUB_OUTPUT"
- name: Run semantic release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TYPE: ${{ github.event.inputs.release_type || 'auto' }}
run: |
if [ "${RELEASE_TYPE}" = "auto" ]; then
uv run --no-project --with python-semantic-release==9.21.1 semantic-release version --no-vcs-release
else
uv run --no-project --with python-semantic-release==9.21.1 semantic-release version --no-vcs-release --"${RELEASE_TYPE}"
fi
- name: Push release commit and tags
run: git push --follow-tags origin HEAD:${{ github.event.repository.default_branch }}
- name: Capture release result
id: release_result
run: |
set -euo pipefail
after_sha=$(git rev-parse HEAD)
after_tag=$(git describe --tags --abbrev=0 2>/dev/null || true)
echo "after_sha=${after_sha}" >> "$GITHUB_OUTPUT"
echo "after_tag=${after_tag}" >> "$GITHUB_OUTPUT"
echo "before_sha=${{ steps.baseline.outputs.sha }}"
echo "after_sha=${after_sha}"
echo "before_tag=${{ steps.baseline.outputs.tag }}"
echo "after_tag=${after_tag}"
if [ "${after_sha}" = "${{ steps.baseline.outputs.sha }}" ] && [ "${after_tag}" = "${{ steps.baseline.outputs.tag }}" ]; then
echo "released=false" >> "$GITHUB_OUTPUT"
echo "No new release generated in this run."
echo "Tip: use release_type=patch/minor/major to force a release when needed."
else
echo "released=true" >> "$GITHUB_OUTPUT"
echo "Release generated. Latest tag: ${after_tag:-none}"
fi
- name: Create GitHub release
if: ${{ steps.release_result.outputs.released == 'true' && startsWith(steps.release_result.outputs.after_tag, 'v') }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_result.outputs.after_tag }}
generate_release_notes: true
- name: Trigger CI release build on new tag
if: ${{ steps.release_result.outputs.released == 'true' && startsWith(steps.release_result.outputs.after_tag, 'v') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
status=$(curl -sS -o /tmp/ci_dispatch_response.json -w "%{http_code}" -X POST \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/CI.yml/dispatches" \
-d "{\"ref\":\"${{ steps.release_result.outputs.after_tag }}\"}")
if [ "${status}" != "204" ]; then
echo "::error::Failed to trigger CI.yml via workflow_dispatch (HTTP ${status})."
cat /tmp/ci_dispatch_response.json
exit 1
fi
echo "Triggered CI.yml on tag ${{ steps.release_result.outputs.after_tag }}"
- name: Skip CI trigger when no release
if: ${{ steps.release_result.outputs.released != 'true' }}
run: echo "Skip CI dispatch because semantic-release produced no new tag."