-
Notifications
You must be signed in to change notification settings - Fork 23
245 lines (215 loc) · 9.84 KB
/
bump-version.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
name: Bump version
on:
workflow_dispatch:
inputs:
part:
description: 'Semver type of new version (major | minor | patch)'
required: true
type: choice
options:
- patch
- minor
- major
release_candidate:
type: choice
description: 'Release candidate?'
options:
- false
- true
new_version:
description: 'New version to bump to'
required: true
force:
type: choice
description: 'Force override check?'
options:
- false
- true
dry_run:
type: choice
description: 'Perform a dry run to check?'
options:
- true
- false
jobs:
bump-version:
runs-on: ubuntu-latest
if: github.repository == 'scikit-hep/pylhe'
steps:
# Use GitHub PAT to authenticate so other workflows trigger
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.ACCESS_TOKEN }}
- name: Verify new version bump step is valid
if: github.event.inputs.force == 'false'
id: script
shell: bash
run: |
current_tag="$(git describe --tags --abbrev=0)"
current_tag="${current_tag:1}"
latest_stable_tag="$(git tag | grep --invert-match 'rc' | tail -n 1)"
latest_stable_tag="${latest_stable_tag:1}"
echo "* Current version: ${current_tag}"
echo "* Latest stable version: ${latest_stable_tag}"
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
echo "* Attempting a ${{ github.event.inputs.part }} version release candidate bump from ${current_tag} to: ${{ github.event.inputs.new_version }}"
else
# For ease of use, set current tag to latest stable
current_tag="${latest_stable_tag}"
echo "* Attempting a ${{ github.event.inputs.part }} version bump from ${current_tag} to: ${{ github.event.inputs.new_version }}"
fi
echo "* Validating bump target version matches SemVer..."
# IFS is single charecter, so split on the 'r' in "rc"
IFS='r' read current_tag_read current_rc <<EOF
${current_tag}
EOF
current_rc="${current_rc:1}"
IFS='.' read current_major current_minor current_patch <<EOF
${current_tag_read}
EOF
# current_tag_read is read only and no longer used
unset current_tag_read
# IFS is single charecter, so split on the 'r' in "rc"
IFS='r' read bump_version bump_rc <<EOF
${{ github.event.inputs.new_version }}
EOF
bump_rc="${bump_rc:1}"
# bump_version is a read only variable
IFS='.' read bump_major bump_minor bump_patch <<EOF
${bump_version}
EOF
unset bump_version
# Check release candidates are valid before proceeding
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
if [ -z "${current_rc}" ]; then
current_rc=0
fi
if [ "${bump_rc}" != "$((${current_rc} + 1))" ]; then
echo "ERROR: ${{ github.event.inputs.new_version }} is more than 1 release candidate version greater then ${current_tag}"
exit 1
fi
else
if [ ! -z "${bump_rc}" ]; then
echo "ERROR: ${{ github.event.inputs.new_version }} contains a release candidate signature rc${bump_rc} but was marked as stable release."
exit 1
fi
fi
if [ ${{ github.event.inputs.part }} == "major" ]; then
# Minor version should be zero
if [ "${bump_minor}" != "0" ]; then
echo "ERROR: ${{ github.event.inputs.part }} release attempted, ${{ github.event.inputs.new_version }} minor version should equal 0."
exit 1
fi
# Patch version should be zero
if [ "${bump_patch}" != "0" ]; then
echo "ERROR: ${{ github.event.inputs.part }} release attempted, ${{ github.event.inputs.new_version }} patch version should equal 0."
exit 1
fi
if [ "${bump_major}" != "$((${current_major} + 1))" ]; then
if ! ([ "${bump_major}" == "${current_major}" ] && [ ${{ github.event.inputs.release_candidate }} == 'true' ]); then
echo "ERROR: ${{ github.event.inputs.part }} release candidate release attempted, but ${{ github.event.inputs.new_version }} is more than 1 ${{ github.event.inputs.part }} version greater then ${current_tag}."
exit 1
fi
fi
fi
if [ ${{ github.event.inputs.part }} == "minor" ]; then
# Major versions should be equal
if [ "${bump_major}" != "${current_major}" ]; then
echo "ERROR: ${{ github.event.inputs.part }} release attempted, but ${{ github.event.inputs.new_version }} major version not equal to ${current_tag}."
exit 1
fi
# Patch version should be zero
if [ "${bump_patch}" != "0" ]; then
echo "ERROR: ${{ github.event.inputs.part }} release attempted, ${{ github.event.inputs.new_version }} patch version should equal 0."
exit 1
fi
if [ "${bump_minor}" != "$((${current_minor} + 1))" ]; then
if ! ([ "${bump_minor}" == "${current_minor}" ] && [ ${{ github.event.inputs.release_candidate }} == 'true' ]); then
echo "ERROR: ${{ github.event.inputs.part }} release candidate release attempted, but ${{ github.event.inputs.new_version }} is more than 1 ${{ github.event.inputs.part }} version greater then ${current_tag}."
exit 1
fi
fi
fi
if [ ${{ github.event.inputs.part }} == "patch" ]; then
# Major versions should be equal
if [ "${bump_major}" != "${current_major}" ]; then
echo "ERROR: ${{ github.event.inputs.part }} release attempted, but ${{ github.event.inputs.new_version }} major version not equal to ${current_tag}."
exit 1
fi
# Minor versions should be equal
if [ "${bump_minor}" != "${current_minor}" ]; then
echo "ERROR: ${{ github.event.inputs.part }} release attempted, but ${{ github.event.inputs.new_version }} minor version not equal to ${current_tag}."
exit 1
fi
if [ "${bump_patch}" != "$((${current_patch} + 1))" ]; then
if ! ([ "${bump_patch}" == "${current_patch}" ] && [ ${{ github.event.inputs.release_candidate }} == 'true' ]); then
echo "ERROR: ${{ github.event.inputs.part }} release candidate release attempted, but ${{ github.event.inputs.new_version }} is more than 1 ${{ github.event.inputs.part }} version greater then ${current_tag}."
exit 1
fi
fi
fi
echo " ...version bump validated!"
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
echo "* Bumping version ${current_tag} to ${{ github.event.inputs.part }} version release candidate ${{ github.event.inputs.new_version }}"
else
echo "* Bumping version ${current_tag} to ${{ github.event.inputs.part }} version ${{ github.event.inputs.new_version }}"
fi
echo ::set-output name=old_tag::v${current_tag}
- name: Set up Python
if: success()
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Python dependencies
run: |
python -m pip install uv
uv pip install --system --upgrade pip wheel
uv pip install --system tbump
python -m pip list
- name: Setup Git user to push new tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump version and push to GitHub
if: >-
github.event_name == 'workflow_dispatch'
&& (
github.event.sender.login == 'lukasheinrich' ||
github.event.sender.login == 'matthewfeickert' ||
github.event.sender.login == 'eduardo-rodrigues'
)
shell: bash
run: |
tbump --non-interactive --no-push ${{ github.event.inputs.new_version }}
- name: Update the Git tag annotation
if: ${{ github.event.inputs.dry_run }} == 'false'
shell: bash
run: |
OLD_TAG=${{ steps.script.outputs.old_tag }}
git tag -n99 --list "${OLD_TAG}"
NEW_TAG=v${{ github.event.inputs.new_version }}
git tag -n99 --list "${NEW_TAG}"
CHANGES=$(git log --pretty=format:'%s' "${OLD_TAG}"..HEAD --regexp-ignore-case --extended-regexp --grep='^([a-z]*?):')
CHANGES_NEWLINE="$(echo "${CHANGES}" | sed -e 's/^/ - /')"
SANITIZED_CHANGES=$(echo "${CHANGES}" | sed -e 's/^/<li>/' -e 's|$|</li>|' -e 's/(#[0-9]\+)//' -e 's/"/'"'"'/g')
NUM_CHANGES=$(echo -n "${CHANGES}" | grep -c '^')
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
git tag "${NEW_TAG}" "${NEW_TAG}"^{} -f -m "$(printf "This is a ${{ github.event.inputs.part }} release candidate from ${OLD_TAG} → ${NEW_TAG}.\n\nChanges:\n${CHANGES_NEWLINE}")"
else
git tag "${NEW_TAG}" "${NEW_TAG}"^{} -f -m "$(printf "This is a ${{ github.event.inputs.part }} release from ${OLD_TAG} → ${NEW_TAG}.\n\nChanges:\n${CHANGES_NEWLINE}")"
fi
git tag -n99 --list "${NEW_TAG}"
- name: Show annotated Git tag
shell: bash
run: |
git show v${{ github.event.inputs.new_version }}
- name: Push new tag back to GitHub
shell: bash
run: |
if [ ${{ github.event.inputs.dry_run }} == 'true' ]; then
echo "# DRY RUN"
else
git push origin main --tags
fi