-
Notifications
You must be signed in to change notification settings - Fork 10
202 lines (170 loc) · 7.17 KB
/
create-release.yml
File metadata and controls
202 lines (170 loc) · 7.17 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
name: Create Release and Tag
on:
push:
branches:
- main
paths:
- pyproject.toml
- sdk/_version.py
env:
CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} Reya Bot
CI_COMMIT_EMAIL: devcold@voltz.xyz
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install tomli
- name: Get current version
id: current-version
run: |
SDK_VERSION=$(python -c "
import tomli
with open('pyproject.toml', 'rb') as f:
data = tomli.load(f)
print(data['project']['version'])
")
echo "sdk_version=$SDK_VERSION" >> $GITHUB_OUTPUT
echo "Current SDK version: $SDK_VERSION"
- name: Check if version is new
id: check-version-new
run: |
VERSION="${{ steps.current-version.outputs.sdk_version }}"
# Check if tag already exists
if git tag -l | grep -q "^v${VERSION}$"; then
echo "version_is_new=false" >> $GITHUB_OUTPUT
echo "⚠️ Tag v$VERSION already exists"
else
echo "version_is_new=true" >> $GITHUB_OUTPUT
echo "✅ Version v$VERSION is new"
fi
- name: Validate version format
if: steps.check-version-new.outputs.version_is_new == 'true'
run: |
VERSION="${{ steps.current-version.outputs.sdk_version }}"
# Check that version has exactly 4 digits (X.Y.Z.W format)
VERSION_PARTS=$(echo "$VERSION" | tr '.' '\n' | wc -l)
if [ "$VERSION_PARTS" -ne 4 ]; then
echo "❌ ERROR: SDK version must have exactly 4 digits (X.Y.Z.W format)"
echo "Found $VERSION_PARTS parts in version: $VERSION"
exit 1
fi
echo "✅ Version format validated: $VERSION"
- name: Create version tag
if: steps.check-version-new.outputs.version_is_new == 'true'
run: |
VERSION="${{ steps.current-version.outputs.sdk_version }}"
COMMIT_SHA="${{ github.sha }}"
# Create annotated tag with v prefix
git config --local user.email "${{ env.CI_COMMIT_EMAIL }}"
git config --local user.name "${{ env.CI_COMMIT_AUTHOR }}"
git tag -a "v$VERSION" -m "Release version v$VERSION
Auto-tagged after merge to main branch.
Reya Python SDK Release v$VERSION
- REST API client for Reya's Trading API
- RPC client for on-chain actions
- WebSocket client for real-time data streaming"
echo "✅ Created tag v$VERSION for commit $COMMIT_SHA"
- name: Push tag
if: steps.check-version-new.outputs.version_is_new == 'true'
run: |
VERSION="${{ steps.current-version.outputs.sdk_version }}"
git push origin "v$VERSION"
echo "✅ Pushed tag v$VERSION to remote"
- name: Create GitHub Release
if: steps.check-version-new.outputs.version_is_new == 'true'
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.current-version.outputs.sdk_version }}';
const commitSha = '${{ github.sha }}';
// Get the previous tag to generate release notes
let previousTag = null;
try {
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 10
});
// Find the most recent tag that's not the current version
previousTag = tags.find(tag => tag.name !== `v${version}`)?.name;
} catch (error) {
console.log('Could not fetch previous tags:', error.message);
}
// Generate automatic release notes
let automaticReleaseNotes = '';
if (previousTag) {
try {
const { data: releaseNotes } = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${version}`,
previous_tag_name: previousTag,
});
automaticReleaseNotes = releaseNotes.body;
} catch (error) {
console.log('Could not generate automatic release notes:', error.message);
}
}
// Get the commit message for context
const { data: commit } = await github.rest.git.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: commitSha,
});
// Build comprehensive release body
let releaseBody = `## 🐍 Reya Python SDK Release ${version}
### 📦 Installation
\`\`\`bash
pip install reya-python-sdk
\`\`\`
### 📋 Release Details
- **Release Tag**: \`v${version}\`
- **Commit**: \`${commitSha.substring(0, 7)}\`
- **Previous Version**: ${previousTag ? `\`${previousTag}\`` : '_First release_'}
### 🔄 Latest Changes
**${commit.message.split('\n')[0]}**`;
if (commit.message.split('\n').length > 1) {
const additionalLines = commit.message.split('\n').slice(1).filter(line => line.trim()).join('\n');
if (additionalLines) {
releaseBody += `\n\n${additionalLines}`;
}
}
// Add automatic release notes if available
if (automaticReleaseNotes) {
releaseBody += `\n\n---\n\n${automaticReleaseNotes}`;
}
const { data: release } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${version}`,
name: `🏷️ v${version}`,
body: releaseBody,
draft: false,
prerelease: false,
generate_release_notes: false, // We're creating custom notes
});
console.log(`✅ Created GitHub release: ${release.html_url}`);
- name: Report results
if: always()
run: |
echo "=== Create Release Results ==="
echo "SDK Version: ${{ steps.current-version.outputs.sdk_version }}"
echo "Version is New: ${{ steps.check-version-new.outputs.version_is_new }}"
if [ "${{ steps.check-version-new.outputs.version_is_new }}" = "true" ]; then
echo "✅ Successfully created GitHub release for version v${{ steps.current-version.outputs.sdk_version }}"
echo "📦 To publish to PyPI, go to the GitHub release and click 'Publish'"
elif [ "${{ steps.check-version-new.outputs.version_is_new }}" = "false" ]; then
echo "⚠️ Skipped: Version v${{ steps.current-version.outputs.sdk_version }} already exists"
fi