Skip to content

Commit 366b9bc

Browse files
Fixup bump version
1 parent 40b082b commit 366b9bc

1 file changed

Lines changed: 53 additions & 35 deletions

File tree

.github/workflows/bump-version.yml

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
permissions:
4242
contents: write # for Git to git push
4343
runs-on: ubuntu-latest
44+
environment: ci
4445
if: github.repository == 'scikit-hep/pyhf'
4546

4647
steps:
@@ -51,6 +52,7 @@ jobs:
5152
ref: ${{ github.event.inputs.target_branch }}
5253
fetch-depth: 0
5354
token: ${{ secrets.ACCESS_TOKEN }}
55+
persist-credentials: false
5456

5557
- name: Check target branch is intended for release
5658
if: github.event.inputs.force == 'false'
@@ -77,13 +79,13 @@ jobs:
7779
echo "* Current version: ${current_tag}"
7880
echo "* Latest stable version: ${latest_stable_tag}"
7981
80-
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
81-
echo "* Attempting a ${{ github.event.inputs.part }} version release candidate bump from ${current_tag} to: ${{ github.event.inputs.new_version }}"
82+
if [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]; then
83+
echo "* Attempting a ${GITHUB_EVENT_INPUTS_PART} version release candidate bump from ${current_tag} to: ${GITHUB_EVENT_INPUTS_NEW_VERSION}"
8284
else
8385
# For ease of use, set current tag to latest stable
8486
current_tag="${latest_stable_tag}"
8587
86-
echo "* Attempting a ${{ github.event.inputs.part }} version bump from ${current_tag} to: ${{ github.event.inputs.new_version }}"
88+
echo "* Attempting a ${GITHUB_EVENT_INPUTS_PART} version bump from ${current_tag} to: ${GITHUB_EVENT_INPUTS_NEW_VERSION}"
8789
fi
8890
8991
echo "* Validating bump target version matches SemVer..."
@@ -102,7 +104,7 @@ jobs:
102104
103105
# IFS is single charecter, so split on the 'r' in "rc"
104106
IFS='r' read bump_version bump_rc <<EOF
105-
${{ github.event.inputs.new_version }}
107+
${GITHUB_EVENT_INPUTS_NEW_VERSION}
106108
EOF
107109
bump_rc="${bump_rc:1}"
108110
@@ -113,87 +115,91 @@ jobs:
113115
unset bump_version
114116
115117
# Check release candidates are valid before proceeding
116-
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
118+
if [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]; then
117119
if [ -z "${current_rc}" ]; then
118120
current_rc=0
119121
fi
120122
if [ "${bump_rc}" != "$((${current_rc} + 1))" ]; then
121-
echo "ERROR: ${{ github.event.inputs.new_version }} is more than 1 release candidate version greater then ${current_tag}"
123+
echo "ERROR: ${GITHUB_EVENT_INPUTS_NEW_VERSION} is more than 1 release candidate version greater then ${current_tag}"
122124
exit 1
123125
fi
124126
else
125127
if [ ! -z "${bump_rc}" ]; then
126-
echo "ERROR: ${{ github.event.inputs.new_version }} contains a release candidate signature rc${bump_rc} but was marked as stable release."
128+
echo "ERROR: ${GITHUB_EVENT_INPUTS_NEW_VERSION} contains a release candidate signature rc${bump_rc} but was marked as stable release."
127129
exit 1
128130
fi
129131
fi
130132
131-
if [ ${{ github.event.inputs.part }} == "major" ]; then
133+
if [ ${GITHUB_EVENT_INPUTS_PART} == "major" ]; then
132134
# Minor version should be zero
133135
if [ "${bump_minor}" != "0" ]; then
134-
echo "ERROR: ${{ github.event.inputs.part }} release attempted, ${{ github.event.inputs.new_version }} minor version should equal 0."
136+
echo "ERROR: ${GITHUB_EVENT_INPUTS_PART} release attempted, ${GITHUB_EVENT_INPUTS_NEW_VERSION} minor version should equal 0."
135137
exit 1
136138
fi
137139
# Patch version should be zero
138140
if [ "${bump_patch}" != "0" ]; then
139-
echo "ERROR: ${{ github.event.inputs.part }} release attempted, ${{ github.event.inputs.new_version }} patch version should equal 0."
141+
echo "ERROR: ${GITHUB_EVENT_INPUTS_PART} release attempted, ${GITHUB_EVENT_INPUTS_NEW_VERSION} patch version should equal 0."
140142
exit 1
141143
fi
142144
if [ "${bump_major}" != "$((${current_major} + 1))" ]; then
143-
if ! ([ "${bump_major}" == "${current_major}" ] && [ ${{ github.event.inputs.release_candidate }} == 'true' ]); then
144-
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}."
145+
if ! ([ "${bump_major}" == "${current_major}" ] && [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]); then
146+
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}."
145147
exit 1
146148
fi
147149
fi
148150
fi
149151
150-
if [ ${{ github.event.inputs.part }} == "minor" ]; then
152+
if [ ${GITHUB_EVENT_INPUTS_PART} == "minor" ]; then
151153
# Major versions should be equal
152154
if [ "${bump_major}" != "${current_major}" ]; then
153-
echo "ERROR: ${{ github.event.inputs.part }} release attempted, but ${{ github.event.inputs.new_version }} major version not equal to ${current_tag}."
155+
echo "ERROR: ${GITHUB_EVENT_INPUTS_PART} release attempted, but ${GITHUB_EVENT_INPUTS_NEW_VERSION} major version not equal to ${current_tag}."
154156
exit 1
155157
fi
156158
# Patch version should be zero
157159
if [ "${bump_patch}" != "0" ]; then
158-
echo "ERROR: ${{ github.event.inputs.part }} release attempted, ${{ github.event.inputs.new_version }} patch version should equal 0."
160+
echo "ERROR: ${GITHUB_EVENT_INPUTS_PART} release attempted, ${GITHUB_EVENT_INPUTS_NEW_VERSION} patch version should equal 0."
159161
exit 1
160162
fi
161163
if [ "${bump_minor}" != "$((${current_minor} + 1))" ]; then
162-
if ! ([ "${bump_minor}" == "${current_minor}" ] && [ ${{ github.event.inputs.release_candidate }} == 'true' ]); then
163-
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}."
164+
if ! ([ "${bump_minor}" == "${current_minor}" ] && [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]); then
165+
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}."
164166
exit 1
165167
fi
166168
fi
167169
fi
168170
169-
if [ ${{ github.event.inputs.part }} == "patch" ]; then
171+
if [ ${GITHUB_EVENT_INPUTS_PART} == "patch" ]; then
170172
# Major versions should be equal
171173
if [ "${bump_major}" != "${current_major}" ]; then
172-
echo "ERROR: ${{ github.event.inputs.part }} release attempted, but ${{ github.event.inputs.new_version }} major version not equal to ${current_tag}."
174+
echo "ERROR: ${GITHUB_EVENT_INPUTS_PART} release attempted, but ${GITHUB_EVENT_INPUTS_NEW_VERSION} major version not equal to ${current_tag}."
173175
exit 1
174176
fi
175177
# Minor versions should be equal
176178
if [ "${bump_minor}" != "${current_minor}" ]; then
177-
echo "ERROR: ${{ github.event.inputs.part }} release attempted, but ${{ github.event.inputs.new_version }} minor version not equal to ${current_tag}."
179+
echo "ERROR: ${GITHUB_EVENT_INPUTS_PART} release attempted, but ${GITHUB_EVENT_INPUTS_NEW_VERSION} minor version not equal to ${current_tag}."
178180
exit 1
179181
fi
180182
if [ "${bump_patch}" != "$((${current_patch} + 1))" ]; then
181-
if ! ([ "${bump_patch}" == "${current_patch}" ] && [ ${{ github.event.inputs.release_candidate }} == 'true' ]); then
182-
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}."
183+
if ! ([ "${bump_patch}" == "${current_patch}" ] && [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]); then
184+
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}."
183185
exit 1
184186
fi
185187
fi
186188
fi
187189
188190
echo " ...version bump validated!"
189-
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
190-
echo "* Bumping version ${current_tag} to ${{ github.event.inputs.part }} version release candidate ${{ github.event.inputs.new_version }}"
191+
if [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]; then
192+
echo "* Bumping version ${current_tag} to ${GITHUB_EVENT_INPUTS_PART} version release candidate ${GITHUB_EVENT_INPUTS_NEW_VERSION}"
191193
else
192-
echo "* Bumping version ${current_tag} to ${{ github.event.inputs.part }} version ${{ github.event.inputs.new_version }}"
194+
echo "* Bumping version ${current_tag} to ${GITHUB_EVENT_INPUTS_PART} version ${GITHUB_EVENT_INPUTS_NEW_VERSION}"
193195
fi
194196
195197
echo "steps.script.outputs.old_tag=v${current_tag}"
196198
echo "old_tag=v${current_tag}" >> $GITHUB_OUTPUT
199+
env:
200+
GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE: ${{ github.event.inputs.release_candidate }}
201+
GITHUB_EVENT_INPUTS_PART: ${{ github.event.inputs.part }}
202+
GITHUB_EVENT_INPUTS_NEW_VERSION: ${{ github.event.inputs.new_version }}
197203

198204
- name: Set up Python
199205
if: success()
@@ -222,16 +228,18 @@ jobs:
222228
)
223229
shell: bash
224230
run: |
225-
tbump --non-interactive --no-push ${{ github.event.inputs.new_version }}
231+
tbump --non-interactive --no-push ${GITHUB_EVENT_INPUTS_NEW_VERSION}
232+
env:
233+
GITHUB_EVENT_INPUTS_NEW_VERSION: ${{ github.event.inputs.new_version }}
226234

227235
- name: Update the Git tag annotation
228-
if: ${{ github.event.inputs.dry_run }} == 'false'
236+
if: ${{ github.event.inputs.dry_run }} == 'false' # zizmor: ignore[unsound-condition]
229237
shell: bash
230238
run: |
231-
OLD_TAG=${{ steps.script.outputs.old_tag }}
239+
OLD_TAG=${STEPS_SCRIPT_OUTPUTS_OLD_TAG}
232240
git tag -n99 --list "${OLD_TAG}"
233241
234-
NEW_TAG=v${{ github.event.inputs.new_version }}
242+
NEW_TAG=v${GITHUB_EVENT_INPUTS_NEW_VERSION}
235243
git tag -n99 --list "${NEW_TAG}"
236244
237245
CHANGES=$(git log --pretty=format:'%s' "${OLD_TAG}"..HEAD --regexp-ignore-case --extended-regexp --grep='^([a-z]*?):')
@@ -245,24 +253,34 @@ jobs:
245253
SANITIZED_CHANGES=$(echo "${CHANGES}" | sed -e 's/^/<li>/' -e 's|$|</li>|' -e 's/(#[0-9]\+)//' -e 's/"/'"'"'/g')
246254
NUM_CHANGES=$(echo -n "${CHANGES}" | grep -c '^')
247255
248-
if [ ${{ github.event.inputs.release_candidate }} == 'true' ]; then
249-
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}")"
256+
if [ ${GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE} == 'true' ]; then
257+
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}")"
250258
else
251-
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}")"
259+
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}")"
252260
fi
253261
254262
git tag -n99 --list "${NEW_TAG}"
263+
env:
264+
STEPS_SCRIPT_OUTPUTS_OLD_TAG: ${{ steps.script.outputs.old_tag }}
265+
GITHUB_EVENT_INPUTS_NEW_VERSION: ${{ github.event.inputs.new_version }}
266+
GITHUB_EVENT_INPUTS_RELEASE_CANDIDATE: ${{ github.event.inputs.release_candidate }}
267+
GITHUB_EVENT_INPUTS_PART: ${{ github.event.inputs.part }}
255268

256269
- name: Show annotated Git tag
257270
shell: bash
258271
run: |
259-
git show v${{ github.event.inputs.new_version }}
272+
git show v${GITHUB_EVENT_INPUTS_NEW_VERSION}
273+
env:
274+
GITHUB_EVENT_INPUTS_NEW_VERSION: ${{ github.event.inputs.new_version }}
260275

261276
- name: Push new tag back to GitHub
262277
shell: bash
263278
run: |
264-
if [ ${{ github.event.inputs.dry_run }} == 'true' ]; then
279+
if [ ${GITHUB_EVENT_INPUTS_DRY_RUN} == 'true' ]; then
265280
echo "# DRY RUN"
266281
else
267-
git push origin ${{ github.event.inputs.target_branch }} --tags
282+
git push origin ${GITHUB_EVENT_INPUTS_TARGET_BRANCH} --tags
268283
fi
284+
env:
285+
GITHUB_EVENT_INPUTS_DRY_RUN: ${{ github.event.inputs.dry_run }}
286+
GITHUB_EVENT_INPUTS_TARGET_BRANCH: ${{ github.event.inputs.target_branch }}

0 commit comments

Comments
 (0)