-
Notifications
You must be signed in to change notification settings - Fork 0
280 lines (242 loc) · 12.5 KB
/
tag-release.yml
File metadata and controls
280 lines (242 loc) · 12.5 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
name: Claude Tag Release
on:
workflow_call:
inputs:
branch_ref:
description: 'The branch ref to tag'
required: true
type: string
outputs:
tag_name:
description: 'The created tag name'
value: ${{ jobs.tag.outputs.tag_name }}
version:
description: 'The version number'
value: ${{ jobs.tag.outputs.version }}
release_url:
description: 'The GitHub release URL'
value: ${{ jobs.tag.outputs.release_url }}
secrets:
ANTHROPIC_API_KEY:
required: true
jobs:
tag:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
outputs:
tag_name: ${{ steps.get-version.outputs.tag_name }}
version: ${{ steps.get-version.outputs.version }}
release_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch_ref }}
# ACTIONS_TOKEN required to push tags to protected repo
token: ${{ secrets.ACTIONS_TOKEN || github.token }}
fetch-depth: 0
- name: Get Version from pyproject.toml
id: get-version
run: |
VERSION=$(grep "^version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_name=v$VERSION" >> $GITHUB_OUTPUT
echo "Found version: $VERSION"
- name: Check If Tag Exists
id: check-tag
run: |
if [ $(git tag -l "v${{ steps.get-version.outputs.version }}") ]; then
echo "tag_exists=true" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.get-version.outputs.version }} already exists"
else
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "Tag v${{ steps.get-version.outputs.version }} does not exist yet"
fi
- name: Analyze changes since last release
if: steps.check-tag.outputs.tag_exists == 'false'
id: analyze-changes
run: |
VERSION="${{ steps.get-version.outputs.version }}"
# Get the last release tag
LAST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ -z "$LAST_TAG" ]; then
echo "No previous release found, analyzing all commits"
LAST_TAG="initial"
# For initial release, use different commands that don't require a range
FILES_CHANGED=$(git ls-files | wc -l)
COMMITS_COUNT=$(git rev-list --count HEAD)
# Get stats by diffing empty tree against HEAD
EMPTY_TREE=$(git hash-object -t tree /dev/null)
ADDITIONS=$(git diff --shortstat "$EMPTY_TREE" HEAD | grep -oE '[0-9]+ insertions?' | grep -oE '[0-9]+' || echo "0")
DELETIONS=$(git diff --shortstat "$EMPTY_TREE" HEAD | grep -oE '[0-9]+ deletions?' | grep -oE '[0-9]+' || echo "0")
COMMIT_MESSAGES=$(git log --oneline --no-color HEAD | head -30)
DETAILED_CHANGES=$(git diff --name-status --no-color "$EMPTY_TREE" HEAD | head -50)
PR_REFS=$(git log --oneline --no-color HEAD | grep -oE '#[0-9]+' | sort -u | head -10 || echo "")
else
echo "Analyzing changes since last release: $LAST_TAG"
# Use explicit two-commit diff syntax instead of range syntax
FILES_CHANGED=$(git diff --name-only "$LAST_TAG" HEAD | wc -l)
COMMITS_COUNT=$(git rev-list --count "$LAST_TAG"..HEAD)
ADDITIONS=$(git diff --shortstat "$LAST_TAG" HEAD | grep -oE '[0-9]+ insertions?' | grep -oE '[0-9]+' || echo "0")
DELETIONS=$(git diff --shortstat "$LAST_TAG" HEAD | grep -oE '[0-9]+ deletions?' | grep -oE '[0-9]+' || echo "0")
COMMIT_MESSAGES=$(git log --oneline --no-color "$LAST_TAG"..HEAD | head -30)
DETAILED_CHANGES=$(git diff --name-status --no-color "$LAST_TAG" HEAD | head -50)
PR_REFS=$(git log --oneline --no-color "$LAST_TAG"..HEAD | grep -oE '#[0-9]+' | sort -u | head -10 || echo "")
fi
# Save outputs
echo "last_tag=$LAST_TAG" >> $GITHUB_OUTPUT
echo "files_changed=$FILES_CHANGED" >> $GITHUB_OUTPUT
echo "commits_count=$COMMITS_COUNT" >> $GITHUB_OUTPUT
echo "additions=$ADDITIONS" >> $GITHUB_OUTPUT
echo "deletions=$DELETIONS" >> $GITHUB_OUTPUT
# Save multiline outputs
{
echo "commit_messages<<EOF"
echo "$COMMIT_MESSAGES"
echo "EOF"
} >> $GITHUB_OUTPUT
{
echo "detailed_changes<<EOF"
echo "$DETAILED_CHANGES"
echo "EOF"
} >> $GITHUB_OUTPUT
{
echo "pr_refs<<EOF"
echo "$PR_REFS"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Generate changelog with Claude
if: steps.check-tag.outputs.tag_exists == 'false'
id: generate-changelog
run: |
VERSION="${{ steps.get-version.outputs.version }}"
LAST_TAG="${{ steps.analyze-changes.outputs.last_tag }}"
# Create analysis prompt for Claude
cat > /tmp/changelog_prompt.txt << PROMPT_EOF
I need you to generate a concise but informative changelog for a software release.
**Release Info:**
- Version: $VERSION
- Previous Version: $LAST_TAG
- Files Changed: ${{ steps.analyze-changes.outputs.files_changed }}
- Commits: ${{ steps.analyze-changes.outputs.commits_count }}
- Lines Added: ${{ steps.analyze-changes.outputs.additions }}
- Lines Deleted: ${{ steps.analyze-changes.outputs.deletions }}
**Recent Commits:**
${{ steps.analyze-changes.outputs.commit_messages }}
**File Changes:**
${{ steps.analyze-changes.outputs.detailed_changes }}
**PR References:**
${{ steps.analyze-changes.outputs.pr_refs }}
Please generate a changelog that includes:
1. A brief 1-2 sentence summary of this release
2. Key features/improvements (bullet points)
3. Breaking changes (if any) - clearly marked with ⚠️
4. Notable technical changes worth mentioning
5. Bug fixes (if any)
Keep it concise but informative. Focus on what users and developers need to know.
Use markdown formatting. Don't include a version header as that will be added separately.
If there are security improvements, highlight them.
If this appears to be a maintenance/infrastructure release, emphasize that.
Format your response as clean markdown without any prefix text.
PROMPT_EOF
echo "✅ Changelog prompt created"
- name: Call Claude API for changelog
if: steps.check-tag.outputs.tag_exists == 'false'
id: claude-changelog
run: |
# Call Claude API with the analysis prompt
PROMPT=$(cat /tmp/changelog_prompt.txt)
# Create a proper JSON payload using jq to handle escaping
PAYLOAD=$(jq -n \
--arg model "${{ vars.CLAUDE_MODEL || 'claude-sonnet-4-6' }}" \
--arg content "$PROMPT" \
'{
"model": $model,
"max_tokens": 3000,
"messages": [
{
"role": "user",
"content": $content
}
]
}')
RESPONSE=$(curl -s --max-time 60 --retry 3 --retry-delay 10 -X POST "https://api.anthropic.com/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: ${{ secrets.ANTHROPIC_API_KEY }}" \
-H "anthropic-version: 2023-06-01" \
-d "$PAYLOAD")
# Check for API errors
if echo "$RESPONSE" | jq -e '.error' > /dev/null; then
echo "❌ Claude API error: $(echo "$RESPONSE" | jq -r '.error.message')"
echo "Using fallback changelog"
CHANGELOG="## What's Changed\n\n- ${{ steps.analyze-changes.outputs.commits_count }} commits with ${{ steps.analyze-changes.outputs.files_changed }} files changed\n- ${{ steps.analyze-changes.outputs.additions }} additions and ${{ steps.analyze-changes.outputs.deletions }} deletions\n\nSee commit history for detailed changes."
else
# Extract changelog from Claude's response
CHANGELOG=$(echo "$RESPONSE" | jq -r '.content[0].text')
# Validate that Claude returned meaningful content
if [ -z "$CHANGELOG" ] || [ "$CHANGELOG" = "null" ]; then
echo "❌ Claude returned empty changelog, using fallback"
CHANGELOG="## What's Changed\n\n- ${{ steps.analyze-changes.outputs.commits_count }} commits with ${{ steps.analyze-changes.outputs.files_changed }} files changed\n- ${{ steps.analyze-changes.outputs.additions }} additions and ${{ steps.analyze-changes.outputs.deletions }} deletions\n\nSee commit history for detailed changes."
else
echo "✅ Claude changelog generated successfully"
fi
fi
# Save changelog to output
{
echo "changelog<<EOF"
echo -e "$CHANGELOG"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create Release Tag
if: steps.check-tag.outputs.tag_exists == 'false'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.get-version.outputs.version }}" -m "Release v${{ steps.get-version.outputs.version }}"
git push origin "v${{ steps.get-version.outputs.version }}"
- name: Create GitHub Release
if: steps.check-tag.outputs.tag_exists == 'false'
id: create-release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get-version.outputs.version }}
name: Release v${{ steps.get-version.outputs.version }}
body: |
# RoboSystems Python SDK v${{ steps.get-version.outputs.version }}
${{ steps.claude-changelog.outputs.changelog }}
---
## 📊 Release Statistics
- **Commits:** ${{ steps.analyze-changes.outputs.commits_count }}
- **Files Changed:** ${{ steps.analyze-changes.outputs.files_changed }}
- **Lines Added:** ${{ steps.analyze-changes.outputs.additions }}
- **Lines Deleted:** ${{ steps.analyze-changes.outputs.deletions }}
- **Previous Release:** ${{ steps.analyze-changes.outputs.last_tag }}
## 🔗 Links
- **Full Changelog:** [${{ steps.analyze-changes.outputs.last_tag }}...v${{ steps.get-version.outputs.version }}](https://github.com/RoboFinSystems/robosystems-python-client/compare/${{ steps.analyze-changes.outputs.last_tag }}...v${{ steps.get-version.outputs.version }})
- **All Releases:** [View all releases](https://github.com/RoboFinSystems/robosystems-python-client/releases)
---
🤖 Generated with [Claude Code](https://claude.ai/code)
draft: false
prerelease: false
env:
# ACTIONS_TOKEN preferred for release creation
GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN || github.token }}
- name: Create release summary
if: steps.check-tag.outputs.tag_exists == 'false'
run: |
VERSION="${{ steps.get-version.outputs.version }}"
echo "## 🚀 Release v$VERSION Created" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Release URL:** [v$VERSION](https://github.com/RoboFinSystems/robosystems-python-client/releases/tag/v$VERSION)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📊 Statistics" >> $GITHUB_STEP_SUMMARY
echo "- **Commits:** ${{ steps.analyze-changes.outputs.commits_count }}" >> $GITHUB_STEP_SUMMARY
echo "- **Files Changed:** ${{ steps.analyze-changes.outputs.files_changed }}" >> $GITHUB_STEP_SUMMARY
echo "- **Lines Added:** ${{ steps.analyze-changes.outputs.additions }}" >> $GITHUB_STEP_SUMMARY
echo "- **Lines Deleted:** ${{ steps.analyze-changes.outputs.deletions }}" >> $GITHUB_STEP_SUMMARY
echo "- **Previous Release:** ${{ steps.analyze-changes.outputs.last_tag }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🤖 Claude-Generated Changelog" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.claude-changelog.outputs.changelog }}" >> $GITHUB_STEP_SUMMARY