-
Notifications
You must be signed in to change notification settings - Fork 40
231 lines (218 loc) · 9.06 KB
/
_generate-changelog.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
name: "Changelog generation"
on:
workflow_call:
inputs:
package:
description: "Choose the package getting published"
type: string
default: "dbt-adapters"
merge:
description: "Choose whether to merge the changelog branch"
type: boolean
default: true
branch:
description: "Choose the branch to use"
type: string
default: "main"
outputs:
branch-name:
description: "The SHA to release"
value: ${{ jobs.branch.outputs.name }}
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
workflow_dispatch:
inputs:
package:
description: "Choose the package getting published"
type: string
default: "dbt-adapters"
merge:
description: "Choose whether to merge the changelog branch"
type: boolean
default: false
branch:
description: "Choose the branch to use"
type: string
default: "main"
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
jobs:
package:
uses: ./.github/workflows/_package-directory.yml
with:
package: ${{ inputs.package }}
version:
needs: package
runs-on: ${{ vars.DEFAULT_RUNNER }}
outputs:
raw: ${{ steps.version.outputs.raw }}
base: ${{ steps.semver.outputs.base-version }}
prerelease: ${{ steps.semver.outputs.pre-release }}
is-prerelease: ${{ steps.semver.outputs.is-pre-release }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- uses: actions/setup-python@v5
with:
python-version: ${{ vars.DEFAULT_PYTHON_VERSION }}
- uses: pypa/hatch@install
- id: version
run: echo "raw=$(hatch version)" >> $GITHUB_OUTPUT
working-directory: ./${{ needs.package.outputs.directory }}
- id: semver
uses: dbt-labs/actions/[email protected]
with:
version: ${{ steps.version.outputs.raw }}
changelog:
needs: [package, version]
runs-on: ${{ vars.DEFAULT_RUNNER }}
outputs:
path: ${{ steps.changelog.outputs.path }}
exists: ${{ steps.changelog.outputs.exists }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- id: changelog
run: |
path=".changes/${{ needs.version.outputs.base }}"
if [[ ${{ needs.version.outputs.is-prerelease }} -eq 1 ]]
then
path+="-${{ needs.version.outputs.prerelease }}"
fi
path+=".md"
echo "path=$path" >> $GITHUB_OUTPUT
exists=false
if test -f $path
then
exists=true
fi
echo "exists=$exists">> $GITHUB_OUTPUT
working-directory: ./${{ needs.package.outputs.directory }}
temp-branch:
needs: [version, changelog]
if: needs.changelog.outputs.exists == 'false'
runs-on: ${{ vars.DEFAULT_RUNNER }}
outputs:
name: ${{ steps.branch.outputs.name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- id: branch
run: |
name="prep-release/${{ inputs.package }}/$GITHUB_RUN_ID"
echo "name=$name" >> $GITHUB_OUTPUT
- run: |
git checkout -b ${{ steps.branch.outputs.name }}
git push -u origin ${{ steps.branch.outputs.name }}
dbt-membership:
needs: [version, changelog]
if: needs.changelog.outputs.exists == 'false'
runs-on: ${{ vars.DEFAULT_RUNNER }}
outputs:
team: ${{ steps.team.outputs.team }}
steps:
- id: temp-file
run: echo "name=output_$GITHUB_RUN_ID.json" >> $GITHUB_OUTPUT
- run: |
gh api -H "Accept: application/vnd.github+json" orgs/dbt-labs/teams/core-group/members > ${{ steps.temp-file.outputs.name }}
env:
GH_TOKEN: ${{ secrets.IT_TEAM_MEMBERSHIP }}
- id: team
run: |
team_list=$(jq -r '.[].login' ${{ steps.temp-file.outputs.name }})
team_list_single=$(echo $team_list | tr '\n' ' ')
echo "team=$team_list_single" >> $GITHUB_OUTPUT
- run: rm ${{ steps.temp-file.outputs.name }}
generate-changelog:
needs: [package, version, changelog, temp-branch, dbt-membership]
if: needs.changelog.outputs.exists == 'false'
runs-on: ${{ vars.DEFAULT_RUNNER }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.temp-branch.outputs.name }}
- run: echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
- run: |
brew install pre-commit
brew tap miniscruff/changie https://github.com/miniscruff/changie
brew install changie
- run: |
if [[ ${{ needs.version.outputs.is-prerelease }} -eq 1 ]]
then
changie batch ${{ needs.version.outputs.base }} --move-dir '${{ needs.version.outputs.base }}' --prerelease ${{ needs.version.outputs.prerelease }}
elif [[ -d ".changes/${{ needs.version.outputs.base }}" ]]
then
changie batch ${{ needs.version.outputs.base }} --include '${{ needs.version.outputs.base }}' --remove-prereleases
else # releasing a final patch with no prereleases
changie batch ${{ needs.version.outputs.base }}
fi
changie merge
working-directory: ./${{ needs.package.outputs.directory }}
env:
CHANGIE_CORE_TEAM: ${{ needs.dbt-membership.outputs.team }}
- run: |
pre-commit run trailing-whitespace --files __version__.py CHANGELOG.md .changes/*
pre-commit run end-of-file-fixer --files __version__.py CHANGELOG.md .changes/*
working-directory: ./${{ needs.package.outputs.directory }}
continue-on-error: true
- run: |
git config user.name "Github Build Bot"
git config user.email "[email protected]"
git pull
git add .
git commit -m "generate changelog"
git push
working-directory: ./${{ needs.package.outputs.directory }}
merge-changes:
needs: [temp-branch, generate-changelog]
if: ${{ needs.temp-branch.outputs.name != '' && inputs.merge }}
runs-on: ${{ vars.DEFAULT_RUNNER }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.temp-branch.outputs.name }}
- uses: everlytic/[email protected]
with:
source_ref: ${{ needs.temp-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"
- run: git push origin -d ${{ needs.temp-branch.outputs.name }}
branch:
needs: [temp-branch, merge-changes]
if: ${{ !failure() && !cancelled() }}
runs-on: ${{ vars.DEFAULT_RUNNER }}
# always run this job, regardless of whether changelog generation was skipped
# Get the sha that will be released. If the changelog already exists on the input sha and the version has already been bumped,
# then it is what we will release. Otherwise, we generated a changelog and 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:
name: ${{ steps.branch.outputs.name }}
steps:
- id: branch
run: |
if [[ ${{ needs.temp-branch.outputs.name == '' || inputs.merge }} ]]
then
branch="${{ inputs.branch }}"
else
branch=${{ needs.temp-branch.outputs.name }}
fi
echo "name=$branch" >> $GITHUB_OUTPUT