forked from github/spec-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (144 loc) · 5.25 KB
/
af-release.yml
File metadata and controls
168 lines (144 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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 }}