-
Notifications
You must be signed in to change notification settings - Fork 27
498 lines (402 loc) · 16.4 KB
/
release.yml
File metadata and controls
498 lines (402 loc) · 16.4 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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
name: 🚀 Release
on:
push:
branches:
- 'master'
workflow_dispatch:
inputs:
release_tag:
description: 'Publish existing tag to npm (e.g. v1.2.3)'
type: string
required: false
dry_run:
description: 'Dry run (skip npm publish and tagging)'
type: boolean
default: false
debug:
description: 'Enable verbose logging'
type: boolean
default: false
permissions:
contents: write
pull-requests: write
id-token: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
manual-publish:
if: inputs.release_tag != ''
runs-on: ubuntu-latest
outputs:
version: ${{ inputs.release_tag }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.release_tag }}
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build-all
- name: Publish to NPM
if: inputs.dry_run != true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --provenance --access public
- name: Purge jsDelivr Cache
if: inputs.dry_run != true
uses: ./.github/actions/purge-jsdelivr
with:
package: cloudinary-video-player
check-release:
if: inputs.release_tag == ''
runs-on: ubuntu-latest
outputs:
is_release: ${{ steps.check.outputs.is_release }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if this is a release merge
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "${{ inputs.debug }}" == "true" ]]; then
set -x
fi
echo "::group::Checking if commit came from release/edge branch"
# Extract PR number from commit message (format: "... (#123)")
COMMIT_MSG=$(git log -1 --pretty=%B)
PR_NUMBER=$(echo "$COMMIT_MSG" | grep -oP '\(#\K\d+(?=\))' || echo "")
if [[ -z "$PR_NUMBER" ]]; then
echo "::notice::No PR number found in commit message"
echo "is_release=false" >> $GITHUB_OUTPUT
echo "::endgroup::"
exit 0
fi
echo "Found PR #$PR_NUMBER in commit message"
# Get PR details to check the source branch
PR_INFO=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" 2>/dev/null || echo "")
if [[ -z "$PR_INFO" ]]; then
echo "::notice::Could not fetch PR #$PR_NUMBER details"
echo "is_release=false" >> $GITHUB_OUTPUT
echo "::endgroup::"
exit 0
fi
BRANCH=$(echo "$PR_INFO" | jq -r '.head.ref')
echo "PR #$PR_NUMBER merged from branch: $BRANCH"
if [[ "$BRANCH" == "release/edge" ]]; then
echo "::notice::This is a release merge from release/edge"
echo "is_release=true" >> $GITHUB_OUTPUT
# Get version from package.json (already bumped in the PR)
VERSION="v$(jq -r '.version' package.json)"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "::notice::Version: $VERSION"
else
echo "::notice::This is NOT a release merge (branch: $BRANCH)"
echo "is_release=false" >> $GITHUB_OUTPUT
fi
echo "::endgroup::"
publish-stable:
needs: check-release
if: needs.check-release.outputs.is_release == 'true'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.tag.outputs.tag_name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Get version from package.json
id: get_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=v$VERSION" >> $GITHUB_OUTPUT
echo "::notice::Publishing stable version: v$VERSION"
- name: Create Git Tag
id: tag
if: inputs.dry_run != true
run: |
VERSION="${{ steps.get_version.outputs.version }}"
echo "::group::Creating tag $VERSION"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "::warning::Tag $VERSION already exists, skipping tag creation"
else
git tag "$VERSION"
git push origin "$VERSION"
echo "::notice::Created and pushed tag $VERSION"
fi
echo "tag_name=$VERSION" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Create GitHub Release
if: inputs.dry_run != true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.get_version.outputs.version }}"
echo "::group::Creating GitHub release"
if gh release view "$VERSION" >/dev/null 2>&1; then
echo "::warning::Release $VERSION already exists, skipping"
else
gh release create "$VERSION" \
--title "$VERSION" \
--generate-notes
echo "::notice::Created GitHub release $VERSION"
fi
echo "::endgroup::"
- run: npm ci
- run: npm run build-all
- name: Publish to NPM
if: inputs.dry_run != true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "::notice::Publishing to npm (stable)"
npm publish --provenance --access public
- name: Purge jsDelivr Cache
if: inputs.dry_run != true
uses: ./.github/actions/purge-jsdelivr
with:
package: cloudinary-video-player
- name: Dry Run Summary
if: inputs.dry_run == true
run: |
echo "## 🧪 Dry Run Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Would have:" >> $GITHUB_STEP_SUMMARY
echo "- Created tag: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Created GitHub release" >> $GITHUB_STEP_SUMMARY
echo "- Published to npm (stable)" >> $GITHUB_STEP_SUMMARY
create-release-pr:
needs: check-release
if: needs.check-release.outputs.is_release != 'true'
runs-on: ubuntu-latest
outputs:
next_version: ${{ steps.calc_version.outputs.next_version }}
bump_type: ${{ steps.calc_version.outputs.bump_type }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.BOT_TOKEN }}
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- run: npm ci
- name: Configure Git
run: |
git config user.name "cloudinary-bot"
git config user.email "cloudinary-bot@users.noreply.github.com"
- name: Get current version
id: current_version
run: |
CURRENT=$(node -p "require('./package.json').version")
echo "version=$CURRENT" >> $GITHUB_OUTPUT
echo "::notice::Current version: $CURRENT"
- name: Calculate next version
id: calc_version
run: |
if [[ "${{ inputs.debug }}" == "true" ]]; then
set -x
fi
echo "::group::Calculating next version"
BUMP_TYPE=$(npx conventional-recommended-bump -p angular 2>/dev/null || echo "")
if [[ -z "$BUMP_TYPE" || "$BUMP_TYPE" == "null" ]]; then
echo "::notice::No conventional commits found; skipping release PR creation"
echo "bump_type=" >> $GITHUB_OUTPUT
echo "next_version=" >> $GITHUB_OUTPUT
echo "::endgroup::"
exit 0
fi
echo "Bump type: $BUMP_TYPE"
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
CURRENT="${{ steps.current_version.outputs.version }}"
NEXT=$(npx semver "$CURRENT" -i "$BUMP_TYPE")
echo "Next version: $NEXT"
echo "next_version=$NEXT" >> $GITHUB_OUTPUT
echo "::notice::Next version will be $NEXT ($BUMP_TYPE bump)"
echo "::endgroup::"
- name: Create or update release branch
if: steps.calc_version.outputs.bump_type != ''
run: |
BRANCH_NAME="release/edge"
echo "::group::Setting up release branch: $BRANCH_NAME"
# Checkout release branch, reset to master
git fetch origin "$BRANCH_NAME" 2>/dev/null || true
git checkout -B "$BRANCH_NAME" origin/master
echo "::endgroup::"
- name: Update version and changelog
if: steps.calc_version.outputs.bump_type != ''
run: |
NEXT_VERSION="${{ steps.calc_version.outputs.next_version }}"
echo "::group::Updating version to $NEXT_VERSION"
npm version "$NEXT_VERSION" --no-git-tag-version
npm install --package-lock-only
echo "::endgroup::"
echo "::group::Generating changelog"
npx conventional-changelog -p angular -i CHANGELOG.md -s -r 1
echo "::endgroup::"
- name: Commit and push changes
if: steps.calc_version.outputs.bump_type != ''
run: |
NEXT_VERSION="${{ steps.calc_version.outputs.next_version }}"
BRANCH_NAME="release/edge"
echo "::group::Committing changes"
git add package.json package-lock.json CHANGELOG.md
git commit -m "chore: release v$NEXT_VERSION"
git push -f origin "$BRANCH_NAME"
echo "::notice::Pushed release branch $BRANCH_NAME"
echo "::endgroup::"
- name: Create or update Pull Request
if: steps.calc_version.outputs.bump_type != ''
env:
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
NEXT_VERSION="${{ steps.calc_version.outputs.next_version }}"
BRANCH_NAME="release/edge"
BUMP_TYPE="${{ steps.calc_version.outputs.bump_type }}"
echo "::group::Creating/updating PR"
CHANGELOG_CONTENT=$(sed -n "/^#\{1,2\} \[$NEXT_VERSION\]/,/^#\{1,2\} \[/p" CHANGELOG.md | head -n -1)
EXISTING_PR=$(gh pr list --head "$BRANCH_NAME" --json number -q '.[0].number' || echo "")
PR_BODY=$(cat <<EOF
## Release v$NEXT_VERSION
This PR was automatically created by the release workflow.
**Bump type:** $BUMP_TYPE
### Changes
$CHANGELOG_CONTENT
---
*Merge this PR to publish v$NEXT_VERSION to npm.*
EOF
)
if [[ -n "$EXISTING_PR" ]]; then
echo "Updating existing PR #$EXISTING_PR"
gh pr edit "$EXISTING_PR" --title "chore: release v$NEXT_VERSION" --body "$PR_BODY"
echo "::notice::Updated PR #$EXISTING_PR"
else
echo "Creating new PR"
gh pr create --base master --head "$BRANCH_NAME" --title "chore: release v$NEXT_VERSION" --body "$PR_BODY"
echo "::notice::Created new release PR"
fi
echo "::endgroup::"
- name: No changes summary
if: steps.calc_version.outputs.bump_type == ''
run: |
echo "## ℹ️ No Release Needed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "conventional-recommended-bump returned no bump; skipping release PR." >> $GITHUB_STEP_SUMMARY
publish-edge:
needs: check-release
if: needs.check-release.outputs.is_release != 'true'
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- name: Get current version from package.json
id: get_version
run: |
current_version=$(node -p "require('./package.json').version")
echo "current_version=${current_version}" >> $GITHUB_OUTPUT
- name: Calculate next version
id: get_next_version
run: |
next_version=$(npx semver ${{ steps.get_version.outputs.current_version }} -i patch)
echo "Next patch version: $next_version"
echo "version=$next_version" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Checkout or create edge branch
run: |
if git rev-parse --verify origin/${{ steps.get_next_version.outputs.version }}-edge; then
git checkout ${{ steps.get_next_version.outputs.version }}-edge
git merge master -X ours --no-edit
else
git checkout master -b ${{ steps.get_next_version.outputs.version }}-edge
fi
- name: Bump version
id: bump_version
run: |
new_version=$(npm version prerelease --preid=edge)
echo "New edge version: $new_version"
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
- name: Push version
if: inputs.dry_run != true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin ${{ steps.get_next_version.outputs.version }}-edge
- run: npm run build-all
- name: Publish to NPM
if: inputs.dry_run != true
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "::notice::Publishing to npm (edge)"
npm publish --tag edge --provenance --access public
- name: Purge jsDelivr Cache
if: inputs.dry_run != true
uses: ./.github/actions/purge-jsdelivr
with:
package: cloudinary-video-player@edge
- name: Dry Run Summary
if: inputs.dry_run == true
run: |
echo "## 🧪 Dry Run Summary (Edge)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Would have:" >> $GITHUB_STEP_SUMMARY
echo "- Created edge version: ${{ steps.bump_version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "- Pushed to branch: ${{ steps.get_next_version.outputs.version }}-edge" >> $GITHUB_STEP_SUMMARY
echo "- Published to npm with edge tag" >> $GITHUB_STEP_SUMMARY
notify:
needs: [publish-stable, manual-publish]
if: always() && (needs.publish-stable.result == 'success' || needs.manual-publish.result == 'success' || needs.publish-stable.result == 'failure' || needs.manual-publish.result == 'failure')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Notification Messages
id: set-messages
run: |
VERSION="${{ needs.publish-stable.outputs.version }}${{ needs.manual-publish.outputs.version }}"
if [[ "${{ needs.publish-stable.result }}" == "success" || "${{ needs.manual-publish.result }}" == "success" ]]; then
RESULT="success"
else
RESULT="failure"
fi
if [[ "$RESULT" == "success" ]]; then
echo "SLACK_TITLE=Video Player $VERSION Deployed" >> $GITHUB_OUTPUT
echo "SLACK_MESSAGE=Success :rocket: cloudinary-video-player version $VERSION deployed successfully" >> $GITHUB_OUTPUT
echo "SLACK_FOOTER=Check it out at https://cloudinary.github.io/cloudinary-video-player/?ver=latest&min=true" >> $GITHUB_OUTPUT
echo "SLACK_COLOR=good" >> $GITHUB_OUTPUT
else
echo "SLACK_TITLE=Video Player Deployment Failed" >> $GITHUB_OUTPUT
echo "SLACK_MESSAGE=:alert: Failed to deploy cloudinary-video-player version $VERSION" >> $GITHUB_OUTPUT
echo "SLACK_FOOTER=See log here https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT
echo "SLACK_COLOR=danger" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2.2.0
env:
SLACK_WEBHOOK: ${{ vars.FE_DEPLOYMENTS_SLACK_WEBHOOK }}
SLACK_CHANNEL: 'rnd-me-video-team-alerts'
SLACK_COLOR: ${{ steps.set-messages.outputs.SLACK_COLOR }}
SLACK_TITLE: ${{ steps.set-messages.outputs.SLACK_TITLE }}
SLACK_MESSAGE: ${{ steps.set-messages.outputs.SLACK_MESSAGE }}
SLACK_FOOTER: ${{ steps.set-messages.outputs.SLACK_FOOTER }}