-
Notifications
You must be signed in to change notification settings - Fork 174
403 lines (380 loc) · 18.2 KB
/
start-release.yml
File metadata and controls
403 lines (380 loc) · 18.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
name: "RELEASE: Start Release"
on:
workflow_dispatch:
inputs:
version:
description: Release version (A.B.C[-N])
required: true
default: 0.0.0
type: string
ref:
description: Override release branch starting ref
required: false
default: ""
type: string
dry-run:
description: Dry-run
required: false
default: false
type: boolean
env:
USER_REF: ${{ inputs.ref }}
main_branch: ${{github.event.repository.default_branch}}
script_url: /repos/${{ github.repository }}/contents/.github/workflows/scripts/common.sh?ref=${{ github.ref_name }}
DRY_RUN: ${{ fromJSON('["true", "false"]')[github.event.inputs.dry-run != 'true'] }}
ACCEPT_RAW: "Accept: application/vnd.github.v3.raw"
GH_TOKEN: ${{ github.token }}
GH_NO_UPDATE_NOTIFIER: 1
run-name: >-
${{
format('Start release {0} from {1}{2}',
inputs.version,
fromJSON(format('["{0}","{1}"]', inputs.ref, 'the last nightly branching point'))[inputs.ref == ''],
fromJSON('[" (dry-run)", ""]')[inputs.dry-run != true]
)
}}
# Ensure that only a single automation workflow can run at a time for each release.
concurrency: Release automation ${{ inputs.version }}
jobs:
start-sha:
name: Find commit for release branch
runs-on: ubuntu-latest
outputs:
start-sha: ${{ fromJSON(format('["{0}","{1}"]', env.USER_REF, steps.find.outputs.merge_base))[env.USER_REF == ''] }}
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0
- name: Print user-provided input
run: |
if [ "${{ env.USER_REF }}" != '' ]; then
echo "User provided the following override for the git-sha: \`${{ env.USER_REF }}\`" >> "$GITHUB_STEP_SUMMARY"
else
echo "User did not provide override for the git-sha" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Find merge-base for ${{ github.event.repository.default_branch }} and 'origin/nightlies'
id: find
run: |
MERGEBASE="$(git merge-base origin/nightlies ${{ github.event.repository.default_branch }})"
echo "merge_base=${MERGEBASE}" >> "$GITHUB_OUTPUT"
echo "Found the following git-sha as a branching point for the release branch: [\`${MERGEBASE}\`](${{github.server_url}}/${{github.repository}}/commits/${MERGEBASE})" >> "$GITHUB_STEP_SUMMARY"
properties:
name: Read repository properties
runs-on: ubuntu-latest
outputs:
docs-repository: ${{ steps.properties.outputs.docs-repository }}
slack-channel: ${{ fromJSON(format('["{0}","{1}"]', steps.properties.outputs.dry-slack-channel, steps.properties.outputs.slack-channel))[github.event.inputs.dry-run != 'true'] }}
jira-project: ${{ steps.properties.outputs.jira-project }}
steps:
- name: Read workflow properties file
id: properties
env:
PROPERTIES_URL: /repos/${{ github.repository }}/contents/.github/properties?ref=${{ github.ref_name }}
run: gh api -H "$ACCEPT_RAW" "$PROPERTIES_URL" >> "$GITHUB_OUTPUT"
run-parameters:
name: Run parameters
runs-on: ubuntu-latest
steps:
- run: |
[ "$DRY_RUN" = "true" ] && echo "::warning::This is a dry run"
echo "Event: ${{github.event_name}}" >>"$GITHUB_STEP_SUMMARY"
cat <<EOF >>"$GITHUB_STEP_SUMMARY"
\`\`\`
${{toJSON(inputs)}}
\`\`\`
EOF
variables:
name: Setup variables
uses: ./.github/workflows/variables.yml
with:
version: ${{github.event.inputs.version}}
assert-format: A.B.C[-N]
check-jira:
name: Check Jira release
needs: [variables, properties]
runs-on: ubuntu-latest
outputs:
release-date: ${{steps.check-jira-release.outputs.date}}
steps:
- name: Check that Jira release ${{needs.variables.outputs.release}}.${{needs.variables.outputs.patch}} is not released
id: check-jira-release
env:
JIRA_USER: ${{ vars.RHACS_BOT_GITHUB_EMAIL }}
JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }}
JIRA_BASE_URL: ${{ vars.JIRA_BASE_URL }}
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
check-jira-release \
"${{needs.variables.outputs.release}}.${{needs.variables.outputs.patch}}" \
"${{needs.properties.outputs.jira-project}}"
branch:
name: Prepare release branch
needs: [variables, start-sha, check-jira]
runs-on: ubuntu-latest
steps:
- name: Check out code (normal release)
if: needs.variables.outputs.patch == 0
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
ref: ${{ needs.start-sha.outputs.start-sha }}
fetch-depth: 0
token: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
- name: Check out code (patch release)
if: needs.variables.outputs.patch != 0
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
ref: ${{ needs.variables.outputs.branch }}
submodules: true
token: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
- name: Check remote branch exists
id: check-existing
run: |
if git ls-remote --quiet --exit-code origin "${{needs.variables.outputs.branch}}"; then
echo "branch-exists=true" >> "$GITHUB_OUTPUT"
else
echo "branch-exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Fail if there is no branch for patch release
if: steps.check-existing.outputs.branch-exists == 'false' && needs.variables.outputs.patch != 0
run: exit 1
- name: Initialize mandatory git config
run: |
git config user.name "${{github.event.sender.login}}"
git config user.email noreply@github.com
- name: Create release branch ${{needs.variables.outputs.branch}}
if: steps.check-existing.outputs.branch-exists == 'false'
run: |
git switch --create "${{needs.variables.outputs.branch}}"
git commit --allow-empty --message \
"Empty commit to diverge ${{needs.variables.outputs.release}} from ${{env.main_branch}}"
- name: Tag release branch with rc.0 ${{needs.variables.outputs.branch}}
run: |
git tag --annotate --message "Upstream automation" \
"${{needs.variables.outputs.release}}.${{needs.variables.outputs.patch}}-rc.0" HEAD
- name: Update the changelog on the release branch
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
patch-release-changelog \
"${{inputs.version}}"
- name: Tag ${{env.main_branch}} for next release
if: steps.check-existing.outputs.branch-exists == 'false'
run: |
# There could be several commits between the starting point of the release branch and the HEAD
# on main/master tagged with the next release. While this leaves those intermediate
# commits tagged with the previous release, this is better than changing the build tag for
# those commits after all their artifacts have already been built and tested.
git switch ${{env.main_branch}}
git pull origin --rebase ${{env.main_branch}}
git tag --annotate --message "Upstream automation" \
"${{needs.variables.outputs.next-minor-release}}.x" HEAD
- name: Push changes
if: env.DRY_RUN == 'false'
env:
GH_TOKEN: "${{ secrets.RHACS_BOT_GITHUB_TOKEN }}"
run: |
git switch "${{needs.variables.outputs.branch}}"
# This command pushes all new tags, not just the ones on the current branch. Therefore, it will push the tag we put on ${{env.main_branch}}.
git push --follow-tags --set-upstream origin "${{needs.variables.outputs.branch}}"
ci:
name: Configure OpenShift CI jobs
needs: [variables, branch]
if: needs.variables.outputs.patch == 0
runs-on: ubuntu-latest
env:
RELEASE: "${{needs.variables.outputs.release}}"
BRANCH: "stackrox-release-${{needs.variables.outputs.release}}"
steps:
- name: Check remote branch exists
id: check-existing
run: |
if gh api --silent -H "$ACCEPT_RAW" "/repos/stackrox/openshift-release/branches/${BRANCH}"; then
echo "branch-exists=true" >> "$GITHUB_OUTPUT"
echo "::notice::OpenShift CI configuration branch exists. Assuming CI is ready."
else
echo "branch-exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Synchronize fork from openshift/release
if: env.DRY_RUN == 'false' && steps.check-existing.outputs.branch-exists == 'false'
env:
GH_TOKEN: "${{ secrets.RHACS_BOT_GITHUB_TOKEN }}"
run: |
gh repo sync stackrox/openshift-release --source openshift/release
- name: Check out stackrox/openshift-release
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
repository: stackrox/openshift-release
token: "${{ secrets.RHACS_BOT_GITHUB_TOKEN }}"
- name: Initialize git config and create new branch
if: steps.check-existing.outputs.branch-exists == 'false'
run: |
git config user.name "${{github.event.sender.login}}"
git config user.email noreply@github.com
git switch --create "$BRANCH"
- name: Make configuration
if: steps.check-existing.outputs.branch-exists == 'false'
env:
CFG_DIR: "ci-operator/config/stackrox/stackrox"
run: |
# Duplicate the template configurations
for yaml in "$CFG_DIR"/stackrox-stackrox-release-x.y*.yaml ; do
yq eval ".zz_generated_metadata.branch=\"release-$RELEASE\"" "$yaml" > "${yaml//stackrox-release-x.y/$BRANCH}"
done
- name: Make update
if: steps.check-existing.outputs.branch-exists == 'false'
run: |
make update
git add ci-operator
git commit -m "Release $RELEASE files" >> "$GITHUB_STEP_SUMMARY"
- name: Push and create PR
if: env.DRY_RUN == 'false' && steps.check-existing.outputs.branch-exists == 'false'
env:
GH_TOKEN: "${{ secrets.RHACS_BOT_GITHUB_TOKEN }}"
run: |
git push --set-upstream origin "$BRANCH"
PR_URL=$(gh pr create --repo openshift/release \
--title "Stackrox release $RELEASE" \
--base "master" \
--body "CI configuration files to support Stackrox release \`$RELEASE\`.")
PR_NUMBER="$(echo "${PR_URL}" | rev | cut -d '/' -f1 | rev)"
gh pr comment "${PR_NUMBER}" --repo openshift/release --body "/assign ${GITHUB_ACTOR}"
echo ":arrow_right: Review and merge the [PR]($PR_URL) that has been created for the \`openshift/release\` repository." >> "$GITHUB_STEP_SUMMARY"
patch-main-changelog:
name: Patch CHANGELOG.md on the default branch
needs: [variables, branch, start-sha]
if: needs.variables.outputs.patch == 0
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
# Working on `start-sha` instead of `env.main_branch` may help
# to spot changes happened to CHANGELOG.md after `start-sha`.
ref: ${{ needs.start-sha.outputs.start-sha }}
- name: Initialize mandatory git config
run: |
git config user.name "${{github.event.sender.login}}"
git config user.email noreply@github.com
- name: Patch CHANGELOG.md on ${{ needs.start-sha.outputs.start-sha }}
env:
GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
patch-main-changelog \
"${{needs.variables.outputs.release}}.${{needs.variables.outputs.patch}}" \
"${{ needs.start-sha.outputs.start-sha }}" \
"${{needs.variables.outputs.branch}}"
patch-scanner-versions:
name: Patch Scanner updater configuration
needs: [variables, branch]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
ref: ${{ env.main_branch }}
- name: Initialize mandatory git config
run: |
git config user.name "${{github.event.sender.login}}"
git config user.email noreply@github.com
- name: Patch scanner/updater/version/RELEASE_VERSION for ${{needs.variables.outputs.release}}.${{needs.variables.outputs.patch}}
env:
GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
patch-scanner-updater-configuration \
"${{needs.variables.outputs.release}}.${{needs.variables.outputs.patch}}"
milestone:
name: Create milestone
needs: [variables]
runs-on: ubuntu-latest
steps:
- name: Create ${{needs.variables.outputs.next-milestone}} milestone
if: env.DRY_RUN == 'false'
run: |
set -u
if ! http_code=$(gh api --silent -X POST \
"repos/${{github.repository}}/milestones" \
-f title="${{needs.variables.outputs.next-milestone}}" \
2>&1); then
if grep "HTTP 422" <<< "$http_code"; then
echo ":arrow_right: Milestone ${{needs.variables.outputs.next-milestone}} already exists." \
"**Close it once it's finished.**" >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::Couldn't create milestone ${{needs.variables.outputs.next-milestone}}: $http_code"
exit 1
fi
else
echo ":arrow_right: Milestone ${{needs.variables.outputs.next-milestone}} has been created." \
"**Close it once it's finished.**" >> "$GITHUB_STEP_SUMMARY"
fi
notify:
name: Notify everybody
needs: [variables, properties, branch, milestone]
runs-on: ubuntu-latest
steps:
- name: Post to Slack (normal release)
if: needs.variables.outputs.patch == 0
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # ratchet:slackapi/slack-github-action@v3.0.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: "${{ needs.properties.outputs.slack-channel }}"
text: "Upstream release ${{needs.variables.outputs.named-release-patch}} has been triggered. Consult the tracker for next steps."
blocks:
- type: "section"
text:
type: "mrkdwn"
text: |
:${{ fromJSON('["desert", "white_check_mark"]')[github.event.inputs.dry-run != 'true'] }}: *Upstream release ${{needs.variables.outputs.named-release-patch}} has been triggered on <${{github.server_url}}/${{github.repository}}|${{github.repository}}> by ${{ github.event.sender.login }}.*
- type: "section"
text:
type: "mrkdwn"
text: |
Branch `${{needs.variables.outputs.branch}}` and milestone `${{needs.variables.outputs.next-milestone}}` have been created.
PRs merged to the ${{env.main_branch}} branch and assigned to RC milestones will be cherry-picked when closing the respective milestones.
For the urgent fixes that must go exclusively to this release open PRs to the `${{needs.variables.outputs.branch}}` branch.
- type: "divider"
- type: "section"
text:
type: "mrkdwn"
text: |
> Repository: <${{github.server_url}}/${{github.repository}}|${{github.repository}}>
> Release: ${{needs.variables.outputs.named-release-patch}}
> Workflow: <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}|${{github.workflow}}>
- name: Post to Slack (patch release)
if: needs.variables.outputs.patch != 0
uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # ratchet:slackapi/slack-github-action@v3.0.1
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: "${{ needs.properties.outputs.slack-channel }}"
text: "Upstream patch release ${{needs.variables.outputs.named-release-patch}} has been triggered. Consult the tracker for next steps."
blocks:
- type: "section"
text:
type: "mrkdwn"
text: |
:${{ fromJSON('["desert", "white_check_mark"]')[github.event.inputs.dry-run != 'true'] }}: *Upstream patch release ${{needs.variables.outputs.named-release-patch}} has been triggered on <${{github.server_url}}/${{github.repository}}|${{github.repository}}> by ${{ github.event.sender.login }}.*
- type: "section"
text:
type: "mrkdwn"
text: |
Milestone `${{needs.variables.outputs.next-milestone}}` has been created.
PRs merged to the ${{env.main_branch}} branch and assigned to RC milestones will be cherry-picked when closing the respective milestones.
For the urgent fixes that must go exclusively to this release open PRs to the `${{needs.variables.outputs.branch}}` branch.
- type: "divider"
- type: "section"
text:
type: "mrkdwn"
text: |
> Repository: <${{github.server_url}}/${{github.repository}}|${{github.repository}}>
> Release: ${{needs.variables.outputs.named-release-patch}}
> Workflow: <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}|${{github.workflow}}>