Repository navigation
472 lines (423 loc) · 19.2 KB
/
Copy pathrelease_workspace_version.yml
File metadata and controls
472 lines (423 loc) · 19.2 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
name: Prior Version Release Workspace
# Base-repository pushes do not require approval for backports from forks.
on:
push:
branches:
- 'release-1.*/*'
- 'release-*.*'
jobs:
check-merged-pr:
name: Classify prior-version release PR
runs-on: ubuntu-latest
outputs:
is_version_pr: ${{ steps.check_push.outputs.is_version_pr }}
is_existing_branch_push: ${{ steps.check_push.outputs.is_existing_branch_push }}
head_ref: ${{ steps.check_push.outputs.head_ref }}
is_repository_release: ${{ steps.classify_branch.outputs.is_repository_release }}
is_supported_branch: ${{ steps.classify_branch.outputs.is_supported_branch }}
workspace_name: ${{ steps.extract_workspace.outputs.workspace_name }}
version_branch_id: ${{ steps.extract_workspace.outputs.version_branch_id }}
steps:
- name: Identify merged PR for this push
id: check_push
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_REF: ${{ github.ref_name }}
COMMIT_SHA_BEFORE: ${{ github.event.before }}
run: |
# Branch creation is not a merge; do not start a release on its first push.
if [[ "$COMMIT_SHA_BEFORE" =~ ^0+$ ]]; then
echo 'is_existing_branch_push=false' >> "$GITHUB_OUTPUT"
echo 'is_version_pr=false' >> "$GITHUB_OUTPUT"
echo 'head_ref=' >> "$GITHUB_OUTPUT"
exit 0
fi
echo 'is_existing_branch_push=true' >> "$GITHUB_OUTPUT"
# The push event has no pull_request payload. Resolve the merged PR
# by its merge commit, not by the fork which supplied the PR head.
PR=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" \
| jq -c --arg sha "$GITHUB_SHA" --arg base "$BASE_REF" \
'map(select(.merged_at != null and .merge_commit_sha == $sha and .base.ref == $base)) | first // {}')
PR_TITLE=$(jq -r '.title // ""' <<< "$PR")
HEAD_REF=$(jq -r '.head.ref // ""' <<< "$PR")
USER_LOGIN=$(jq -r '.user.login // ""' <<< "$PR")
PR_MERGED=$(jq -r 'if .merged_at then "true" else "false" end' <<< "$PR")
echo "head_ref=$HEAD_REF" >> "$GITHUB_OUTPUT"
is_version_pr=false
if [[ "$PR_TITLE" == "Version Packages"* \
&& "$USER_LOGIN" == "rhdh-bot" \
&& "$PR_MERGED" == "true" ]]; then
if [[ "$BASE_REF" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
if [[ "$HEAD_REF" =~ ^maintenance-changesets-release/${BASE_REF}/[^/]+$ ]]; then
is_version_pr=true
fi
elif [[ "$BASE_REF" =~ ^release-1\.[0-9]+/[^/]+$ ]]; then
if [[ "$HEAD_REF" == "maintenance-changesets-release/$BASE_REF" ]]; then
is_version_pr=true
fi
fi
fi
echo "is_version_pr=$is_version_pr" >> "$GITHUB_OUTPUT"
- name: Classify target branch
id: classify_branch
env:
BASE_REF: ${{ github.ref_name }}
run: |
if [[ "$BASE_REF" =~ ^release-([0-9]+)\.[0-9]+$ ]]; then
RELEASE_MAJOR="${BASH_REMATCH[1]}"
if (( RELEASE_MAJOR >= 2 )); then
echo "is_repository_release=true" >> "$GITHUB_OUTPUT"
echo "is_supported_branch=true" >> "$GITHUB_OUTPUT"
echo "::notice title=Release workflow classification::$BASE_REF uses the repository-wide release path."
else
echo "is_repository_release=false" >> "$GITHUB_OUTPUT"
echo "is_supported_branch=false" >> "$GITHUB_OUTPUT"
echo "::warning title=Release workflow skipped::$BASE_REF is not a supported 1.x per-workspace branch or 2.x+ repository-wide branch. Use release-1.x/<workspace> for legacy releases."
fi
elif [[ "$BASE_REF" =~ ^release-1\.[0-9]+/[^/]+$ ]]; then
echo "is_repository_release=false" >> "$GITHUB_OUTPUT"
echo "is_supported_branch=true" >> "$GITHUB_OUTPUT"
echo "::notice title=Release workflow classification::$BASE_REF uses the legacy per-workspace release path."
else
echo "is_repository_release=false" >> "$GITHUB_OUTPUT"
echo "is_supported_branch=false" >> "$GITHUB_OUTPUT"
echo "::warning title=Release workflow skipped::$BASE_REF does not match release-1.x/<workspace> or release-2.x+."
fi
- name: Extract workspace name from branch
id: extract_workspace
env:
BASE_REF: ${{ github.ref_name }}
HEAD_REF: ${{ steps.check_push.outputs.head_ref }}
run: |
if [[ "$BASE_REF" =~ ^release-1\.[0-9]+/[^/]+$ ]]; then
WORKSPACE_NAME=$(echo "$BASE_REF" | cut -d'/' -f2)
VERSION_BRANCH_ID="$BASE_REF"
elif [[ "$BASE_REF" =~ ^release-[0-9]+\.[0-9]+$ && "$HEAD_REF" =~ ^maintenance-changesets-release/${BASE_REF}/[^/]+$ ]]; then
WORKSPACE_NAME=$(echo "$HEAD_REF" | cut -d'/' -f3)
VERSION_BRANCH_ID="$BASE_REF/$WORKSPACE_NAME"
else
WORKSPACE_NAME=""
VERSION_BRANCH_ID=""
fi
echo "workspace_name=$WORKSPACE_NAME" >> "$GITHUB_OUTPUT"
echo "version_branch_id=$VERSION_BRANCH_ID" >> "$GITHUB_OUTPUT"
if [[ -n "$WORKSPACE_NAME" ]]; then
echo "::notice title=Release workspace::$WORKSPACE_NAME (version branch ID: $VERSION_BRANCH_ID)"
else
echo "::warning title=Release workspace unavailable::Could not derive a workspace from base '$BASE_REF' and head '$HEAD_REF'. Release jobs will be skipped."
fi
changesets-pr:
name: LEGACY - Update Version Packages PR
runs-on: ubuntu-latest
needs: check-merged-pr
if: needs.check-merged-pr.outputs.is_supported_branch == 'true' && needs.check-merged-pr.outputs.is_version_pr == 'false' && needs.check-merged-pr.outputs.is_repository_release == 'false' && needs.check-merged-pr.outputs.is_existing_branch_push == 'true'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
defaults:
run:
working-directory: ./workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
YARN_ENABLE_SCRIPTS: false
outputs:
needs_release: ${{ steps.release_check.outputs.needs_release }}
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.ref }}
- name: Verify maintenance-changesets-release branch does not exist
env:
VERSION_BRANCH_ID: ${{ needs.check-merged-pr.outputs.version_branch_id }}
run: |
if git ls-remote --exit-code origin "refs/heads/maintenance-changesets-release/$VERSION_BRANCH_ID"; then
echo "Error: maintenance-changesets-release/$VERSION_BRANCH_ID branch already exists. Please clean up the branch before proceeding."
exit 1
fi
- name: Set up Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', needs.check-merged-pr.outputs.workspace_name)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Fetch previous commit for release check
env:
BASE_SHA: ${{ github.event.before }}
run: git fetch origin "$BASE_SHA"
- name: Fetch the commit that triggered the workflow (used by backstage/changesets-action)
run: git fetch origin "$GITHUB_SHA"
continue-on-error: true
- name: Check if release
id: release_check
run: |
yarn install
node scripts/ci/check-if-release.js
working-directory: ./
env:
WORKSPACE_NAME: ${{ needs.check-merged-pr.outputs.workspace_name }}
COMMIT_SHA_BEFORE: '${{ github.event.before }}'
TARGET_BRANCH: ${{ github.ref }}
- name: Update Version Packages (${{ needs.check-merged-pr.outputs.workspace_name }}) PR
id: changesets-pr
if: steps.release_check.outputs.needs_release != 'true'
uses: backstage/changesets-action@a39baf18913e669734ffb00c2fd9900472cfa240 # v2.3.2
with:
title: Version Packages (${{ needs.check-merged-pr.outputs.workspace_name }})
cwd: workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
version: yarn changeset version
versionBranch: maintenance-changesets-release/${{ needs.check-merged-pr.outputs.version_branch_id }}
skipRootChangelogUpdate: true
env:
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
repository-release-workspaces:
name: Find changed workspaces
runs-on: ubuntu-latest
needs: check-merged-pr
if: needs.check-merged-pr.outputs.is_supported_branch == 'true' && needs.check-merged-pr.outputs.is_repository_release == 'true' && needs.check-merged-pr.outputs.is_version_pr == 'false' && needs.check-merged-pr.outputs.is_existing_branch_push == 'true'
outputs:
workspaces: ${{ steps.find-workspaces.outputs.workspaces }}
steps:
- name: Checkout pushed commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.sha }}
fetch-depth: 0
- name: Find changed workspaces
id: find-workspaces
run: node scripts/ci/list-workspaces-with-changes.js
env:
COMMIT_SHA_BEFORE: ${{ github.event.before }}
INCLUDE_NOOP: 'false'
repository-changesets-pr:
name: Update Version Packages PR
runs-on: ubuntu-latest
needs:
- check-merged-pr
- repository-release-workspaces
if: needs.repository-release-workspaces.outputs.workspaces != '[]'
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ matrix.workspace }}
strategy:
fail-fast: false
matrix:
workspace: ${{ fromJSON(needs.repository-release-workspaces.outputs.workspaces) }}
defaults:
run:
working-directory: ./workspaces/${{ matrix.workspace }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
YARN_ENABLE_SCRIPTS: false
steps:
- name: Checkout pushed commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.sha }}
fetch-depth: 0
- name: Verify maintenance-changesets-release branch does not exist
env:
WORKSPACE: ${{ matrix.workspace }}
RELEASE_BRANCH: ${{ github.ref_name }}
run: |
VERSION_BRANCH_ID="$RELEASE_BRANCH/$WORKSPACE"
if git ls-remote --exit-code origin "refs/heads/maintenance-changesets-release/$VERSION_BRANCH_ID"; then
echo "Error: maintenance-changesets-release/$VERSION_BRANCH_ID branch already exists. Please clean up the branch before proceeding."
exit 1
fi
- name: Set up Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', matrix.workspace)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Fetch previous commit for release check
env:
BASE_SHA: ${{ github.event.before }}
run: git fetch origin "$BASE_SHA"
- name: Check if release
id: release_check
run: |
yarn install
node scripts/ci/check-if-release.js
working-directory: ./
env:
WORKSPACE_NAME: ${{ matrix.workspace }}
COMMIT_SHA_BEFORE: '${{ github.event.before }}'
TARGET_BRANCH: ${{ github.sha }}
- name: Update Version Packages (${{ matrix.workspace }}) PR
if: steps.release_check.outputs.needs_release != 'true'
uses: backstage/changesets-action@a39baf18913e669734ffb00c2fd9900472cfa240 # v2.3.2
with:
title: Version Packages (${{ matrix.workspace }})
cwd: workspaces/${{ matrix.workspace }}
version: yarn changeset version
versionBranch: maintenance-changesets-release/${{ github.ref_name }}/${{ matrix.workspace }}
skipRootChangelogUpdate: true
env:
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
release:
name: LEGACY - Publish legacy workspace
runs-on: ubuntu-latest
needs: check-merged-pr
if: needs.check-merged-pr.outputs.is_supported_branch == 'true' && needs.check-merged-pr.outputs.is_version_pr == 'true' && needs.check-merged-pr.outputs.is_repository_release == 'false'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
defaults:
run:
working-directory: ./workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.sha }}
- name: Set up Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Install root dependencies
run: yarn install --immutable
working-directory: ${{ github.workspace }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', needs.check-merged-pr.outputs.workspace_name)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Compile TypeScript
run: yarn tsc:full
- name: Build all packages
run: yarn build:all
- name: Verify release commit
env:
RELEASE_SHA: ${{ github.sha }}
run: |
actual_sha=$(git rev-parse HEAD)
if [ "$actual_sha" != "$RELEASE_SHA" ]; then
echo "::error::Refusing to publish $actual_sha; expected release commit $RELEASE_SHA" >&2
exit 1
fi
- name: publish
run: |
yarn config set -H 'npmAuthToken' "$NODE_AUTH_TOKEN"
yarn workspaces foreach -A -v --no-private npm publish --access public --tolerate-republish --tag "maintenance"
env:
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
- name: Create tag
working-directory: ${{ github.workspace }}/scripts/ci
run: node create-tag.js
env:
WORKSPACE_NAME: ${{ needs.check-merged-pr.outputs.workspace_name }}
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
update-overlays:
name: Update overlays after maintenance release
needs: [check-merged-pr, release, repository-release]
# One publish job is always skipped: evaluate explicitly after both finish.
if: >-
!cancelled() &&
github.repository == 'redhat-developer/rhdh-plugins' &&
needs.check-merged-pr.outputs.is_version_pr == 'true' &&
(needs.release.result == 'success' || needs.repository-release.result == 'success')
uses: ./.github/workflows/update-overlays.yml
with:
workspace: ${{ needs.check-merged-pr.outputs.workspace_name }}
branch: ${{ github.ref_name }}
secrets:
RHDH_BOT_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
repository-release:
name: Publish workspace
runs-on: ubuntu-latest
needs:
- check-merged-pr
if: needs.check-merged-pr.outputs.is_supported_branch == 'true' && needs.check-merged-pr.outputs.is_version_pr == 'true' && needs.check-merged-pr.outputs.is_repository_release == 'true'
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ needs.check-merged-pr.outputs.workspace_name }}
defaults:
run:
working-directory: ./workspaces/${{ needs.check-merged-pr.outputs.workspace_name }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
steps:
- name: Checkout pushed Version Packages commit
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ github.sha }}
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Install root dependencies
run: yarn install --immutable
working-directory: ${{ github.workspace }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', needs.check-merged-pr.outputs.workspace_name)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Compile TypeScript
run: yarn tsc:full
- name: Build all packages
run: yarn build:all
- name: Verify release commit
env:
RELEASE_SHA: ${{ github.sha }}
run: |
actual_sha=$(git rev-parse HEAD)
if [ "$actual_sha" != "$RELEASE_SHA" ]; then
echo "::error::Refusing to publish $actual_sha; expected release commit $RELEASE_SHA" >&2
exit 1
fi
- name: publish
run: |
yarn config set -H 'npmAuthToken' "$NODE_AUTH_TOKEN"
yarn workspaces foreach -A -v --no-private npm publish --access public --tolerate-republish --tag "maintenance"
env:
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
- name: Create tag
working-directory: ${{ github.workspace }}/scripts/ci
run: node create-tag.js
env:
WORKSPACE_NAME: ${{ needs.check-merged-pr.outputs.workspace_name }}
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}