-
Notifications
You must be signed in to change notification settings - Fork 15
401 lines (340 loc) · 12.5 KB
/
release.yml
File metadata and controls
401 lines (340 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
name: Release
run-name:
${{ inputs.type }} | ${{ github.event.inputs.prerelease == 'true' && format('{0}',
inputs.prerelease-type) || 'stable' }} | ${{ github.ref_name }} | @${{ github.actor }}
permissions:
contents: write
statuses: write
repository-projects: write
actions: write
on:
workflow_dispatch:
inputs:
type:
description: 'Release tag'
required: true
type: choice
options:
# - 'major'
- 'minor'
- 'patch'
default: 'patch'
prerelease:
description: 'Is this a prerelease?'
type: boolean
default: false
prerelease-type:
description: 'Prerelease tag'
required: false
type: string
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
inputs-validation:
name: Validate inputs
runs-on: ubuntu-latest
steps:
- name: 🧪 Validate inputs
id: validate
run: |
if [ "${{ github.event.inputs.prerelease }}" = "true" ] && [ -z "${{ github.event.inputs.prerelease-type }}" ]; then
echo "Error: prerelease-type is required when prerelease is checked"
exit 1
fi
if [ "${{ github.event.inputs.prerelease }}" = "false" ] && [ ! -z "${{ github.event.inputs.prerelease-type }}" ]; then
echo "Error: prerelease-type is not allowed when prerelease is not checked"
exit 1
fi
echo "All inputs are valid"
calculate-version:
name: Calculate version
runs-on: ubuntu-latest
needs: inputs-validation
outputs:
new_version: ${{ steps.calculate.outputs.new_version }}
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: 🔄 Check if can be fast-forwarded to develop
run: |
# Skip check if on develop
if [ "${{ github.ref_name }}" = "develop" ]; then
echo "✅ On develop branch, skipping rebase check"
exit 0
fi
# Fetch both branches
git fetch origin develop
# Get latest commits
current_commit=$(git rev-parse HEAD)
develop_commit=$(git rev-parse origin/develop)
# Get merge base
merge_base=$(git merge-base $current_commit $develop_commit)
# Check if current branch is behind develop
if [ "$merge_base" != "$develop_commit" ]; then
echo "::error::Branch is behind develop. Please rebase first."
exit 1
fi
# Check if fast-forward is possible
if ! git merge-tree $merge_base $develop_commit $current_commit | grep -q "^changed in both"; then
echo "✅ Branch can be fast-forwarded to develop"
else
echo "::error::Branch has conflicts with develop. Please resolve conflicts first."
exit 1
fi
- name: 🔍 Find previous version tag
id: previoustag
run: |
regex='^[0-9]+\.[0-9]+\.[0-9]+$'
previousTag=$(git tag --list | grep -E "$regex" | sort -V | tail -n 1)
echo "previousTag=${previousTag}"
echo "previousTag=${previousTag}" >> $GITHUB_OUTPUT
- name: 🧮 Calculate new version
id: calculate
run: |
. ./scripts/functions.sh
previousTag=${{ steps.previoustag.outputs.previousTag }}
if [ -z "$previousTag" ]; then
previousTag="0.0.0"
fi
if [ "${{ github.event.inputs.prerelease }}" = "true" ]; then
newVersion=$(increment_version "$previousTag" "${{ github.event.inputs.type }}" "${{ github.event.inputs.prerelease-type }}")
else
newVersion=$(increment_version "$previousTag" "${{ github.event.inputs.type }}")
fi
echo "Next version: $newVersion"
echo "new_version=$newVersion" >> $GITHUB_OUTPUT
pre-release:
name: Prepare release ${{ needs.calculate-version.outputs.new_version }}
needs: calculate-version
environment:
name: release-approval
env:
HUSKY_SKIP_HOOKS: 1
runs-on: ubuntu-latest
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Git configure
uses: ./.github/actions/gitconfig
- name: 🔧 Bump version
run: ./scripts/git/bump-version.sh ${{ needs.calculate-version.outputs.new_version }}
- name: 🛠️ Setup environment
uses: ./.github/actions/setup
with:
rust-target: 'x86_64-unknown-linux-gnu'
- name: Install dependencies
run: |
pnpm install --no-frozen-lockfile --ignore-scripts
- name: 🔄 Update Cargo lock
run: |
cargo update --workspace
- name: 📝 Commit version bump
id: commit
run: |
git add .
git commit --no-verify -m "Bump version to ${{ needs.calculate-version.outputs.new_version }}"
git log --oneline | head -n 3
- name: ✅ Check if tag can be fast-forwarded
id: ff_check
run: |
git fetch --all --tags
# Get the merge base between current HEAD and master
merge_base=$(git merge-base HEAD origin/master)
master_commit=$(git rev-parse origin/master)
# Check if HEAD is ahead of or equal to master
if [ "$merge_base" = "$master_commit" ]; then
echo "Tag can be fast-forwarded to master"
echo "can_ff=true" >> $GITHUB_OUTPUT
else
echo "Error: Current HEAD cannot be fast-forwarded to master"
echo "can_ff=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: 🏷️ Create new version tag
id: newtag
if: steps.ff_check.outputs.can_ff == 'true'
run: |
newVersion=${{ needs.calculate-version.outputs.new_version }}
if git rev-parse "$newVersion" >/dev/null 2>&1; then
git tag -d "$newVersion"
git push --delete origin "$newVersion"
fi
git tag $newVersion -m "Release $newVersion"
git push origin $newVersion
release-draft:
name: Draft release ${{ needs.calculate-version.outputs.new_version }}
needs: [pre-release, calculate-version]
runs-on: ubuntu-latest
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Git configure
uses: ./.github/actions/gitconfig
- name: 🔀 Checkout to ${{ needs.calculate-version.outputs.new_version }}
run: |
git checkout ${{ needs.calculate-version.outputs.new_version }}
- name: 🚀 Create Release
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
prerelease: ${{ github.event.inputs.prerelease }}
generate_release_notes: true
draft: true
fail_on_unmatched_files: true
tag_name: ${{ needs.calculate-version.outputs.new_version }}
target_commitish: ${{ github.sha }}
name: ${{ needs.calculate-version.outputs.new_version }}
upload-npm:
name: Upload ${{ needs.calculate-version.outputs.new_version }} version to NPM
needs: [release-draft, calculate-version]
runs-on: ubuntu-latest
environment:
name: changlog-approval
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Git configure
uses: ./.github/actions/gitconfig
- name: 🔀 Checkout to ${{ needs.calculate-version.outputs.new_version }}
run: |
git checkout ${{ needs.calculate-version.outputs.new_version }}
- name: 📦 Publish to NPM
id: npm
run: |
MAX_ATTEMPTS=100
SLEEP_BASE=5
run_id=$(gh workflow run npm.yml \
--ref ${{ needs.calculate-version.outputs.new_version }} \
--repo ${{ github.repository }}) || exit 1
for i in $(seq 1 $MAX_ATTEMPTS); do
wait_time=$(( SLEEP_BASE * i ))
echo "Waiting for $wait_time seconds before checking the status"
sleep "$wait_time"
run_id=$(gh run list \
--workflow=npm.yml \
--limit=5 \
--json databaseId,status \
-q 'map(select(.status == "in_progress" or .status == "queued" or .status == "waiting")) | .[0].databaseId')
if [ ! -z "$run_id" ]; then
break
fi
done
if [ -z "$run_id" ]; then
echo "Error: Failed to get run ID"
exit 1
fi
SLEEP_BASE=$((60*20))
echo "Sleeping for $((SLEEP_BASE/60)) minutes before checking the status"
sleep $SLEEP_BASE # Wait before checking the status
while true; do
status=$(gh run view "$run_id" --json status --jq '.status')
echo "Current status: $status"
case $status in
"completed")
conclusion=$(gh run view "$run_id" --json conclusion --jq '.conclusion')
if [ "$conclusion" = "success" ]; then
echo "✅ Workflow completed successfully"
exit 0
else
echo "::error::Workflow failed with conclusion: $conclusion"
exit 1
fi
;;
"in_progress"|"queued"|"waiting")
sleep 60 # Wait for 1 minute
;;
*)
echo "::error::Unexpected status: $status"
exit 1
;;
esac
done
status=$(gh run view "$run_id" --json status --jq '.status')
if [ "$status" != "completed" ] || [ "$status" = "failure" ] || [ "$status" = "cancelled" ]; then
echo "Workflow failed with status: $status"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
name: Release ${{ needs.calculate-version.outputs.new_version }}
needs: [upload-npm, calculate-version]
runs-on: ubuntu-latest
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: 📢 Update Release Status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! gh release view ${{ needs.calculate-version.outputs.new_version }}; then
echo "::error::Release not found"
exit 1
fi
gh release edit ${{ needs.calculate-version.outputs.new_version }} \
--draft=false \
${{ github.event.inputs.prerelease != 'true' && '--latest' || '' }} \
--verify-tag
gh release view ${{ needs.calculate-version.outputs.new_version }} \
--json isDraft,tagName,url \
--template '✅ Release {{.tagName}} published: {{.url}}'
merge-develop:
name: Merge to develop branch
needs: [release, calculate-version]
runs-on: ubuntu-latest
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Git config
uses: ./.github/actions/gitconfig
- name: 🔀 Merge to develop
run: |
git checkout develop
git pull origin develop
git merge ${{ needs.calculate-version.outputs.new_version }}
git push origin develop
merge-master:
name: Merge to master branch
needs: [merge-develop, calculate-version]
runs-on: ubuntu-latest
steps:
- name: 🛠️ Checkout code
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Git configure
uses: ./.github/actions/gitconfig
- name: 🔀 Merge to master
run: |
git checkout master
git pull origin master
git merge --ff-only ${{ needs.calculate-version.outputs.new_version }}
git push origin master
deploy-docs:
name: Deploy docs to GitHub Pages
needs: [release, calculate-version]
runs-on: ubuntu-latest
if: github.event.inputs.prerelease == 'false'
steps:
- name: 📚 Deploy docs
id: deploy-docs
run: |
gh workflow run docs.yml \
--ref ${{ needs.calculate-version.outputs.new_version }} \
--repo ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}