Skip to content

chore: release af-v0.6.1.3 #12

chore: release af-v0.6.1.3

chore: release af-v0.6.1.3 #12

Workflow file for this run

name: AF Release
on:
push:
branches:
- af-main
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
if: "!startsWith(github.event.head_commit.message, 'chore: release')"
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Compute next version
id: version
run: |
# Read current version from pyproject.toml
CURRENT=$(python3 -c "
import tomllib
with open('pyproject.toml', 'rb') as f:
print(tomllib.load(f)['project']['version'])
")
echo "current=$CURRENT" >> $GITHUB_OUTPUT
# Find latest af-v* tag
LATEST_TAG=$(git tag -l 'af-v*' --sort=-version:refname | head -n 1)
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
# Bump fourth segment
IFS='.' read -ra PARTS <<< "$CURRENT"
if [ ${#PARTS[@]} -le 3 ]; then
NEXT="${CURRENT}.1"
else
LAST=${PARTS[3]}
NEXT="${PARTS[0]}.${PARTS[1]}.${PARTS[2]}.$((LAST + 1))"
fi
echo "next=$NEXT" >> $GITHUB_OUTPUT
# Check if this version is already tagged
if git tag -l "af-v${NEXT}" | grep -q .; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Generate changelog
if: steps.version.outputs.skip == 'false'
id: changelog
run: |
LATEST_TAG="${{ steps.version.outputs.latest_tag }}"
NEXT="${{ steps.version.outputs.next }}"
if [ -z "$LATEST_TAG" ]; then
# First release — use commits since the upstream base tag
COMMITS=$(git log --oneline --pretty=format:"- %s" --no-merges v0.6.1..HEAD)
else
COMMITS=$(git log --oneline --pretty=format:"- %s" --no-merges "${LATEST_TAG}..HEAD")
fi
DATE=$(date +%Y-%m-%d)
ENTRY="## ${NEXT} (${DATE})"$'\n\n'"${COMMITS}"
# Write to file for later use (avoids multiline env var issues)
echo "$ENTRY" > /tmp/changelog_entry.txt
echo "date=$DATE" >> $GITHUB_OUTPUT
- name: Check for existing release PR
if: steps.version.outputs.skip == 'false'
id: existing_pr
run: |
PR_NUM=$(gh pr list --repo ${{ github.repository }} \
--head "af-release" --base "af-main" \
--json number --jq '.[0].number // empty')
echo "number=${PR_NUM}" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create or update release branch
if: steps.version.outputs.skip == 'false'
run: |
NEXT="${{ steps.version.outputs.next }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create/reset release branch from af-main
git checkout -B af-release
# Bump version in pyproject.toml
python3 -c "
import re
with open('pyproject.toml', 'r') as f:
content = f.read()
content = re.sub(
r'(version\s*=\s*\")([^\"]+)(\")',
lambda m: m.group(1) + '${NEXT}' + m.group(3),
content,
count=1
)
with open('pyproject.toml', 'w') as f:
f.write(content)
"
# Prepend changelog to FORK.md at the marker
python3 << 'PYEOF'
marker = "<!-- release-please writes changelog entries below this line -->"
with open("/tmp/changelog_entry.txt") as f:
changelog = f.read().strip()
with open("FORK.md", "r") as f:
content = f.read()
if marker in content:
content = content.replace(marker, marker + "\n\n" + changelog)
else:
content += "\n\n" + changelog
with open("FORK.md", "w") as f:
f.write(content)
PYEOF
git add pyproject.toml FORK.md
git commit -m "chore: release af-v${NEXT}"
git push -f origin af-release
- name: Create or update PR
if: steps.version.outputs.skip == 'false'
run: |
NEXT="${{ steps.version.outputs.next }}"
EXISTING="${{ steps.existing_pr.outputs.number }}"
CHANGELOG=$(cat /tmp/changelog_entry.txt)
BODY="$(cat <<EOF
## Release af-v${NEXT}
${CHANGELOG}
---
Merging this PR will trigger a tagged release with extension ZIPs.
EOF
)"
if [ -n "$EXISTING" ]; then
gh pr edit "$EXISTING" \
--title "chore: release af-v${NEXT}" \
--body "$BODY"
echo "Updated PR #${EXISTING}"
else
gh pr create \
--title "chore: release af-v${NEXT}" \
--body "$BODY" \
--head af-release \
--base af-main
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}