|
| 1 | +name: AF Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - af-main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v6 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + fetch-tags: true |
| 21 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + - name: Setup Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: "3.11" |
| 27 | + |
| 28 | + - name: Compute next version |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + # Read current version from pyproject.toml |
| 32 | + CURRENT=$(python3 -c " |
| 33 | + import tomllib |
| 34 | + with open('pyproject.toml', 'rb') as f: |
| 35 | + print(tomllib.load(f)['project']['version']) |
| 36 | + ") |
| 37 | + echo "current=$CURRENT" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + # Find latest af-v* tag |
| 40 | + LATEST_TAG=$(git tag -l 'af-v*' --sort=-version:refname | head -n 1) |
| 41 | + echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 42 | +
|
| 43 | + # Bump fourth segment |
| 44 | + IFS='.' read -ra PARTS <<< "$CURRENT" |
| 45 | + if [ ${#PARTS[@]} -le 3 ]; then |
| 46 | + NEXT="${CURRENT}.1" |
| 47 | + else |
| 48 | + LAST=${PARTS[3]} |
| 49 | + NEXT="${PARTS[0]}.${PARTS[1]}.${PARTS[2]}.$((LAST + 1))" |
| 50 | + fi |
| 51 | + echo "next=$NEXT" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + # Check if this version is already tagged |
| 54 | + if git tag -l "af-v${NEXT}" | grep -q .; then |
| 55 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 56 | + else |
| 57 | + echo "skip=false" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Generate changelog |
| 61 | + if: steps.version.outputs.skip == 'false' |
| 62 | + id: changelog |
| 63 | + run: | |
| 64 | + LATEST_TAG="${{ steps.version.outputs.latest_tag }}" |
| 65 | + NEXT="${{ steps.version.outputs.next }}" |
| 66 | +
|
| 67 | + if [ -z "$LATEST_TAG" ]; then |
| 68 | + # First release — use commits since the upstream base tag |
| 69 | + COMMITS=$(git log --oneline --pretty=format:"- %s" --no-merges v0.6.1..HEAD) |
| 70 | + else |
| 71 | + COMMITS=$(git log --oneline --pretty=format:"- %s" --no-merges "${LATEST_TAG}..HEAD") |
| 72 | + fi |
| 73 | +
|
| 74 | + DATE=$(date +%Y-%m-%d) |
| 75 | + ENTRY="## ${NEXT} (${DATE})"$'\n\n'"${COMMITS}" |
| 76 | +
|
| 77 | + # Write to file for later use (avoids multiline env var issues) |
| 78 | + echo "$ENTRY" > /tmp/changelog_entry.txt |
| 79 | + echo "date=$DATE" >> $GITHUB_OUTPUT |
| 80 | +
|
| 81 | + - name: Check for existing release PR |
| 82 | + if: steps.version.outputs.skip == 'false' |
| 83 | + id: existing_pr |
| 84 | + run: | |
| 85 | + PR_NUM=$(gh pr list --repo ${{ github.repository }} \ |
| 86 | + --head "af-release" --base "af-main" \ |
| 87 | + --json number --jq '.[0].number // empty') |
| 88 | + echo "number=${PR_NUM}" >> $GITHUB_OUTPUT |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + |
| 92 | + - name: Create or update release branch |
| 93 | + if: steps.version.outputs.skip == 'false' |
| 94 | + run: | |
| 95 | + NEXT="${{ steps.version.outputs.next }}" |
| 96 | +
|
| 97 | + git config user.name "github-actions[bot]" |
| 98 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 99 | +
|
| 100 | + # Create/reset release branch from af-main |
| 101 | + git checkout -B af-release |
| 102 | +
|
| 103 | + # Bump version in pyproject.toml |
| 104 | + python3 -c " |
| 105 | + import re |
| 106 | + with open('pyproject.toml', 'r') as f: |
| 107 | + content = f.read() |
| 108 | + content = re.sub( |
| 109 | + r'(version\s*=\s*\")([^\"]+)(\")', |
| 110 | + lambda m: m.group(1) + '${NEXT}' + m.group(3), |
| 111 | + content, |
| 112 | + count=1 |
| 113 | + ) |
| 114 | + with open('pyproject.toml', 'w') as f: |
| 115 | + f.write(content) |
| 116 | + " |
| 117 | +
|
| 118 | + # Prepend changelog to FORK.md at the marker |
| 119 | + python3 << 'PYEOF' |
| 120 | + marker = "<!-- release-please writes changelog entries below this line -->" |
| 121 | + with open("/tmp/changelog_entry.txt") as f: |
| 122 | + changelog = f.read().strip() |
| 123 | + with open("FORK.md", "r") as f: |
| 124 | + content = f.read() |
| 125 | + if marker in content: |
| 126 | + content = content.replace(marker, marker + "\n\n" + changelog) |
| 127 | + else: |
| 128 | + content += "\n\n" + changelog |
| 129 | + with open("FORK.md", "w") as f: |
| 130 | + f.write(content) |
| 131 | + PYEOF |
| 132 | +
|
| 133 | + git add pyproject.toml FORK.md |
| 134 | + git commit -m "chore: release af-v${NEXT}" |
| 135 | + git push -f origin af-release |
| 136 | +
|
| 137 | + - name: Create or update PR |
| 138 | + if: steps.version.outputs.skip == 'false' |
| 139 | + run: | |
| 140 | + NEXT="${{ steps.version.outputs.next }}" |
| 141 | + EXISTING="${{ steps.existing_pr.outputs.number }}" |
| 142 | + CHANGELOG=$(cat /tmp/changelog_entry.txt) |
| 143 | +
|
| 144 | + BODY="$(cat <<EOF |
| 145 | + ## Release af-v${NEXT} |
| 146 | +
|
| 147 | + ${CHANGELOG} |
| 148 | +
|
| 149 | + --- |
| 150 | + Merging this PR will trigger a tagged release with extension ZIPs. |
| 151 | + EOF |
| 152 | + )" |
| 153 | +
|
| 154 | + if [ -n "$EXISTING" ]; then |
| 155 | + gh pr edit "$EXISTING" \ |
| 156 | + --title "chore: release af-v${NEXT}" \ |
| 157 | + --body "$BODY" |
| 158 | + echo "Updated PR #${EXISTING}" |
| 159 | + else |
| 160 | + gh pr create \ |
| 161 | + --title "chore: release af-v${NEXT}" \ |
| 162 | + --body "$BODY" \ |
| 163 | + --head af-release \ |
| 164 | + --base af-main |
| 165 | + fi |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments