Skip to content

Merge branch 'main' of https://github.com/Annotation-Garden/HEDit #27

Merge branch 'main' of https://github.com/Annotation-Garden/HEDit

Merge branch 'main' of https://github.com/Annotation-Garden/HEDit #27

Workflow file for this run

name: Auto Release on Main
on:
push:
branches:
- main
paths-ignore:
- '.github/**'
- 'docs/**'
- '**/*.md'
- '.context/**'
- '.rules/**'
- '.serena/**'
permissions:
contents: write
jobs:
auto-release:
name: Auto Version and Release
runs-on: ubuntu-latest
# Skip if commit message contains version bump (avoid loops) or [skip-release]
if: >-
!contains(github.event.head_commit.message, 'Bump version to') &&
!contains(github.event.head_commit.message, '[skip-release]')
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
# Use PAT to bypass branch protection rules
# Create a Fine-grained PAT with 'Contents: Read and write' permission
# and add it as repository secret named RELEASE_PAT
token: ${{ secrets.RELEASE_PAT }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get current version
id: current
run: |
# Extract version from pyproject.toml
VERSION=$(grep -m1 'version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Calculate new alpha version
id: new_version
run: |
VERSION="${{ steps.current.outputs.version }}"
# Parse version components
# Handles: 0.6.5.dev3, 0.6.5a1, 0.6.5.alpha1, 0.6.5
if [[ "$VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+)(\.dev[0-9]+|\.alpha[0-9]+|a[0-9]+|b[0-9]+|rc[0-9]+)?$ ]]; then
BASE="${BASH_REMATCH[1]}"
PRERELEASE="${BASH_REMATCH[2]}"
# Check if already alpha for this base version
LATEST_ALPHA=$(git tag -l "v${BASE}a*" | sort -V | tail -1 || echo "")
if [ -z "$LATEST_ALPHA" ]; then
# No alpha yet, start at a1
NEW_VERSION="${BASE}a1"
else
# Extract alpha number and increment
ALPHA_NUM=$(echo "$LATEST_ALPHA" | sed "s/v${BASE}a//")
NEW_ALPHA=$((ALPHA_NUM + 1))
NEW_VERSION="${BASE}a${NEW_ALPHA}"
fi
else
echo "Unexpected version format: $VERSION"
exit 1
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Update version files
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
# Parse version for __version_info__
# Format: 0.6.7a1 -> (0, 6, 7, "alpha")
MAJOR=$(echo "$NEW_VERSION" | cut -d. -f1)
MINOR=$(echo "$NEW_VERSION" | cut -d. -f2)
PATCH=$(echo "$NEW_VERSION" | cut -d. -f3 | sed 's/[^0-9].*//')
if [[ "$NEW_VERSION" == *"a"* ]]; then
PRERELEASE="alpha"
elif [[ "$NEW_VERSION" == *"b"* ]]; then
PRERELEASE="beta"
elif [[ "$NEW_VERSION" == *"rc"* ]]; then
PRERELEASE="rc"
elif [[ "$NEW_VERSION" == *"dev"* ]]; then
PRERELEASE="dev"
else
PRERELEASE=""
fi
# Update pyproject.toml
sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" pyproject.toml
# Update src/version.py with full exports
cat > src/version.py << PYEOF
"""Version information for HEDit."""
__version__ = "$NEW_VERSION"
__version_info__ = ($MAJOR, $MINOR, $PATCH, "$PRERELEASE")
def get_version() -> str:
"""Get the current version string."""
return __version__
def get_version_info() -> tuple:
"""Get the version info tuple (major, minor, patch, prerelease)."""
return __version_info__
PYEOF
# Fix indentation (remove leading spaces from heredoc)
sed -i 's/^ //' src/version.py
- name: Commit version bump
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
git add pyproject.toml src/version.py
git commit -m "Bump version to $NEW_VERSION"
git push origin main
- name: Create and push tag
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
git tag "v$NEW_VERSION"
git push origin "v$NEW_VERSION"
echo "Created tag: v$NEW_VERSION"