-
Notifications
You must be signed in to change notification settings - Fork 0
470 lines (416 loc) · 16.4 KB
/
release_prep_hatch.yml
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
# **what?**
# Perform the version bump, generate the changelog and run tests.
#
# Inputs:
# branch: The branch that we will release from
# version: The release version number (i.e. 1.0.0b1, 1.2.3rc2, 1.0.0)
# deploy-to: If we are deploying to prod or test, if test then release from branch
# is-nightly-release: Identifier that this is nightly release
#
# Outputs:
# release-sha: The sha that will actually be released. This can differ from the
# input sha if adding a version bump and/or changelog
# changelog-path: Path to the changelog file (ex .changes/1.2.3-rc1.md)
#
# Branching strategy:
# - During execution workflow execution the temp branch will be generated.
# - For normal runs the temp branch will be removed once changes were merged to target branch;
# - For test runs we will keep temp branch and will use it for release;
# Naming strategy:
# - For normal runs: prep-release/${{ inputs.deploy-to}}/${{ inputs.version }}_$GITHUB_RUN_ID
# - For nightly releases: prep-release/nightly-release/${{ inputs.version }}_$GITHUB_RUN_ID
#
# **why?**
# Reusable and consistent GitHub release process.
#
# **when?**
# Call when ready to kick off a build and release
#
# Validation Checks
#
# 1. Bump the version if it has not been bumped
# 2. Generate the changelog (via changie) if there is no markdown file for this version
name: "Release prep"
run-name: "Release prep: Generate changelog and bump to ${{ inputs.version }} for release to ${{ inputs.deploy-to }}"
on:
workflow_call:
inputs:
branch:
description: "The branch to release from"
type: string
default: "main"
version:
description: "The version to release"
required: true
type: string
deploy-to:
description: "Deploy to test or prod"
type: string
default: "prod"
is-nightly-release:
description: "Identify if this is a nightly release"
type: boolean
default: false
outputs:
release-branch:
description: "The branch to be released from"
value: ${{ jobs.release.outputs.branch }}
release-sha:
description: "The SHA to be released"
value: ${{ jobs.release.outputs.sha }}
changelog-path:
description: "The path to the changelog from the repo root for this version, e.g. .changes/1.8.0-b1.md"
value: ${{ jobs.release-inputs.outputs.changelog-path }}
secrets:
FISHTOWN_BOT_PAT:
description: "Token to commit/merge changes into branches"
required: true
IT_TEAM_MEMBERSHIP:
description: "Token that can view org level teams"
required: true
permissions:
contents: write
defaults:
run:
shell: bash
env:
PYTHON_TARGET_VERSION: 3.12
NOTIFICATION_PREFIX: "[Release Prep]"
jobs:
release-inputs:
runs-on: ubuntu-latest
outputs:
changelog-path: ${{ steps.changelog.outputs.path }}
changelog-exists: ${{ steps.changelog.outputs.exists }}
base-version: ${{ steps.semver.outputs.base-version }}
pre-release: ${{ steps.semver.outputs.pre-release }}
is-pre-release: ${{ steps.semver.outputs.is-pre-release }}
version-is-current: ${{ steps.version.outputs.is-current }}
steps:
- name: "[DEBUG] Log inputs"
run: |
# WORKFLOW INPUTS
echo Branch: ${{ inputs.branch }}
echo Release version: ${{ inputs.version }}
echo Deploy to: ${{ inputs.deploy-to }}
echo Nightly release: ${{ inputs.is-nightly-release }}
# ENVIRONMENT VARIABLES
echo Python version: ${{ env.PYTHON_TARGET_VERSION }}
echo Notification prefix: ${{ env.NOTIFICATION_PREFIX }}
- name: "Checkout ${{ github.event.repository.name }}@${{ inputs.branch }}"
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: "Setup `hatch`"
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main
- name: "Parse input version"
id: semver
uses: dbt-labs/actions/[email protected]
with:
version: ${{ inputs.version }}
- name: "Audit version"
id: version
run: |
is_current=false
current_version=$(hatch version)
if test "$current_version" = "${{ inputs.version }}"
then
is_current=true
fi
echo "is-current=$is_current" >> $GITHUB_OUTPUT
- name: "[INFO] Skip version bump"
if: steps.version.outputs.is-current == 'true'
run: |
title="Skip version bump"
message="The version matches the input version ${{ inputs.version }}, skipping version bump"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
- name: "Audit changelog"
id: changelog
run: |
path=".changes/"
if [[ ${{ steps.semver.outputs.is-pre-release }} -eq 1 ]]
then
path+="${{ steps.semver.outputs.base-version }}-${{ steps.semver.outputs.pre-release }}.md"
else
path+="${{ steps.semver.outputs.base-version }}.md"
fi
echo "path=$path" >> $GITHUB_OUTPUT
does_exist=false
if test -f $path
then
does_exist=true
fi
echo "exists=$does_exist">> $GITHUB_OUTPUT
- name: "[INFO] Skip changelog generation"
if: steps.changelog.outputs.exists == 'true'
run: |
title="Skip changelog generation"
message="A changelog already exists at ${{ steps.changelog.outputs.path }}, skipping generating changelog"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
release-branch:
runs-on: ubuntu-latest
needs: release-inputs
if: |
needs.release-inputs.outputs.changelog-exists == 'false' ||
needs.release-inputs.outputs.version-is-current == 'false'
outputs:
name: ${{ steps.release-branch.outputs.name }}
steps:
- name: "Checkout ${{ github.event.repository.name }}@${{ inputs.branch }}"
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: "Set release branch"
id: release-branch
run: |
name="prep-release/"
if [[ ${{ inputs.is-nightly-release }} == true ]]
then
name+="nightly-release/"
else
name+="${{ inputs.deploy-to }}/"
fi
name+="${{ inputs.version }}_$GITHUB_RUN_ID"
echo "name=$name" >> $GITHUB_OUTPUT
- name: "Create release branch ${{ steps.release-branch.outputs.name }}"
run: |
git checkout -b ${{ steps.release-branch.outputs.name }}
git push -u origin ${{ steps.release-branch.outputs.name }}
- name: "[INFO] Create release branch"
run: |
title="Create release branch"
message="Create release branch: ${{ steps.release-branch.outputs.name }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
core-team:
if: needs.release-inputs.outputs.changelog-exists == 'false'
needs: release-inputs
uses: dbt-labs/actions/.github/workflows/determine-team-membership.yml@main
with:
github_team: "core-group"
secrets: inherit
generate-changelog:
runs-on: ubuntu-latest
if: needs.release-inputs.outputs.changelog-exists == 'false'
# only runs if we need to make changes, determined by not skipping release-branch
needs:
- release-inputs
- release-branch
- core-team
steps:
- name: "Checkout ${{ github.event.repository.name }}@${{ needs.release-branch.outputs.name }}"
uses: actions/checkout@v4
with:
ref: ${{ needs.release-branch.outputs.name }}
- name: "Setup `hatch`"
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main
- name: "Install `changie`"
run: |
brew tap miniscruff/changie https://github.com/miniscruff/changie
brew install changie
- name: "Generate changelog at ${{ needs.release-inputs.outputs.changelog-path }}"
run: |
if [[ ${{ needs.release-inputs.outputs.is-pre-release }} -eq 1 ]]
then
changie batch ${{ needs.release-inputs.outputs.base-version }} \
--move-dir '${{ needs.release-inputs.outputs.base-version }}' \
--prerelease ${{ needs.release-inputs.outputs.pre-release }}
elif [[ -d ".changes/${{ needs.release-inputs.outputs.base-version }}" ]]
then
changie batch ${{ needs.release-inputs.outputs.base-version }} \
--include '${{ needs.release-inputs.outputs.base-version }}' \
--remove-prereleases
else # releasing a final patch with no pre-releases
changie batch ${{ needs.release-inputs.outputs.base-version }}
fi
changie merge
env:
CHANGIE_CORE_TEAM: ${{ needs.core-team.outputs.team_membership }}
- name: "Remove trailing whitespace and missing new lines"
# this step will fail on whitespace errors but also correct them
continue-on-error: true
run: hatch run code-quality
- name: "Commit & push changes"
run: |
git config user.name "$USER"
git config user.email "$EMAIL"
git pull
git add .
git commit -m "$COMMIT_MESSAGE"
git push
env:
USER: "GitHub Build Bot"
EMAIL: "[email protected]"
COMMIT_MESSAGE: "Generate changelog at ${{ needs.release-inputs.outputs.changelog-path }}"
- name: "[INFO] Generated changelog at ${{ needs.release-inputs.outputs.changelog-path }}"
run: |
title="Changelog generation"
if [[ -f ${{ needs.release-inputs.outputs.changelog-path }} ]]
then
message="Generated changelog file successfully"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
else
message="Failed to generate changelog file"
echo "::error title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
exit 1
fi
bump-version:
runs-on: ubuntu-latest
if: needs.release-inputs.outputs.version-is-current == 'false'
# only runs if we need to make changes, determined by not skipping release-branch
needs:
- release-inputs
- release-branch
- generate-changelog
steps:
- name: "Checkout ${{ github.event.repository.name }}@${{ needs.release-branch.outputs.name }}"
uses: actions/checkout@v4
with:
ref: ${{ needs.release-branch.outputs.name }}
- name: "Setup `hatch`"
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main
- name: "Bump version to ${{ inputs.version }}"
run: hatch version ${{ inputs.version }}
- name: "Commit & push changes"
run: |
git config user.name "$USER"
git config user.email "$EMAIL"
git pull
git add .
git commit -m "$COMMIT_MESSAGE"
git push
env:
USER: "GitHub Build Bot"
EMAIL: "[email protected]"
COMMIT_MESSAGE: "Bump version to ${{ inputs.version }}"
- name: "[INFO] Bumped version to ${{ inputs.version }}"
run: |
title="Version bump"
message="Bumped version to ${{ inputs.version }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
unit-tests:
runs-on: ubuntu-latest
# only run unit tests if we created a release branch and already bumped the version and generated the changelog
if: |
!failure() && !cancelled() &&
needs.release-branch.outputs.name != ''
needs:
- release-branch
- generate-changelog
- bump-version
steps:
- name: "Checkout ${{ github.event.repository.name }}@${{ needs.release-branch.outputs.name }}"
uses: actions/checkout@v4
with:
ref: ${{ needs.release-branch.outputs.name }}
- name: "Setup `hatch`"
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main
- name: "Run unit tests"
run: hatch run unit-tests
integration-tests:
runs-on: ubuntu-latest
# only run integration tests if we created a release branch and already bumped the version and generated the changelog
if: |
!failure() && !cancelled() &&
needs.release-branch.outputs.name != ''
needs:
- release-branch
- generate-changelog
- bump-version
strategy:
fail-fast: false
matrix:
cratedb-version: [ 'nightly' ]
services:
cratedb:
image: crate/crate:${{ matrix.cratedb-version }}
ports:
- 4200:4200
- 5432:5432
env:
CRATE_HEAP_SIZE: 4g
steps:
- name: "Checkout ${{ github.event.repository.name }}@${{ needs.release-branch.outputs.name }}"
uses: actions/checkout@v4
with:
ref: ${{ needs.release-branch.outputs.name }}
- name: Setup database
run: psql -f ./scripts/setup_test_database.sql
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: crate
PGPASSWORD: ""
PGDATABASE: crate
- name: "Set up `hatch`"
uses: dbt-labs/dbt-adapters/.github/actions/setup-hatch@main
- name: "Run integration tests"
run: hatch run integration-tests
env:
POSTGRES_TEST_HOST: localhost
POSTGRES_TEST_PORT: 5432
POSTGRES_TEST_USER: crate
POSTGRES_TEST_PASS: ""
POSTGRES_TEST_DATABASE: crate
POSTGRES_TEST_THREADS: 4
merge-release-branch:
runs-on: ubuntu-latest
needs:
- unit-tests
- integration-tests
- release-branch
- release-inputs
if: |
!failure() && !cancelled() &&
needs.release-branch.result == 'success' &&
inputs.deploy-to == 'prod'
steps:
- name: "Checkout ${{ github.event.repository.name }}"
uses: actions/checkout@v4
- name: "Merge changes into ${{ inputs.branch }}"
uses: everlytic/[email protected]
with:
source_ref: ${{ needs.release-branch.outputs.name }}
target_branch: ${{ inputs.branch }}
github_token: ${{ secrets.FISHTOWN_BOT_PAT }}
commit_message_template: "[Automated] Merged {source_ref} into target {target_branch} during release process"
- name: "[INFO] Merge changes into ${{ inputs.branch }}"
run: |
title="Merge changes"
message="Merge ${{ needs.release-branch.outputs.name }} into ${{ inputs.branch }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
release:
runs-on: ubuntu-latest
needs:
- release-branch
- merge-release-branch
if: ${{ !failure() && !cancelled() }}
# Get the SHA that will be released.
# If the changelog already exists and the version was already current on the input branch, then release from there.
# Otherwise, we generated a changelog and/or did the version bump in this workflow and there is a
# new sha to use from the merge we just did. Grab that here instead.
outputs:
branch: ${{ steps.branch.outputs.name }}
sha: ${{ steps.sha.outputs.sha }}
steps:
- name: "Set release branch"
id: branch
# If a release branch was created and not merged, use the release branch
# Otherwise, use the input branch because either nothing was done, or the changes were merged back in
run: |
if [[ ${{ needs.release-branch.result == 'success' }} && ${{ needs.merge-release-branch.result == 'skipped' }} ]]; then
branch="${{ needs.release-branch.outputs.name }}"
else
branch="${{ inputs.branch }}"
fi
echo "name=$branch" >> $GITHUB_OUTPUT
- name: "Checkout ${{ github.event.repository.name }}@${{ steps.branch.outputs.name }}"
uses: actions/checkout@v4
with:
ref: ${{ steps.branch.outputs.name }}
- name: "Set release SHA"
id: sha
run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
# if this is a real release and a release branch was created, delete it
- name: "Delete release branch: ${{ needs.release-branch.outputs.name }}"
if: ${{ inputs.deploy-to == 'prod' && inputs.is-nightly-release == 'false' && needs.release-branch.outputs.name != '' }}
run: git push origin -d ${{ needs.release-branch.outputs.name }}