-
Notifications
You must be signed in to change notification settings - Fork 22
401 lines (358 loc) · 13.9 KB
/
create-release.yaml
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: "Create release"
run-name: Create release ${{ inputs.name }}
env:
IMAGE_REPO: europe-docker.pkg.dev/kyma-project/prod/kyma-environment-broker
KYMA_ENVIRONMENT_BROKER_REPO: ${{ github.repository_owner }}/kyma-environment-broker
GIT_EMAIL: [email protected]
GIT_NAME: kyma-gopher-bot
BUMP_CHART_AND_IMAGES: bump-chart-and-images-${{ inputs.name }}
on:
workflow_dispatch:
inputs:
name:
description: 'Create release'
default: ""
required: true
skip-sec-file-and-chart-bump:
type: boolean
description: 'Do not bump sec file and chart'
default: false
dry-run:
type: boolean
description: 'Do not publish'
default: false
workflow_call:
inputs:
name:
type: string
description: 'Create release'
default: ""
required: true
skip-sec-file-and-chart-bump:
type: boolean
description: 'Do not bump sec file and chart'
default: false
dry-run:
type: boolean
description: 'Do not publish'
default: false
jobs:
validate-release:
name: Validate release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if tag already exists
run: |
if [ $(git tag -l ${{ inputs.name }}) ]; then
echo "::error ::Tag ${{ inputs.name }} already exists"
exit 1
fi
- name: Check for existing artifacts from previous release runs
run: "./scripts/check_artifacts_existence.sh ${{ inputs.name }}"
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
- name: Install requirements
run: pip install -r scripts/python/requirements.txt
- name: Validate labels
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}
NAME: ${{ inputs.name }}
run: python3 scripts/python/release_label_validator.py
run-unit-tests:
name: Unit tests, go mod tidy
uses: "./.github/workflows/run-unit-tests-reusable.yaml"
build-keb-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-broker
dockerfile: Dockerfile.keb
context: .
tags: ${{ inputs.name }}
build-archiver-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-archiver-job
dockerfile: Dockerfile.job
context: .
build-args: BIN=archiver
tags: ${{ inputs.name }}
build-environments-cleanup-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environments-cleanup-job
dockerfile: Dockerfile.job
context: .
build-args: BIN=environmentscleanup
tags: ${{ inputs.name }}
build-deprovision-retrigger-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-deprovision-retrigger-job
dockerfile: Dockerfile.job
context: .
build-args: BIN=deprovisionretrigger
tags: ${{ inputs.name }}
build-expirator-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-expirator-job
dockerfile: Dockerfile.job
context: .
build-args: BIN=expirator
tags: ${{ inputs.name }}
build-runtime-reconciler-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-runtime-reconciler
dockerfile: Dockerfile.runtimereconciler
context: .
build-args: BIN=runtime-reconciler
tags: ${{ inputs.name }}
build-subaccount-cleanup-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-subaccount-cleanup-job
dockerfile: Dockerfile.job
context: .
build-args: BIN=accountcleanup
tags: ${{ inputs.name }}
build-subaccount-sync-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-subaccount-sync
dockerfile: Dockerfile.subaccountsync
context: .
build-args: BIN=subaccount-sync
tags: ${{ inputs.name }}
build-globalaccounts-image:
needs: [validate-release]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-globalaccounts
dockerfile: Dockerfile.globalaccounts
context: .
build-args: BIN=globalaccounts
tags: ${{ inputs.name }}
build-schema-migrator-image:
needs: [ validate-release ]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-broker-schema-migrator
dockerfile: Dockerfile.schemamigrator
context: .
tags: ${{ inputs.name }}
build-service-binding-cleanup-image:
needs: [ validate-release ]
uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main
with:
name: kyma-environment-service-binding-cleanup-job
dockerfile: Dockerfile.job
context: .
build-args: BIN=servicebindingcleanup
tags: ${{ inputs.name }}
run-keb-chart-install-tests:
name: Validate KEB chart
needs: [build-keb-image, build-archiver-image, build-environments-cleanup-image, build-deprovision-retrigger-image, build-expirator-image, build-runtime-reconciler-image, build-subaccount-cleanup-image, build-subaccount-sync-image, build-globalaccounts-image, build-schema-migrator-image, build-service-binding-cleanup-image]
uses: "./.github/workflows/run-keb-chart-install-tests-reusable.yaml"
secrets: inherit
with:
last-k3s-versions: ${{ vars.LAST_K3S_VERSIONS }}
release: "true"
version: ${{ inputs.name }}
bumps:
name: Bump sec-scanners-config, KEB chart
needs: [validate-release, run-unit-tests, run-keb-chart-install-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git pull
- name: Update sec-scanners-config.yaml
if: ${{ !inputs.skip-sec-file-and-chart-bump }}
run: scripts/create_scan_config.sh "sec-scanners-config.yaml" ${{ inputs.name }}
- name: Bump KEB chart
if: ${{ !inputs.skip-sec-file-and-chart-bump }}
run: scripts/bump_keb_chart.sh ${{ inputs.name }} "release"
- name: Check if any PR was merged during release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[0].sha')
echo "Latest commit sha: $COMMIT_SHA"
echo "Workflow sha: ${{ github.sha }}"
if [ "$COMMIT_SHA" != "${{ github.sha }}" ]; then
echo "::error ::a PR was merged during the release. Don't rerun this workflow, create a new release with the same version"
exit 1
fi
- name: Create PR if anything changed
if: ${{ !inputs.skip-sec-file-and-chart-bump }}
env:
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
prs=$(gh pr list -A ${{ env.GIT_NAME }} --state open --json headRefName | jq -r '.[] | .headRefName')
if echo $prs | tr " " '\n' | grep -F -q -x ${{ env.BUMP_CHART_AND_IMAGES }}; then
echo "PR already exists, no need to create a new one"
echo "PR_NUMBER=$(gh pr list --search "base:main head:${{ env.BUMP_CHART_AND_IMAGES }}" --json number | jq -r '.[] | .number')" >> $GITHUB_ENV
elif [ -z "$(git status --porcelain)" ]; then
echo "Nothing changed, no need to create PR"
echo "PR_NUMBER=-1" >> $GITHUB_ENV
else
PR_STATUS=$(scripts/create_bump_pr.sh ${{ inputs.name }})
echo "PR_NUMBER=$(echo "$PR_STATUS" | tail -n 1)" >> $GITHUB_ENV
fi
- name: Merge PR
if: ${{ !inputs.skip-sec-file-and-chart-bump }}
env:
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
REPOSITORY: ${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}
run: |
if [ "$PR_NUMBER" -gt 0 ]; then
scripts/merge_pr.sh
else
echo "Step skipped"
fi
- name: Await PR merge
if: ${{ !inputs.skip-sec-file-and-chart-bump }}
timeout-minutes: 45
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$PR_NUMBER" -gt 0 ]; then
scripts/await_pr_merge.sh
git push origin -d ${{ env.BUMP_CHART_AND_IMAGES }}
else
echo "Step skipped"
fi
- name: Check if any PR have been merged before merging the bump PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "$PR_NUMBER" -gt 0 ]; then
COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[1].sha')
echo "Latest commit sha: $COMMIT_SHA"
echo "Bump sha: ${{ github.sha }}"
if [ "$COMMIT_SHA" != "${{ github.sha }}" ]; then
echo "::error ::a PR have been merged before merging the bump PR. Don't rerun this workflow. Create a new release with the same version"
exit 1
fi
else
echo "Step skipped"
fi
- name: Save latest commit ref
id: pull-ref
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git checkout main
git stash
git pull
LATEST_COMMIT=$(git rev-parse HEAD)
echo "latest_commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT
echo "Latest commit ref $LATEST_COMMIT"
outputs:
latest_commit: ${{ steps.pull-ref.outputs.latest_commit }}
create-draft:
name: Create draft release
needs: bumps
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.bumps.outputs.latest_commit}}
- name: Check if any PR was merged after bumps
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[0].sha')
echo "Latest commit sha: $COMMIT_SHA"
echo "Bump sha: ${{ needs.bumps.outputs.latest_commit}}"
if [ "$COMMIT_SHA" != "${{ needs.bumps.outputs.latest_commit}}" ]; then
echo "::error ::a PR was merged after the bumps. Don't rerun this workflow, create a new release with the same version"
exit 1
fi
- name: Create draft release
id: create-draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository_owner }}/kyma-environment-broker
run: |
RELEASE_ID=$(./scripts/create_draft_release.sh ${{ github.event.inputs.name }})
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
- name: Create lightweight tag
run: |
git tag ${{ github.event.inputs.name }}
git push origin ${{ github.event.inputs.name }}
- name: Check if any PR may have been merged before creating the tag and draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
COMMIT_SHA=$(gh api repos/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/commits -q '.[0].sha')
echo "Latest commit sha: $COMMIT_SHA"
echo "Bump sha: ${{ needs.bumps.outputs.latest_commit}}"
if [ "$COMMIT_SHA" != "${{ needs.bumps.outputs.latest_commit}}" ]; then
echo "::error ::a PR may have been merged before the tag and draft release were created. Delete the tag and the draft release. Don't rerun this workflow. Create a new release with the same version"
exit 1
fi
outputs:
release_id: ${{ steps.create-draft.outputs.release_id }}
publish-release:
name: Publish release
needs: [bumps, create-draft]
if: ${{ !inputs.dry-run }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.bumps.outputs.latest_commit}}
- run: |
git checkout main
git pull
- name: Package KEB chart
run: |
OUTPUT=$(helm package ./resources/keb -d ./)
FILENAME=$(echo $OUTPUT | grep -o '[^ ]*.tgz')
echo "KEB_CHART=$FILENAME" >> $GITHUB_ENV
- name: Upload packaged KEB chart to release
env:
BOT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./scripts/upload_assets.sh ${{ needs.create-draft.outputs.release_id }} $KEB_CHART
- name: Update KEB chart metadata
run: |
git checkout gh-pages
helm repo index --url https://github.com/${{ env.KYMA_ENVIRONMENT_BROKER_REPO }}/releases/download/${{ inputs.name }} --merge ./index.yaml ./
- name: Commit KEB chart metadata to gh-pages branch
run: |
git config --global user.email ${{ env.GIT_EMAIL }}
git config --global user.name ${{ env.GIT_NAME }}
git add index.yaml
git commit -m "Update KEB chart metadata with version ${{ inputs.name }}"
git push origin gh-pages
- name: Publish release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository_owner }}/kyma-environment-broker
run: |
git checkout main
./scripts/publish_release.sh ${{ needs.create-draft.outputs.release_id }}