55 inputs :
66 version :
77 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)"
99 required : true
1010
1111permissions : write-all
@@ -41,10 +41,16 @@ jobs:
4141 env :
4242 VERSION : ${{ github.event.inputs.version }}
4343 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
4450 echo "version=$VERSION" >> $GITHUB_OUTPUT
4551 PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^)
4652 echo "previous_tag=${PREVIOUS_TAG}" >> $GITHUB_OUTPUT
47- if [[ $VERSION =~ -rc ]]; then
53+ if [[ $VERSION =~ rc[0-9]+$ ]]; then
4854 MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
4955 echo "branch_name=v${MAJOR_MINOR_VERSION}.x" >> $GITHUB_OUTPUT
5056 echo "is_rc=true" >> $GITHUB_OUTPUT
6369 runs-on : ubuntu-latest
6470 environment : release
6571 env :
66- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
6773 steps :
6874 - name : " Checkout Repository"
6975 uses : actions/checkout@v5
@@ -75,36 +81,126 @@ jobs:
7581 shell : bash
7682 env :
7783 VERSION_BRANCH : ${{ needs.pre_config.outputs.branch_name }}
78- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
84+ GITHUB_TOKEN : ${{ secrets.ADMIN_GITHUB_TOKEN }}
7985 run : |
8086 git fetch origin
8187 if ! git show-ref --verify --quiet refs/heads/$VERSION_BRANCH; then
8288 git checkout -b $VERSION_BRANCH
8389 git push origin $VERSION_BRANCH
8490 fi
8591 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
8995 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 }}
9596 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+
100196
101197 - name : " Echo release url"
102- run : echo "${{ steps.pycord -release.outputs.gh-release }}"
198+ run : echo "${{ steps.gh -release.outputs.url }}"
103199
104200 docs_release :
105201 runs-on : ubuntu-latest
106202 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 ')) }}
108204 environment : release
109205 steps :
110206 - name : " Sync Versions on Read the Docs"
@@ -117,7 +213,7 @@ jobs:
117213 run : |
118214 VERSION=${{ needs.pre_config.outputs.version }}
119215 MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
120- if [[ $VERSION == *- rc* ]]; then
216+ if [[ $VERSION == *rc* ]]; then
121217 DOCS_VERSION="v${MAJOR_MINOR_VERSION}.x"
122218 else
123219 DOCS_VERSION="v$VERSION"
@@ -132,22 +228,22 @@ jobs:
132228
133229 inform_discord :
134230 runs-on : ubuntu-latest
135- needs : [lib_release,docs_release,close_milestone, pre_config]
231+ needs : [lib_release,docs_release,pre_config]
136232 environment : release
137233 steps :
138234 - name : " Notify Discord"
139235 run : |
140236 VERSION=${{ needs.pre_config.outputs.version }}
141237 MAJOR_MINOR_VERSION=$(echo $VERSION | grep -oE '^[0-9]+\.[0-9]+')
142- if [[ $VERSION == *- rc* ]]; then
238+ if [[ $VERSION == *rc* ]]; then
143239 DOCS_URL="<https://docs.pycord.dev/en/v${MAJOR_MINOR_VERSION}.x/changelog.html>"
144240 else
145241 DOCS_URL="<https://docs.pycord.dev/en/v$VERSION/changelog.html>"
146242 fi
147243 GITHUB_COMPARE_URL="<https://github.com/Pycord-Development/pycord/compare/${{ needs.pre_config.outputs.previous_tag }}...v$VERSION>"
148244 GITHUB_RELEASE_URL="<https://github.com/Pycord-Development/pycord/releases/tag/v$VERSION>"
149245 PYPI_RELEASE_URL="<https://pypi.org/project/py-cord/$VERSION/>"
150- if [[ $VERSION == *- rc* ]]; then
246+ if [[ $VERSION == *rc* ]]; then
151247 ANNOUNCEMENT="## <:pycord:1063211537008955495> Pycord v${MAJOR_MINOR_VERSION} Release Candidate ($VERSION) is available!\n\n"
152248 ANNOUNCEMENT="${ANNOUNCEMENT}This is a pre-release (release candidate) for testing and feedback.\n\n"
153249 ANNOUNCEMENT="${ANNOUNCEMENT}You can view the changelog here: <$DOCS_URL>\n\n"
@@ -191,7 +287,7 @@ jobs:
191287 close_milestone :
192288 runs-on : ubuntu-latest
193289 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') }}
195291 environment : release
196292 env :
197293 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments