-
Notifications
You must be signed in to change notification settings - Fork 28
266 lines (218 loc) · 11.1 KB
/
Copy pathauto-release.yml
File metadata and controls
266 lines (218 loc) · 11.1 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
name: Auto Release on Main Branch
on:
pull_request:
types: [closed]
branches: [main]
permissions:
contents: write
jobs:
create-tags:
# Only run if PR was merged to main from release branch and has release label
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'release' &&
contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_tags_labels.outputs.version }}
devnet_tag: ${{ steps.get_tags_labels.outputs.devnet_tag }}
docker_tag: ${{ steps.get_tags_labels.outputs.docker_tag }}
github_tag: ${{ steps.get_tags_labels.outputs.github_tag }}
has_devnet_tag: ${{ steps.get_tags_labels.outputs.has_devnet_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract tags from PR labels
id: get_tags_labels
run: |
LABELS='${{ toJson(github.event.pull_request.labels.*.name) }}'
echo "PR Labels: $LABELS"
VERSION=$(echo $LABELS | jq -r '.[] | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))' | head -n 1)
DEVNET_TAG_LOWER=$(echo $LABELS | jq -r '.[] | select(test("^devnet[0-9]+$"))' | head -n 1)
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "❌ Version label is mandatory! Please add a version label in x.y.z format (e.g. 1.0.0)"
exit 1
else
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "git_tag=v$VERSION" >> $GITHUB_OUTPUT
echo "✅ Version found: $VERSION"
fi
if [ -n "$DEVNET_TAG_LOWER" ] && [ "$DEVNET_TAG_LOWER" != "null" ]; then
DOCKER_TAG="$DEVNET_TAG_LOWER"
GITHUB_TAG="D${DEVNET_TAG_LOWER:1}"
echo "devnet_tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "docker_tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "github_tag=$GITHUB_TAG" >> $GITHUB_OUTPUT
echo "has_devnet_tag=true" >> $GITHUB_OUTPUT
echo "✅ Found devnet tag: label=$DEVNET_TAG_LOWER -> docker_tag=$DOCKER_TAG, github_tag=$GITHUB_TAG"
else
echo "has_devnet_tag=false" >> $GITHUB_OUTPUT
echo "ℹ️ No devnet tag found (optional)"
fi
- name: Create and push git tags
id: create_tags
run: |
git fetch --prune --tags --force
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
CREATE_VERSION_TAG=false
CREATE_DEVNET_TAG=false
if [ -n "${{ steps.get_tags_labels.outputs.version }}" ] && [ "${{ steps.get_tags_labels.outputs.version }}" != "null" ]; then
if git rev-parse "${{ steps.get_tags_labels.outputs.git_tag }}" >/dev/null 2>&1; then
echo "❌ Version tag ${{ steps.get_tags_labels.outputs.git_tag }} already exists. Please use a different version label."
exit 1
else
CREATE_VERSION_TAG=true
fi
fi
if [ "${{ steps.get_tags_labels.outputs.has_devnet_tag }}" = "true" ]; then
DEVNET_GIT_TAG="${{ steps.get_tags_labels.outputs.github_tag }}"
if git rev-parse "$DEVNET_GIT_TAG" >/dev/null 2>&1; then
echo "🗑️ Devnet tag $DEVNET_GIT_TAG already exists, will be recreated"
git tag -d "$DEVNET_GIT_TAG" || echo "⚠️ Local tag deletion failed"
git push --delete origin "$DEVNET_GIT_TAG" || echo "⚠️ Remote tag deletion failed"
fi
CREATE_DEVNET_TAG=true
fi
if [ "$CREATE_VERSION_TAG" = "true" ]; then
git tag -a "${{ steps.get_tags_labels.outputs.git_tag }}" -m "Release version ${{ steps.get_tags_labels.outputs.version }}"
git push origin "${{ steps.get_tags_labels.outputs.git_tag }}"
echo "✅ Created version tag ${{ steps.get_tags_labels.outputs.git_tag }}"
fi
if [ "$CREATE_DEVNET_TAG" = "true" ]; then
git tag -a "$DEVNET_GIT_TAG" -m "Devnet release for $DEVNET_GIT_TAG"
git push origin "$DEVNET_GIT_TAG"
echo "✅ Created devnet git tag $DEVNET_GIT_TAG"
fi
echo "create_version_tag=$CREATE_VERSION_TAG" >> $GITHUB_OUTPUT
echo "create_devnet_tag=$CREATE_DEVNET_TAG" >> $GITHUB_OUTPUT
create-github-release:
needs: [create-tags]
runs-on: ubuntu-latest
if: ${{ needs.create-tags.outputs.has_devnet_tag == 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Delete existing devnet release if exists
run: |
DEVNET_TAG="${{ needs.create-tags.outputs.github_tag }}"
echo "🔍 Checking for existing $DEVNET_TAG release..."
if gh api repos/${{ github.repository }}/releases/tags/$DEVNET_TAG >/dev/null 2>&1; then
RELEASE_ID=$(gh api repos/${{ github.repository }}/releases/tags/$DEVNET_TAG --jq '.id')
echo "🗑️ Found existing GitHub release for $DEVNET_TAG (ID: $RELEASE_ID), deleting..."
gh api --method DELETE repos/${{ github.repository }}/releases/$RELEASE_ID
echo "✅ Deleted existing GitHub release"
else
echo "ℹ️ No existing GitHub release found for $DEVNET_TAG"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate changelog from previous release
id: changelog
run: |
DEVNET_TAG="${{ needs.create-tags.outputs.github_tag }}"
PREVIOUS_TAG=$(git tag -l | grep -iE "^[Dd]evnet[0-9]+" | sort -V -r | grep -v "^$DEVNET_TAG$" | head -1)
if [ -n "$PREVIOUS_TAG" ] && [ "$PREVIOUS_TAG" != "$DEVNET_TAG" ]; then
echo "✅ Found previous tag: $PREVIOUS_TAG"
echo "📝 Generating changelog from $PREVIOUS_TAG to current release..."
COMMIT_LOG=$(git log --pretty=format:"- %s (%h)" --no-merges "$PREVIOUS_TAG"..HEAD)
FILES_CHANGED=$(git diff --name-only "$PREVIOUS_TAG"..HEAD | wc -l)
INSERTIONS=$(git diff --shortstat "$PREVIOUS_TAG"..HEAD | grep -o '[0-9]\+ insertion' | grep -o '[0-9]\+' || echo "0")
DELETIONS=$(git diff --shortstat "$PREVIOUS_TAG"..HEAD | grep -o '[0-9]\+ deletion' | grep -o '[0-9]\+' || echo "0")
CONTRIBUTORS=$(git log --pretty=format:"%an" --no-merges "$PREVIOUS_TAG"..HEAD | sort | uniq | tr '\n' ', ' | sed 's/, $//')
CHANGELOG="## 📋 Changes since $PREVIOUS_TAG
### 📊 Summary
- **Files changed**: $FILES_CHANGED
- **Insertions**: +$INSERTIONS
- **Deletions**: -$DELETIONS
- **Contributors**: $CONTRIBUTORS
### 🔄 Recent commits
$COMMIT_LOG
### 🔗 Compare changes
[View full diff](${{ github.server_url }}/${{ github.repository }}/compare/$PREVIOUS_TAG...HEAD)"
else
echo "ℹ️ No previous release found or this is the first release"
CHANGELOG="## 📋 Changes
This is the first devnet release for lean-quickstart."
fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.create-tags.outputs.github_tag }}
name: "lean-quickstart ${{ needs.create-tags.outputs.github_tag }} Release"
body: |
# lean-quickstart ${{ needs.create-tags.outputs.github_tag }} Release
## Release information
- **Version**: ${{ needs.create-tags.outputs.version }}
- **Network tag**: ${{ needs.create-tags.outputs.github_tag }}
- **Branch**: `${{ needs.create-tags.outputs.docker_tag }}` (updated from `main` after merge)
This repository provides devnet tooling (Ansible, scripts, genesis helpers). Client container images are published from the [zeam](https://github.com/blockblaz/zeam) repository.
## 📋 Changes
${{ steps.changelog.outputs.changelog }}
## 🌿 Use this release
```bash
git fetch origin tag ${{ needs.create-tags.outputs.github_tag }}
git checkout ${{ needs.create-tags.outputs.github_tag }}
```
draft: false
prerelease: true
- name: Push code to corresponding devnet branch
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
GITHUB_TAG="${{ needs.create-tags.outputs.github_tag }}"
DOCKER_TAG="${{ needs.create-tags.outputs.docker_tag }}"
DEVNET_BRANCH="$DOCKER_TAG"
git fetch origin main
echo "✅ GitHub tag: $GITHUB_TAG, branch: $DEVNET_BRANCH"
if git ls-remote --heads origin "$DEVNET_BRANCH" | grep -q "$DEVNET_BRANCH"; then
echo "✅ $DEVNET_BRANCH branch exists, updating it"
git fetch origin "$DEVNET_BRANCH"
git checkout "$DEVNET_BRANCH"
git merge origin/main --no-edit
else
echo "✅ $DEVNET_BRANCH branch doesn't exist, creating it from current main"
git checkout -b "$DEVNET_BRANCH"
fi
git push origin "$DEVNET_BRANCH"
echo "✅ Successfully pushed code to $DEVNET_BRANCH branch"
- name: Send Telegram success notification
if: ${{ success() }}
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
run: |
if [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then
echo "ℹ️ Telegram secrets not set; skipping notification"
exit 0
fi
DOCKER_TAG="${{ needs.create-tags.outputs.docker_tag }}"
GITHUB_TAG="${{ needs.create-tags.outputs.github_tag }}"
VERSION="${{ needs.create-tags.outputs.version }}"
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
MESSAGE="🚀 *lean-quickstart $GITHUB_TAG release SUCCESS*
*Release details:*
• Version: \`$VERSION\`
• Network: \`$GITHUB_TAG\`
• Repository: [${{ github.repository }}]($REPO_URL)
*🔗 Links:*
• [GitHub release]($REPO_URL/releases/tag/$GITHUB_TAG)
*🌿 Branch:*
• Code pushed to \`$DOCKER_TAG\`
_Automated release notification_"
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
-H "Content-Type: application/json" \
-d "{
\"chat_id\": \"${TELEGRAM_CHAT_ID}\",
\"text\": \"$MESSAGE\",
\"parse_mode\": \"Markdown\",
\"disable_web_page_preview\": true
}" && echo "📱 Telegram notification sent successfully" || echo "❌ Failed to send Telegram notification"