5
5
inputs :
6
6
version :
7
7
type : string
8
- description : " Version number to release (e.g., 1.2.3, 1.2.3-rc1 , 1.2.0)"
8
+ description : " Version number to release (e.g., 1.2.3, 1.2.3rc1 , 1.2.0)"
9
9
required : true
10
10
11
11
permissions : write-all
@@ -41,10 +41,16 @@ jobs:
41
41
env :
42
42
VERSION : ${{ github.event.inputs.version }}
43
43
run : |
44
+ # PEP 440 version regex
45
+ VALID_VERSION_REGEX='^([0-9]+\.[0-9]+\.[0-9]+((a|b|rc|\.dev|\.post)[0-9]+)?)$'
46
+ if ! [[ $VERSION =~ $VALID_VERSION_REGEX ]]; then
47
+ 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)"
48
+ exit 1
49
+ fi
44
50
echo "version=$VERSION" >> $GITHUB_OUTPUT
45
51
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^)
46
52
echo "previous_tag=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT
47
- if [[ $VERSION =~ -rc ]]; then
53
+ if [[ $VERSION =~ rc[0-9]+$ ]]; then
48
54
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
49
55
echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT
50
56
echo "is_rc=true" >> $GITHUB_OUTPUT
63
69
runs-on : ubuntu-latest
64
70
environment : release
65
71
env :
66
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72
+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
67
73
steps :
68
74
- name : " Checkout Repository"
69
75
uses : actions/checkout@v5
@@ -75,36 +81,126 @@ jobs:
75
81
shell : bash
76
82
env :
77
83
VERSION_BRANCH : ${{ needs.pre_config.outputs.branch_name }}
78
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
84
+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
79
85
run : |
80
86
git fetch origin
81
87
if ! git show-ref --verify --quiet refs/heads/$VERSION_BRANCH; then
82
88
git checkout -b $VERSION_BRANCH
83
89
git push origin $VERSION_BRANCH
84
90
fi
85
91
git checkout $VERSION_BRANCH
86
- - name : " Release Pycord "
87
- id : pycord-release
88
- uses :
Aiko-IT-Systems/[email protected]
92
+ - name : " Setup Python "
93
+ id : python-setup
94
+ uses : actions/setup-python@v5
89
95
with :
90
- github-token : ${{ secrets.GITHUB_TOKEN }}
91
- pypi-token : ${{ secrets.PYPI_TOKEN }}
92
- version-branch-name : ${{ needs.pre_config.outputs.branch_name }}
93
- ref : ${{ github.ref_name }}
94
- repository : ${{ github.repository }}
95
96
python-version : " 3.13"
96
- release-requirements : " requirements/_release.txt"
97
- version : ${{ needs.pre_config.outputs.version }}
98
- is-rc : ${{ needs.pre_config.outputs.is_rc }}
99
- pypi-package : " py-cord"
97
+ cache : " pip"
98
+ cache-dependency-path : " requirements/_release.txt"
99
+ - name : " Install Release Dependencies"
100
+ id : python-install
101
+ env :
102
+ REQ_FILE : " requirements/_release.txt"
103
+ shell : bash
104
+ run : |
105
+ python -m pip install --upgrade pip
106
+ pip install setuptools setuptools_scm twine build
107
+ pip install -r $REQ_FILE
108
+ - name : " Prepare and Update CHANGELOG.md"
109
+ id : changelog-update
110
+ shell : bash
111
+ env :
112
+ VERSION : ${{ inputs.version }}
113
+ REPOSITORY : ${{ github.repository }}
114
+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
115
+ BRANCH : ${{ github.ref_name }}
116
+ run : |
117
+ git config user.name "NyuwBot"
118
+ git config user.email "[email protected] "
119
+ DATE=$(date +'%Y-%m-%d')
120
+ sed -i "/These changes are available on the \`.*\` branch, but have not yet been released\./{N;d;}" CHANGELOG.md
121
+ 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
123
+ 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
124
+ git add CHANGELOG.md
125
+ git commit -m "chore(release): update CHANGELOG.md for version $VERSION"
126
+ - name : " Commit and Push Changelog to ${{ github.ref_name }}"
127
+ id : commit-main-branch
128
+ shell : bash
129
+ env :
130
+ VERSION : ${{ inputs.version }}
131
+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
132
+ BRANCH : ${{ github.ref_name }}
133
+ run : |
134
+ git config user.name "NyuwBot"
135
+ git config user.email "[email protected] "
136
+ git push origin HEAD:$BRANCH -f
137
+ - name : " Push Changelog to Version Branch"
138
+ id : commit-version-branch
139
+ shell : bash
140
+ env :
141
+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
142
+ VERSION_BRANCH : ${{ needs.pre_config.outputs.branch_name }}
143
+ run : |
144
+ git config user.name "NyuwBot"
145
+ git config user.email "[email protected] "
146
+ git push origin HEAD:$VERSION_BRANCH -f
147
+ - name : " Create Git Tag"
148
+ id : create-git-tag
149
+ shell : bash
150
+ env :
151
+ VERSION : ${{ inputs.version }}
152
+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
153
+ run : |
154
+ git config user.name "NyuwBot"
155
+ git config user.email "[email protected] "
156
+ git tag v$VERSION -m "Release version $VERSION"
157
+ git push origin v$VERSION -f
158
+ - name : " Verify Version"
159
+ id : python-version-verify
160
+ shell : bash
161
+ run : python -m setuptools_scm
162
+ - name : " Build Package"
163
+ id : python-version-build
164
+ shell : bash
165
+ run : |
166
+ python3 -m build --sdist
167
+ python3 -m build --wheel
168
+ - name : " Create GitHub Release"
169
+
170
+ id : gh-release
171
+ with :
172
+ tag_name : " v${{ inputs.version }}"
173
+ name : " v${{ inputs.version }}"
174
+ generate_release_notes : true
175
+ draft : false
176
+ prerelease : ${{ needs.pre_config.outputs.is_rc }}
177
+ files : |
178
+ dist/*.whl
179
+ dist/*.tar.gz
180
+ token : ${{ secrets.ADMIN_GITHUB_TOKEN }}
181
+ make_latest : true
182
+ repository : ${{ github.repository }}
183
+ target_commitish : ${{ github.ref_name }}
184
+
185
+ - name : " Publish package distributions to PyPI"
186
+
187
+ env :
188
+ name : " pypi"
189
+ url : " https://pypi.org/p/py-cord"
190
+ with :
191
+ password : ${{ secrets.PYPI_TOKEN }}
192
+ user : __token__
193
+ attestations : false
194
+ verify-metadata : false
195
+
100
196
101
197
- name : " Echo release url"
102
- run : echo "${{ steps.pycord -release.outputs.gh-release }}"
198
+ run : echo "${{ steps.gh -release.outputs.url }}"
103
199
104
200
docs_release :
105
201
runs-on : ubuntu-latest
106
202
needs : [lib_release,pre_config]
107
- if : ${{ needs.pre_config.outputs.is_rc == 'false' || (needs.pre_config.outputs.is_rc == 'true' && endsWith(needs.pre_config.outputs.version, '.0-rc.1 ')) }}
203
+ if : ${{ needs.pre_config.outputs.is_rc == 'false' || (needs.pre_config.outputs.is_rc == 'true' && endsWith(needs.pre_config.outputs.version, '0rc1 ')) }}
108
204
environment : release
109
205
steps :
110
206
- name : " Sync Versions on Read the Docs"
@@ -117,7 +213,7 @@ jobs:
117
213
run : |
118
214
VERSION=${{ needs.pre_config.outputs.version }}
119
215
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
120
- if [[ $VERSION == *- rc* ]]; then
216
+ if [[ $VERSION == *rc* ]]; then
121
217
DOCS_VERSION="v${MAJOR_MINOR_VERSION}.x"
122
218
else
123
219
DOCS_VERSION="v$VERSION"
@@ -132,22 +228,22 @@ jobs:
132
228
133
229
inform_discord :
134
230
runs-on : ubuntu-latest
135
- needs : [lib_release,docs_release,close_milestone, pre_config]
231
+ needs : [lib_release,docs_release,pre_config]
136
232
environment : release
137
233
steps :
138
234
- name : " Notify Discord"
139
235
run : |
140
236
VERSION=${{ needs.pre_config.outputs.version }}
141
237
MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
142
- if [[ $VERSION == *- rc* ]]; then
238
+ if [[ $VERSION == *rc* ]]; then
143
239
DOCS_URL="<https://docs.pycord.dev/en/v${MAJOR_MINOR_VERSION}.x/changelog.html>"
144
240
else
145
241
DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>"
146
242
fi
147
243
GITHUB_COMPARE_URL="<https://github.com/Pycord-Development/pycord/compare/${{ needs.pre_config.outputs.previous_tag }}...v$VERSION>"
148
244
GITHUB_RELEASE_URL="<https://github.com/Pycord-Development/pycord/releases/tag/v$VERSION>"
149
245
PYPI_RELEASE_URL="<https://pypi.org/project/py-cord/$VERSION/>"
150
- if [[ $VERSION == *- rc* ]]; then
246
+ if [[ $VERSION == *rc* ]]; then
151
247
ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${MAJOR_MINOR_VERSION} Release Candidate ($VERSION) is available!\n\n"
152
248
ANNOUNCEMENT="${ANNOUNCEMENT}This is a pre-release (release candidate) for testing and feedback.\n\n"
153
249
ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n"
@@ -191,7 +287,7 @@ jobs:
191
287
close_milestone :
192
288
runs-on : ubuntu-latest
193
289
needs : [determine_milestone_id,pre_config]
194
- if : ${{ !contains(needs.pre_config.outputs.version, '- ') && endsWith(needs.pre_config.outputs.version, '.0') }}
290
+ if : ${{ !contains(needs.pre_config.outputs.version, 'rc ') && endsWith(needs.pre_config.outputs.version, '.0') }}
195
291
environment : release
196
292
env :
197
293
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments