-
Notifications
You must be signed in to change notification settings - Fork 176
350 lines (326 loc) · 15.3 KB
/
cut-rc.yml
File metadata and controls
350 lines (326 loc) · 15.3 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
name: "RELEASE: Cut RC"
on:
milestone:
types:
- closed
workflow_dispatch:
inputs:
version:
description: Full RC version (A.B.C[-N]-rc.D)
required: true
default: 0.0.0-test-rc.1
type: string
dry-run:
description: Dry-run
required: false
default: true
type: boolean
create-k8s-cluster:
description: Create a GKE demo cluster
required: true
default: true
type: boolean
create-os4-cluster:
description: Create an Openshift 4 demo cluster
required: true
default: true
type: boolean
create-long-cluster:
description: Create a long-running cluster on RC1
required: true
default: true
type: boolean
check-jira-issues:
description: Check Jira issues for current release
required: true
default: true
type: boolean
env:
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
TIMEOUT_WAIT_FOR_IMAGES_SECONDS: 3600
run-name: >-
${{
format('Cut {0}{1}{2}',
github.event.milestone.title,
inputs.version,
fromJSON('[" (dry-run)", ""]')[github.event.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:
properties:
runs-on: ubuntu-latest
outputs:
slack-channel: ${{ fromJSON(format('["{0}","{1}"]', steps.fetch.outputs.dry-slack-channel, steps.fetch.outputs.slack-channel))[github.event.inputs.dry-run != 'true'] }}
jira-project: ${{ steps.fetch.outputs.jira-project }}
steps:
- name: Read workflow properties file
id: fetch
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"
if [ "${{github.event_name}}" = "workflow_dispatch" ]; then
cat <<EOF >>"$GITHUB_STEP_SUMMARY"
\`\`\`
${{toJSON(inputs)}}
\`\`\`
EOF
fi
variables:
name: Setup variables
uses: ./.github/workflows/variables.yml
with:
version: ${{format('{0}{1}', github.event.milestone.title, github.event.inputs.version)}}
assert-format: A.B.C[-N]-rc.D
check-jira:
name: Check Jira tickets for release
needs: [variables, properties]
runs-on: ubuntu-latest
steps:
- name: Query JIRA
# Checking unequal with "false" because closed milestones have unset input values.
if: github.event.inputs.check-jira-issues != 'false'
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-issues \
"${{needs.properties.outputs.jira-project}}" \
"${{needs.variables.outputs.release}}" \
"${{needs.variables.outputs.patch}}" \
"${{needs.variables.outputs.named-release-patch}}"
postpone-prs:
name: Postpone open PRs
needs: variables
runs-on: ubuntu-latest
steps:
- name: Check open PRs
id: check
run: |
set -u
PRs=$(gh pr list -s open \
--repo "${{github.repository}}" \
--search "milestone:${{needs.variables.outputs.milestone}}" \
--json number \
--jq length)
if [ "$PRs" -gt 0 ]; then
echo "open-issues=$PRs" >> "$GITHUB_OUTPUT"
fi
- name: Create next milestone
if: env.DRY_RUN == 'false' && steps.check.outputs.open-issues != ''
run: |
set -u
if ! RESPONSE=$(gh api -X POST \
"repos/${{github.repository}}/milestones" \
-f title="${{needs.variables.outputs.next-milestone}}" \
2>&1); then
if grep "HTTP 422" <<< "$RESPONSE"; then
echo "Milestone ${{needs.variables.outputs.next-milestone}} already exists." >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::Couldn't create milestone ${{needs.variables.outputs.next-milestone}}: $RESPONSE"
exit 1
fi
else
NEXT_MILESTONE_URL=$(echo "${RESPONSE}" | jq -r '.html_url')
echo ":arrow_right: Close the newly created [milestone ${{ needs.variables.outputs.next-milestone }}](${NEXT_MILESTONE_URL}) when ready, or delete it when finishing the release." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Move open PRs
run: |
set -u
PRS=$(gh pr list -s open \
--repo "${{github.repository}}" \
--search "milestone:${{needs.variables.outputs.milestone}}" \
--json number \
--jq ".[] | .number")
echo "The following PRs are still open: $PRS"
for PR in $PRS; do
[ "$DRY_RUN" = "false" ] && \
gh pr edit "$PR" \
--milestone "${{needs.variables.outputs.next-milestone}}" \
--repo "${{github.repository}}"
echo "PR $PR has been moved to milestone ${{needs.variables.outputs.next-milestone}}." >> "$GITHUB_STEP_SUMMARY"
done
cut-rc:
name: Tag RC for milestone ${{needs.variables.outputs.milestone}}
runs-on: ubuntu-latest
needs: [variables, properties, postpone-prs, check-jira]
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6
with:
ref: ${{needs.variables.outputs.branch}}
token: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
- name: Initialize mandatory git config
run: |
git config user.name "${{github.event.sender.login}}"
git config user.email noreply@github.com
- name: Check CHANGELOG entry exists for release "${{ needs.variables.outputs.named-release-patch }}"
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{ env.script_url }}" | bash -s -- \
check-changelog \
"${{ needs.variables.outputs.branch }}" \
"${{ needs.variables.outputs.named-release-patch }}"
- run: |
# Could be optimized: done only if there are closed PRs to cherry-pick
git fetch origin ${{env.main_branch}}:${{env.main_branch}} --unshallow
- name: Cherry-pick commits from the main branch
id: cherry-pick
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
cherry-pick \
"${{needs.variables.outputs.milestone}}" \
"${{needs.variables.outputs.branch}}" \
"${{needs.variables.outputs.named-release-patch}}"
- name: Post to Slack about picked cherries
if: failure() && steps.cherry-pick.outputs.bad-cherries != ''
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: "Couldn't close upstream milestone ${{needs.variables.outputs.milestone}} on <${{github.server_url}}/${{github.repository}}|${{github.repository}}>. See workflow run <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}|${{github.workflow}}> for details."
blocks:
- type: "section"
text:
type: "mrkdwn"
text: |
:${{ fromJSON('["desert", "red_circle"]')[github.event.inputs.dry-run != 'true'] }}:
*Couldn't close upstream milestone ${{needs.variables.outputs.milestone}} on <${{github.server_url}}/${{github.repository}}|${{github.repository}}>.*
- type: "section"
text:
type: "mrkdwn"
text: |
*Couldn't cherry-pick the following PRs to the release branch:*
${{steps.cherry-pick.outputs.bad-cherries}}
- type: "divider"
- type: "section"
text:
type: "mrkdwn"
text: |
:arrow_right: *Please assist the PR assignees in merging their changes to `${{needs.variables.outputs.branch}}` branch
and then re-run failed jobs of the <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}|workflow run>.*
- type: "section"
text:
type: "mrkdwn"
text: |
> Repository: <${{github.server_url}}/${{github.repository}}|${{github.repository}}>
> Milestone: <${{github.event.milestone.html_url}}|${{needs.variables.outputs.milestone}}>
> Workflow: <${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}|${{github.workflow}}>
- name: Tag release branch with "${{needs.variables.outputs.milestone}}"
id: tag
env:
GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
tag-rc \
"${{needs.variables.outputs.milestone}}"
- name: Create next milestone
if: env.DRY_RUN == 'false'
env:
GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
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 "Milestone ${{needs.variables.outputs.next-milestone}} already exists." >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::Couldn't create milestone ${{needs.variables.outputs.next-milestone}}: $http_code"
exit 1
fi
else
echo ":arrow_right: Close the newly created milestone [${{needs.variables.outputs.next-milestone}}](${{github.event.milestone.html_url}}) when ready." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Create GitHub Pre-release
id: pre-release
if: env.DRY_RUN == 'false'
env:
GH_TOKEN: ${{ secrets.RHACS_BOT_GITHUB_TOKEN }}
run: |
set -uo pipefail
gh api -H "$ACCEPT_RAW" "${{env.script_url}}" | bash -s -- \
create-release \
"${{ needs.variables.outputs.milestone }}" \
"${{ needs.variables.outputs.branch }}" \
"true"
- name: Post to Slack
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 candidate <${{steps.pre-release.outputs.url}}|${{needs.variables.outputs.milestone}}> of <${{github.server_url}}/${{github.repository}}|${{github.repository}}> has been published on GitHub"
blocks:
- type: "section"
text:
type: "mrkdwn"
text: |
:${{ fromJSON('["desert", "white_check_mark"]')[github.event.inputs.dry-run != 'true'] }}: *Upstream release candidate <${{steps.pre-release.outputs.url}}|${{needs.variables.outputs.milestone}}> of <${{github.server_url}}/${{github.repository}}|${{github.repository}}> has been published on GitHub*
- type: "divider"
- type: "section"
text:
type: "mrkdwn"
text: |
:arrow_right: Once all checks pass and you're ready for release, run the <${{ github.server_url }}/${{ github.repository }}/actions/workflows/finish-release.yml|Finish Release> workflow and delete the `${{ needs.variables.outputs.next-milestone }}` milestone to avoid confusion.
trim-cluster-names:
runs-on: ubuntu-latest
outputs:
cluster-with-fake-load-name-cleaned: ${{ steps.cluster-names.outputs.cluster-with-fake-load-name-cleaned }}
cluster-with-real-load-name-cleaned: ${{ steps.cluster-names.outputs.cluster-with-real-load-name-cleaned }}
env:
CLUSTER_WITH_FAKE_LOAD_NAME: lfl-${{format('{0}{1}', github.event.milestone.title, github.event.inputs.version)}}
CLUSTER_WITH_REAL_LOAD_NAME: lrl-${{format('{0}{1}', github.event.milestone.title, github.event.inputs.version)}}
steps:
- name: Trim and clean cluster names
id: cluster-names
run: |
# Cluster names are cropped to infra's max length and dots replaced with dashes.
# Latter is to avoid informing release engineers of incorrect cluster names.
CLEANED_CLUSTER_WITH_FAKE_LOAD_NAME="$(echo "${CLUSTER_WITH_FAKE_LOAD_NAME:0:28}" | tr '.' '-')"
echo "cluster-with-fake-load-name-cleaned=${CLEANED_CLUSTER_WITH_FAKE_LOAD_NAME}" >> "${GITHUB_OUTPUT}"
CLEANED_CLUSTER_WITH_REAL_LOAD_NAME="$(echo "${CLUSTER_WITH_REAL_LOAD_NAME:0:28}" | tr '.' '-')"
echo "cluster-with-real-load-name-cleaned=${CLEANED_CLUSTER_WITH_REAL_LOAD_NAME}" >> "${GITHUB_OUTPUT}"
clusters:
name: Setup demo clusters
secrets: inherit
needs: [variables, cut-rc, trim-cluster-names]
uses: stackrox/actions/.github/workflows/create-demo-clusters.yml@9238e423c3ae1ac4eb0f254cbb98da9daae24d86 # ratchet:stackrox/actions/.github/workflows/create-demo-clusters.yml@v1
if: >- # Skip if no clusters are going to be created. Checking unequal with "false" because closed milestones have unset input values.
github.event.inputs.create-k8s-cluster != 'false' ||
github.event.inputs.create-os4-cluster != 'false' ||
needs.variables.outputs.rc == '1' &&
github.event.inputs.create-long-cluster != 'false'
with:
version: ${{needs.variables.outputs.milestone}}
create-k8s-cluster: ${{github.event.inputs.create-k8s-cluster != 'false'}}
create-os4-cluster: ${{github.event.inputs.create-os4-cluster != 'false'}}
create-long-cluster: ${{needs.variables.outputs.rc == '1' && github.event.inputs.create-long-cluster != 'false'}}
dry-run: ${{github.event.inputs.dry-run == 'true'}}
workflow-ref: v1
kube-burner-config-ref: ${{needs.variables.outputs.milestone}}
kube-burner-config-repo: stackrox
cluster-with-fake-load-name: ${{ needs.trim-cluster-names.outputs.cluster-with-fake-load-name-cleaned }}
cluster-with-real-load-name: ${{ needs.trim-cluster-names.outputs.cluster-with-real-load-name-cleaned }}