Skip to content

Commit 8401096

Browse files
authored
Merge branch 'master' into feat/select-defaults
2 parents 77202d1 + 97ed68e commit 8401096

File tree

1 file changed

+83
-31
lines changed

1 file changed

+83
-31
lines changed

.github/workflows/release.yml

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,63 @@ 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
64+
branch_protection_rename:
65+
needs: [safety_check]
66+
runs-on: ubuntu-latest
67+
environment: release
68+
env:
69+
GH_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
70+
outputs:
71+
master_rule_id: ${{ steps.get_rule_ids.outputs.master_rule_id }}
72+
master_pattern: ${{ steps.get_rule_ids.outputs.master_pattern }}
73+
v_rule_id: ${{ steps.get_rule_ids.outputs.v_rule_id }}
74+
v_pattern: ${{ steps.get_rule_ids.outputs.v_pattern }}
75+
steps:
76+
- name: Get branch protection rule IDs
77+
id: get_rule_ids
78+
run: |
79+
gh api repos/${{ github.repository }}/branch-protection-rules > rules.json
80+
MASTER_ID=$(jq -r '.[] | select(.pattern == "master") | .id' rules.json)
81+
MASTER_PATTERN=$(jq -r '.[] | select(.pattern == "master") | .pattern' rules.json)
82+
V_ID=$(jq -r '.[] | select(.pattern | test("^v[0-9]+\\.[0-9]+\\.x$")) | .id' rules.json)
83+
V_PATTERN=$(jq -r '.[] | select(.pattern | test("^v[0-9]+\\.[0-9]+\\.x$")) | .pattern' rules.json)
84+
echo "master_rule_id=$MASTER_ID" >> $GITHUB_OUTPUT
85+
echo "master_pattern=$MASTER_PATTERN" >> $GITHUB_OUTPUT
86+
echo "v_rule_id=$V_ID" >> $GITHUB_OUTPUT
87+
echo "v_pattern=$V_PATTERN" >> $GITHUB_OUTPUT
88+
- name: Rename master protection to temp-master
89+
if: ${{ steps.get_rule_ids.outputs.master_rule_id != '' }}
90+
run: |
91+
gh api repos/${{ github.repository }}/branch-protection-rules/${{ steps.get_rule_ids.outputs.master_rule_id }} \
92+
-X PATCH -F pattern="temp-master"
93+
- name: Rename v*.* protection to temp-v
94+
if: ${{ steps.get_rule_ids.outputs.v_rule_id != '' }}
95+
run: |
96+
gh api repos/${{ github.repository }}/branch-protection-rules/${{ steps.get_rule_ids.outputs.v_rule_id }} \
97+
-X PATCH -F pattern="temp-v"
98+
6799
lib_release:
68-
needs: [safety_check,pre_config]
100+
needs: [pre_config, branch_protection_rename]
69101
runs-on: ubuntu-latest
70102
environment: release
71103
env:
@@ -119,7 +151,7 @@ jobs:
119151
DATE=$(date +'%Y-%m-%d')
120152
sed -i "/These changes are available on the \`.*\` branch, but have not yet been released\./{N;d;}" CHANGELOG.md
121153
sed -i "s/## \[Unreleased\]/## [$VERSION] - $DATE/" CHANGELOG.md
122-
sed -i "0,/## \[$VERSION\]/ s|## \[$VERSION\]|## [Unreleased]\n\nThese changes are available on the \`$BRANCH\` branch, but have not yet been released.\n\n### Added\n\n### Changed\n\n### Fixed\n\n### Removed\n\n&|" CHANGELOG.md
154+
sed -i "0,/## \[$VERSION\]/ s|## \[$VERSION\]|## [Unreleased]\n\nThese changes are available on the \`$BRANCH\` branch, but have not yet been released.\n\n### Added\n\n### Changed\n\n### Fixed\n\n### Deprecated\n\n### Removed\n\n&|" CHANGELOG.md
123155
sed -i "s|\[unreleased\]:.*|[unreleased]: https://github.com/$REPOSITORY/compare/v$VERSION...HEAD\n[$VERSION]: https://github.com/$REPOSITORY/compare/$(git describe --tags --abbrev=0 @^)...v$VERSION|" CHANGELOG.md
124156
git add CHANGELOG.md
125157
git commit -m "chore(release): update CHANGELOG.md for version $VERSION"
@@ -193,14 +225,15 @@ jobs:
193225
attestations: false
194226
verify-metadata: false
195227

196-
197228
- name: "Echo release url"
198229
run: echo "${{ steps.gh-release.outputs.url }}"
199230

200231
docs_release:
201232
runs-on: ubuntu-latest
202-
needs: [lib_release,pre_config]
203-
if: ${{ needs.pre_config.outputs.is_rc == 'false' || (needs.pre_config.outputs.is_rc == 'true' && endsWith(needs.pre_config.outputs.version, '0rc1')) }}
233+
needs: [lib_release, pre_config]
234+
if:
235+
${{ needs.pre_config.outputs.is_rc == 'false' || (needs.pre_config.outputs.is_rc
236+
== 'true' && endsWith(needs.pre_config.outputs.version, '0rc1')) }}
204237
environment: release
205238
steps:
206239
- name: "Sync Versions on Read the Docs"
@@ -213,6 +246,7 @@ jobs:
213246
run: |
214247
VERSION=${{ needs.pre_config.outputs.version }}
215248
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
249+
HIDDEN=$([[ $VERSION == *rc* ]] && echo true || echo false)
216250
if [[ $VERSION == *rc* ]]; then
217251
DOCS_VERSION="v${MAJOR_MINOR_VERSION}.x"
218252
else
@@ -223,48 +257,45 @@ jobs:
223257
--header "Authorization: Token ${{ secrets.READTHEDOCS_TOKEN }}" \
224258
--data '{
225259
"active": true,
226-
"hidden": false
260+
"hidden": $HIDDEN
227261
}'
228262
229263
inform_discord:
230264
runs-on: ubuntu-latest
231-
needs: [lib_release,docs_release,pre_config]
265+
needs: [docs_release, lib_release, pre_config]
232266
environment: release
233267
steps:
234268
- name: "Notify Discord"
235269
run: |
236270
VERSION=${{ needs.pre_config.outputs.version }}
237271
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
238-
if [[ $VERSION == *rc* ]]; then
239-
DOCS_URL="<https://docs.pycord.dev/en/v${MAJOR_MINOR_VERSION}.x/changelog.html>"
240-
else
241-
DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>"
242-
fi
272+
DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>"
243273
GITHUB_COMPARE_URL="<https://github.com/Pycord-Development/pycord/compare/${{ needs.pre_config.outputs.previous_tag }}...v$VERSION>"
244274
GITHUB_RELEASE_URL="<https://github.com/Pycord-Development/pycord/releases/tag/v$VERSION>"
245275
PYPI_RELEASE_URL="<https://pypi.org/project/py-cord/$VERSION/>"
246276
if [[ $VERSION == *rc* ]]; then
247-
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"
248279
ANNOUNCEMENT="${ANNOUNCEMENT}This is a pre-release (release candidate) for testing and feedback.\n\n"
249280
ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n"
250281
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"
251282
ANNOUNCEMENT="${ANNOUNCEMENT}You can install this version by running the following command:\n\`\`\`sh\npip install -U py-cord==$VERSION\n\`\`\`\n\n"
252-
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!"
253284
else
254-
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${MAJOR_MINOR_VERSION} is out!\n\n"
255-
ANNOUNCEMENT="${ANNOUNCEMENT}[@everyone]\n\n"
285+
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${VERSION} is out!\n\n"
286+
ANNOUNCEMENT="${ANNOUNCEMENT}@everyone\n\n"
256287
ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n"
257288
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"
258-
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\`\`\`"
259290
fi
260291
curl -H "Content-Type: application/json" \
261292
-X POST \
262-
-d "{\"content\":\"$ANNOUNCEMENT\",\"allowed_mentions\":{\"parse\": [\"everyone\"]}}" \
293+
-d "{\"content\":\"$ANNOUNCEMENT\",\"allowed_mentions\":{\"parse\":[\"everyone\",\"roles\"]}}" \
263294
${{ secrets.DISCORD_WEBHOOK_URL }}
264295
265296
determine_milestone_id:
266297
runs-on: ubuntu-latest
267-
needs: [lib_release,pre_config]
298+
needs: [lib_release, pre_config]
268299
if: ${{ !contains(needs.pre_config.outputs.version, '-') }}
269300
outputs:
270301
old_milestone_version: ${{ steps.extract_version.outputs.old_milestone_version }}
@@ -286,8 +317,10 @@ jobs:
286317
287318
close_milestone:
288319
runs-on: ubuntu-latest
289-
needs: [determine_milestone_id,pre_config]
290-
if: ${{ !contains(needs.pre_config.outputs.version, 'rc') && endsWith(needs.pre_config.outputs.version, '.0') }}
320+
needs: [determine_milestone_id, pre_config]
321+
if:
322+
${{ !contains(needs.pre_config.outputs.version, 'rc') &&
323+
endsWith(needs.pre_config.outputs.version, '.0') }}
291324
environment: release
292325
env:
293326
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -308,3 +341,22 @@ jobs:
308341
run: |
309342
gh extension install valeriobelli/gh-milestone
310343
gh milestone create "${{ needs.determine_milestone_id.outputs.new_milestone_version }}"
344+
345+
branch_protection_restore:
346+
runs-on: ubuntu-latest
347+
needs: [branch_protection_rename, lib_release, docs_release, inform_discord, determine_milestone_id, close_milestone]
348+
environment: release
349+
if: always()
350+
env:
351+
GH_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
352+
steps:
353+
- name: Restore master protection pattern
354+
if: ${{ needs.branch_protection_rename.outputs.master_rule_id != '' }}
355+
run: |
356+
gh api repos/${{ github.repository }}/branch-protection-rules/${{ needs.branch_protection_rename.outputs.master_rule_id }} \
357+
-X PATCH -F pattern="${{ needs.branch_protection_rename.outputs.master_pattern }}"
358+
- name: Restore v*.* protection pattern
359+
if: ${{ needs.branch_protection_rename.outputs.v_rule_id != '' }}
360+
run: |
361+
gh api repos/${{ github.repository }}/branch-protection-rules/${{ needs.branch_protection_rename.outputs.v_rule_id }} \
362+
-X PATCH -F pattern="${{ needs.branch_protection_rename.outputs.v_pattern }}"

0 commit comments

Comments
 (0)