Skip to content

Release

Release #1

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.5.0)"
required: true
type: string
dry_run:
description: "Preview without making changes"
required: false
type: boolean
default: false
jobs:
release:
if: github.repository == 'EndstoneMC/python-example-plugin'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Validate version
run: |
VERSION="${{ inputs.version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version format: $VERSION (expected X.Y.Z)"
exit 1
fi
if git tag -l "v$VERSION" | grep -q .; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Extract unreleased changelog
run: |
BODY=$(sed -n '/^## \[Unreleased\]/,/^## \[/{/^## \[/d; p}' CHANGELOG.md)
BODY=$(echo "$BODY" | sed '/./,$!d' | sed -e :a -e '/^\n*$/{$d;N;ba}')
if [ -z "$BODY" ]; then
echo "::error::Unreleased section in CHANGELOG.md is empty"
exit 1
fi
echo "$BODY" > /tmp/release_body.md
echo "Extracted changelog:"
echo "$BODY"
- name: Preview
if: inputs.dry_run
run: |
DATE=$(date -u +%Y-%m-%d)
echo "=== Dry Run ==="
echo "Version: $VERSION"
echo "Tag: v$VERSION"
echo "Date: $DATE"
echo ""
echo "=== Release Body ==="
cat /tmp/release_body.md
echo ""
echo "=== CHANGELOG.md will become ==="
echo "## [Unreleased]"
echo ""
echo "## [$VERSION] - $DATE"
- name: Update CHANGELOG.md
if: ${{ !inputs.dry_run }}
run: |
DATE=$(date -u +%Y-%m-%d)
sed -i "s/^## \[Unreleased\]/## [Unreleased]\n\n## [$VERSION] - $DATE/" CHANGELOG.md
- name: Commit and tag
if: ${{ !inputs.dry_run }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "Release $VERSION"
git tag "v$VERSION"
- name: Push
if: ${{ !inputs.dry_run }}
run: |
git push origin main
git push origin "v$VERSION"
- name: Create GitHub release
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ github.token }}
run: |
PREV_TAG=$(git tag --sort=-v:refname | sed -n '2p')
if [ -n "$PREV_TAG" ]; then
printf '\n**Full Changelog**: https://github.com/%s/compare/%s...v%s\n' \
"${{ github.repository }}" "$PREV_TAG" "$VERSION" >> /tmp/release_body.md
fi
gh release create "v$VERSION" \
--title "v$VERSION" \
--notes-file /tmp/release_body.md
build:
if: ${{ !inputs.dry_run }}
needs: [ release ]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.10"
- name: Install
run: uv sync --extra dev
- name: Lint
run: uv run ruff check src/
publish:
needs: [ build ]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
ref: v${{ inputs.version }}
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@v7
- name: Build
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Attach wheel to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "v${{ inputs.version }}" dist/*.whl