Skip to content

Commit 97ed68e

Browse files
committed
Refine release workflow version handling and dependencies
Improves version string validation to only support normal and rc releases, simplifies branch name and is_rc output logic, and streamlines job dependencies for better workflow clarity. Also updates Discord announcement formatting and docs release visibility for rc versions.
1 parent 78db054 commit 97ed68e

File tree

1 file changed

+23
-37
lines changed

1 file changed

+23
-37
lines changed

.github/workflows/release.yml

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,23 @@ jobs:
4141
env:
4242
VERSION: ${{ github.event.inputs.version }}
4343
run: |
44-
# PEP 440 version regex
4544
VALID_VERSION_REGEX='^([0-9]+\.[0-9]+\.[0-9]+((a|b|rc|\.dev|\.post)[0-9]+)?)$'
4645
if ! [[ $VERSION =~ $VALID_VERSION_REGEX ]]; then
4746
echo "::error::Invalid version string '$VERSION'. Must match PEP 440 (e.g. 1.2.0, 1.2.0rc1, 1.2.0.dev1, 1.2.0a1, 1.2.0b1, 1.2.0.post1)"
4847
exit 1
4948
fi
49+
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+rc[0-9]+$ ]]; then
50+
echo "::error::Unsupported version string '$VERSION'. Only normal releases (e.g. 1.2.3) and rc (e.g. 1.2.3rc1) are supported at this time."
51+
exit 1
52+
fi
5053
echo "version=$VERSION" >> $GITHUB_OUTPUT
5154
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^)
5255
echo "previous_tag=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT
53-
if [[ $VERSION =~ rc[0-9]+$ ]]; then
54-
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
55-
echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT
56+
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
57+
echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT
58+
if [[ $VERSION == *rc* ]]; then
5659
echo "is_rc=true" >> $GITHUB_OUTPUT
57-
elif [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
58-
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
59-
echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT
60-
echo "is_rc=false" >> $GITHUB_OUTPUT
6160
else
62-
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
63-
echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT
6461
echo "is_rc=false" >> $GITHUB_OUTPUT
6562
fi
6663
@@ -100,7 +97,7 @@ jobs:
10097
-X PATCH -F pattern="temp-v"
10198
10299
lib_release:
103-
needs: [safety_check, pre_config, branch_protection_rename]
100+
needs: [pre_config, branch_protection_rename]
104101
runs-on: ubuntu-latest
105102
environment: release
106103
env:
@@ -233,7 +230,7 @@ jobs:
233230

234231
docs_release:
235232
runs-on: ubuntu-latest
236-
needs: [lib_release, pre_config, branch_protection_rename, safety_check]
233+
needs: [lib_release, pre_config]
237234
if:
238235
${{ needs.pre_config.outputs.is_rc == 'false' || (needs.pre_config.outputs.is_rc
239236
== 'true' && endsWith(needs.pre_config.outputs.version, '0rc1')) }}
@@ -249,6 +246,7 @@ jobs:
249246
run: |
250247
VERSION=${{ needs.pre_config.outputs.version }}
251248
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
249+
HIDDEN=$([[ $VERSION == *rc* ]] && echo true || echo false)
252250
if [[ $VERSION == *rc* ]]; then
253251
DOCS_VERSION="v${MAJOR_MINOR_VERSION}.x"
254252
else
@@ -259,49 +257,45 @@ jobs:
259257
--header "Authorization: Token ${{ secrets.READTHEDOCS_TOKEN }}" \
260258
--data '{
261259
"active": true,
262-
"hidden": false
260+
"hidden": $HIDDEN
263261
}'
264262
265263
inform_discord:
266264
runs-on: ubuntu-latest
267-
needs:
268-
[lib_release, docs_release, pre_config, branch_protection_rename, safety_check]
265+
needs: [docs_release, lib_release, pre_config]
269266
environment: release
270267
steps:
271268
- name: "Notify Discord"
272269
run: |
273270
VERSION=${{ needs.pre_config.outputs.version }}
274271
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
275-
if [[ $VERSION == *rc* ]]; then
276-
DOCS_URL="<https://docs.pycord.dev/en/v${MAJOR_MINOR_VERSION}.x/changelog.html>"
277-
else
278-
DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>"
279-
fi
272+
DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>"
280273
GITHUB_COMPARE_URL="<https://github.com/Pycord-Development/pycord/compare/${{ needs.pre_config.outputs.previous_tag }}...v$VERSION>"
281274
GITHUB_RELEASE_URL="<https://github.com/Pycord-Development/pycord/releases/tag/v$VERSION>"
282275
PYPI_RELEASE_URL="<https://pypi.org/project/py-cord/$VERSION/>"
283276
if [[ $VERSION == *rc* ]]; then
284-
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${MAJOR_MINOR_VERSION} Release Candidate ($VERSION) is available!\n\n"
277+
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v$VERSION Release Candidate ($MAJOR_MINOR_VERSION) is available!\n\n"
278+
ANNOUNCEMENT="${ANNOUNCEMENT}@here\n\n"
285279
ANNOUNCEMENT="${ANNOUNCEMENT}This is a pre-release (release candidate) for testing and feedback.\n\n"
286280
ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n"
287281
ANNOUNCEMENT="${ANNOUNCEMENT}Check out the [GitHub changelog]($GITHUB_COMPARE_URL), [GitHub release page]($GITHUB_RELEASE_URL), and [PyPI release page]($PYPI_RELEASE_URL).\n\n"
288282
ANNOUNCEMENT="${ANNOUNCEMENT}You can install this version by running the following command:\n\`\`\`sh\npip install -U py-cord==$VERSION\n\`\`\`\n\n"
289-
ANNOUNCEMENT="${ANNOUNCEMENT}Please try it out and let us know your feedback or any issues!\n@here"
283+
ANNOUNCEMENT="${ANNOUNCEMENT}Please try it out and let us know your feedback or any issues!"
290284
else
291-
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${MAJOR_MINOR_VERSION} is out!\n\n"
292-
ANNOUNCEMENT="${ANNOUNCEMENT}[@everyone]\n\n"
285+
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${VERSION} is out!\n\n"
286+
ANNOUNCEMENT="${ANNOUNCEMENT}@everyone\n\n"
293287
ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n"
294288
ANNOUNCEMENT="${ANNOUNCEMENT}Feel free to take a look at the [GitHub changelog]($GITHUB_COMPARE_URL), [GitHub release page]($GITHUB_RELEASE_URL) and the [PyPI release page]($PYPI_RELEASE_URL).\n\n"
295-
ANNOUNCEMENT="${ANNOUNCEMENT}You can install this version by running the following command:\n\`\`\`sh\npip install -U py-cord==$VERSION\n\`\`\`\n\n"
289+
ANNOUNCEMENT="${ANNOUNCEMENT}You can install this version by running the following command:\n\`\`\`sh\npip install -U py-cord==$VERSION\n\`\`\`"
296290
fi
297291
curl -H "Content-Type: application/json" \
298292
-X POST \
299-
-d "{\"content\":\"$ANNOUNCEMENT\",\"allowed_mentions\":{\"parse\": [\"everyone\"]}}" \
293+
-d "{\"content\":\"$ANNOUNCEMENT\",\"allowed_mentions\":{\"parse\":[\"everyone\",\"roles\"]}}" \
300294
${{ secrets.DISCORD_WEBHOOK_URL }}
301295
302296
determine_milestone_id:
303297
runs-on: ubuntu-latest
304-
needs: [lib_release, pre_config, branch_protection_rename, safety_check]
298+
needs: [lib_release, pre_config]
305299
if: ${{ !contains(needs.pre_config.outputs.version, '-') }}
306300
outputs:
307301
old_milestone_version: ${{ steps.extract_version.outputs.old_milestone_version }}
@@ -323,7 +317,7 @@ jobs:
323317
324318
close_milestone:
325319
runs-on: ubuntu-latest
326-
needs: [determine_milestone_id, pre_config, branch_protection_rename, safety_check]
320+
needs: [determine_milestone_id, pre_config]
327321
if:
328322
${{ !contains(needs.pre_config.outputs.version, 'rc') &&
329323
endsWith(needs.pre_config.outputs.version, '.0') }}
@@ -350,15 +344,7 @@ jobs:
350344
351345
branch_protection_restore:
352346
runs-on: ubuntu-latest
353-
needs:
354-
[
355-
branch_protection_rename,
356-
lib_release,
357-
docs_release,
358-
inform_discord,
359-
determine_milestone_id,
360-
close_milestone,
361-
]
347+
needs: [branch_protection_rename, lib_release, docs_release, inform_discord, determine_milestone_id, close_milestone]
362348
environment: release
363349
if: always()
364350
env:

0 commit comments

Comments
 (0)