-
Notifications
You must be signed in to change notification settings - Fork 2
252 lines (244 loc) · 9.55 KB
/
zz_generated.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
# DO NOT EDIT. Generated with:
#
#
name: Create Release
on:
push:
branches:
- 'legacy'
- 'main'
- 'master'
- 'release-v*.*.x'
# "!" negates previous positive patterns so it has to be at the end.
- '!release-v*.x.x'
jobs:
debug_info:
name: Debug info
runs-on: ubuntu-22.04
steps:
- name: Print github context JSON
run: |
cat <<EOF
${{ toJson(github) }}
EOF
gather_facts:
name: Gather facts
runs-on: ubuntu-22.04
outputs:
project_go_path: ${{ steps.get_project_go_path.outputs.path }}
ref_version: ${{ steps.ref_version.outputs.refversion }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get version
id: get_version
run: |
title="$(cat <<- 'COMMIT_MESSAGE_END' | head -n 1 -
${{ github.event.head_commit.message }}
COMMIT_MESSAGE_END
)"
# Matches strings like:
#
# - "Release v1.2.3"
# - "Release v1.2.3-r4"
# - "Release v1.2.3 (#56)"
# - "Release v1.2.3-r4 (#56)"
#
# And outputs version part (1.2.3).
if echo "${title}" | grep -iqE '^Release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
version=$(echo "${title}" | cut -d ' ' -f 2)
fi
version="${version#v}" # Strip "v" prefix.
echo "version=\"${version}\""
echo "version=${version}" >> $GITHUB_OUTPUT
- name: Checkout code
if: ${{ steps.get_version.outputs.version != '' }}
uses: actions/checkout@v4
- name: Get project.go path
id: get_project_go_path
if: ${{ steps.get_version.outputs.version != '' }}
run: |
path='./pkg/project/project.go'
if [[ ! -f $path ]] ; then
path=''
fi
echo "path=\"$path\""
echo "path=${path}" >> $GITHUB_OUTPUT
- name: Check if reference version
id: ref_version
run: |
title="$(cat <<- 'COMMIT_MESSAGE_END' | head -n 1 -
${{ github.event.head_commit.message }}
COMMIT_MESSAGE_END
)"
if echo "${title}" | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then
version=$(echo "${title}" | cut -d ' ' -f 2)
fi
version=$(echo "${title}" | cut -d ' ' -f 2)
version="${version#v}" # Strip "v" prefix.
refversion=false
if [[ "${version}" =~ ^[0-9]+.[0-9]+.[0-9]+-[0-9]+$ ]]; then
refversion=true
fi
echo "refversion =\"${refversion}\""
echo "refversion=${refversion}" >> $GITHUB_OUTPUT
update_project_go:
name: Update project.go
runs-on: ubuntu-22.04
if: ${{ needs.gather_facts.outputs.version != '' && needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }}
needs:
- gather_facts
steps:
- name: Install architect
uses: giantswarm/[email protected]
with:
binary: "architect"
version: "6.13.0"
- name: Install semver
uses: giantswarm/[email protected]
with:
binary: "semver"
version: "3.2.0"
download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz"
tarball_binary_path: "*/src/${binary}"
smoke_test: "${binary} --version"
- name: Checkout code
uses: actions/checkout@v4
- name: Update project.go
id: update_project_go
env:
branch: "${{ github.ref }}-version-bump"
run: |
git checkout -b ${{ env.branch }}
file="${{ needs.gather_facts.outputs.project_go_path }}"
version="${{ needs.gather_facts.outputs.version }}"
new_version="$(semver bump patch $version)-dev"
echo "version=\"$version\" new_version=\"$new_version\""
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
sed -Ei "s/(version[[:space:]]*=[[:space:]]*)\"${version}\"/\1\"${new_version}\"/" $file
if git diff --exit-code $file ; then
echo "error: no changes in \"$file\"" >&2
exit 1
fi
- name: Set up git identity
run: |
git config --local user.email "[email protected]"
git config --local user.name "taylorbot"
- name: Commit changes
run: |
file="${{ needs.gather_facts.outputs.project_go_path }}"
git add $file
git commit -m "Bump version to ${{ steps.update_project_go.outputs.new_version }}"
- name: Push changes
env:
REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git"
branch: "${{ github.ref }}-version-bump"
run: |
git push "${REMOTE_REPO}" HEAD:${{ env.branch }}
- name: Create PR
env:
GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}"
base: "${{ github.ref }}"
branch: "${{ github.ref }}-version-bump"
version: "${{ needs.gather_facts.outputs.version }}"
title: "Bump version to ${{ steps.update_project_go.outputs.new_version }}"
run: |
gh pr create --title "${{ env.title }}" --body "" --base ${{ env.base }} --head ${{ env.branch }} --reviewer ${{ github.actor }}
create_release:
name: Create release
runs-on: ubuntu-22.04
needs:
- gather_facts
if: ${{ needs.gather_facts.outputs.version }}
outputs:
upload_url: ${{ steps.create_gh_release.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Ensure correct version in project.go
if: ${{ needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }}
run: |
file="${{ needs.gather_facts.outputs.project_go_path }}"
version="${{ needs.gather_facts.outputs.version }}"
grep -qE "version[[:space:]]*=[[:space:]]*\"$version\"" $file
- name: Get Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
with:
version: ${{ needs.gather_facts.outputs.version }}
path: ./CHANGELOG.md
- name: Set up git identity
run: |
git config --local user.email "[email protected]"
git config --local user.name "taylorbot"
- name: Create tag
run: |
version="${{ needs.gather_facts.outputs.version }}"
git tag "v$version" ${{ github.sha }}
- name: Push tag
env:
REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git"
run: |
git push "${REMOTE_REPO}" --tags
- name: Create release
id: create_gh_release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}"
with:
body: ${{ steps.changelog_reader.outputs.changes }}
tag: "v${{ needs.gather_facts.outputs.version }}"
create-release-branch:
name: Create release branch
runs-on: ubuntu-22.04
needs:
- gather_facts
if: ${{ needs.gather_facts.outputs.version }}
steps:
- name: Install semver
uses: giantswarm/[email protected]
with:
binary: "semver"
version: "3.0.0"
download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz"
tarball_binary_path: "*/src/${binary}"
smoke_test: "${binary} --version"
- name: Check out the repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Clone the whole history, not just the most recent commit.
- name: Fetch all tags and branches
run: "git fetch --all"
- name: Create long-lived release branch
run: |
current_version="${{ needs.gather_facts.outputs.version }}"
parent_version="$(git describe --tags --abbrev=0 HEAD^ || true)"
parent_version="${parent_version#v}" # Strip "v" prefix.
if [[ -z "$parent_version" ]] ; then
echo "Unable to find a parent tag version. No branch to create."
exit 0
fi
echo "current_version=$current_version parent_version=$parent_version"
current_major=$(semver get major $current_version)
current_minor=$(semver get minor $current_version)
parent_major=$(semver get major $parent_version)
parent_minor=$(semver get minor $parent_version)
echo "current_major=$current_major current_minor=$current_minor parent_major=$parent_major parent_minor=$parent_minor"
if [[ $current_major -gt $parent_major ]] ; then
echo "Current tag is a new major version"
elif [[ $current_major -eq $parent_major ]] && [[ $current_minor -gt $parent_minor ]] ; then
echo "Current tag is a new minor version"
else
echo "Current tag is not a new major or minor version. Nothing to do here."
exit 0
fi
release_branch="release-v${parent_major}.${parent_minor}.x"
echo "release_branch=$release_branch"
if git rev-parse --verify $release_branch ; then
echo "Release branch $release_branch already exists. Nothing to do here."
exit 0
fi
git branch $release_branch HEAD^
git push origin $release_branch