-
Notifications
You must be signed in to change notification settings - Fork 4
166 lines (137 loc) · 5.67 KB
/
Copy pathprepare-release.yml
File metadata and controls
166 lines (137 loc) · 5.67 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
# .github/workflows/prepare-release.yml
name: Prepare Release
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Calculate new version
id: version
run: |
# Get current version from Cargo.toml
CURRENT=$(grep '^version = ' Cargo.toml | head -1 | cut -d'"' -f2)
# Calculate new version based on bump type
IFS='.' read -r major minor patch <<< "$CURRENT"
case "${{ inputs.bump }}" in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
esac
NEW_VERSION="$major.$minor.$patch"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT" >> $GITHUB_OUTPUT
echo "Bumping from $CURRENT to $NEW_VERSION"
- name: Update Cargo.toml
run: |
sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.new_version }}"/' Cargo.toml
- name: Update Cargo.lock
run: |
cargo update -p flux9s --precise ${{ steps.version.outputs.new_version }}
- name: Generate changelog with Claude API
id: changelog
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
VERSION="${{ steps.version.outputs.new_version }}"
CURRENT_VERSION="${{ steps.version.outputs.current_version }}"
# Get git diff since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
DIFF=$(git log $LAST_TAG..HEAD --pretty=format:"%h %s" --no-merges)
else
DIFF=$(git log --pretty=format:"%h %s" --no-merges --max-count=20)
fi
# Create the prompt
PROMPT="Generate a concise changelog summary for version $VERSION based on these git commits. Format as bullet points under categories: Added, Changed, Fixed. Be specific but brief. Only include categories that have changes.
Commits:
$DIFF"
# Generate changelog using Claude API with proper JSON escaping
RESPONSE=$(curl -s https://api.anthropic.com/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d @- << EOF
{
"model": "claude-3-haiku-20240307",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": $(echo "$PROMPT" | jq -Rs .)
}]
}
EOF
)
# Extract the changelog text, with error handling
CHANGELOG=$(echo "$RESPONSE" | jq -r '.content[0].text // empty')
if [ -z "$CHANGELOG" ]; then
echo "Warning: Claude API returned empty response"
echo "API Response: $RESPONSE"
CHANGELOG="### Changes\n- Version bump to $VERSION"
fi
# Save to file for next step
echo "$CHANGELOG" > /tmp/ai_changelog.txt
echo "Generated changelog:"
cat /tmp/ai_changelog.txt
- name: Update CHANGELOG.md
run: |
VERSION="${{ steps.version.outputs.new_version }}"
DATE=$(date +%Y-%m-%d)
# Read AI-generated changelog
AI_CHANGELOG=$(cat /tmp/ai_changelog.txt 2>/dev/null || echo "### Changes\n- Version bump to $VERSION")
# Create the new changelog entry
cat > /tmp/changelog_entry.txt << EOF
## [$VERSION] - $DATE
$AI_CHANGELOG
EOF
# Insert after the [Unreleased] line
sed -i "/^## \[Unreleased\]/r /tmp/changelog_entry.txt" CHANGELOG.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: bump version to ${{ steps.version.outputs.new_version }}"
title: "Release v${{ steps.version.outputs.new_version }}"
body: |
## Release v${{ steps.version.outputs.new_version }}
This PR prepares the release for v${{ steps.version.outputs.new_version }}.
**Version bump:** ${{ steps.version.outputs.current_version }} → ${{ steps.version.outputs.new_version }} (${{ inputs.bump }})
**Changes in this PR:**
- ✅ Updated version in Cargo.toml
- ✅ Updated Cargo.lock
- ✅ Updated CHANGELOG.md with AI-generated summary
**What happens after merge:**
1. ✅ PR gets merged to main
2. ✅ Tag `v${{ steps.version.outputs.new_version }}` is automatically created by auto-tag workflow
3. ✅ Release workflow is automatically triggered via workflow_dispatch
4. ✅ Release workflow builds binaries for all platforms
5. ✅ Publishes to crates.io
6. ✅ Creates GitHub release with artifacts
7. ✅ Updates Homebrew formula
The CHANGELOG.md has been automatically generated using Claude AI. Please review and edit if needed before merging!
branch: release-v${{ steps.version.outputs.new_version }}
delete-branch: true
labels: release