Skip to content

Commit 13717c5

Browse files
Merge pull request #67 from kevinbackhouse/publish-pre-release
Auto-update the version number for publishing pre-releases on TestPyPI
2 parents 397ae27 + 5f11124 commit 13717c5

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

.github/workflows/publish-to-pypi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ jobs:
4545
name: python-package-distributions
4646
path: dist/
4747

48+
- name: Publish to TestPyPI
49+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
50+
with:
51+
repository-url: https://test.pypi.org/legacy/
52+
verbose: true
53+
4854
- name: Publish to PyPI
4955
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
5056
with:

.github/workflows/publish-to-testpypi.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish to TestPyPI
1+
name: Publish Pre-Release to TestPyPI
22

33
on: workflow_dispatch
44

@@ -20,10 +20,6 @@ jobs:
2020
id-token: write # For trusted publishing
2121

2222
steps:
23-
- name: Generate unique name for the test release
24-
id: create_release_name
25-
run: echo "RELEASE_NAME=test-release-`date -Is --utc`" >> $GITHUB_OUTPUT
26-
2723
- name: Checkout repository
2824
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2925
with:
@@ -37,6 +33,21 @@ jobs:
3733
- name: Install Hatch
3834
run: pip install --upgrade hatch
3935

36+
- name: Generate new pre-release version number
37+
id: create_version_number
38+
run: |
39+
# Convert current version number to an alpha release of the next version.
40+
# For example, 1.0.2 becomes 1.0.3a0
41+
hatch version micro,a
42+
# Get latest version number from test.pypi.org
43+
CURRENT_VERSION_NUMBER=$(pip index versions --pre --index-url https://test.pypi.org/simple seclab-taskflow-agent | sed 's/[^(]*[(]\([^)]*\)[)].*/\1/' | head -n 1)
44+
# Set version number to match test.pypi.org
45+
hatch version "$CURRENT_VERSION_NUMBER" || echo TestPyPI is behind current version
46+
# Bump version number
47+
hatch version a
48+
# Create a name for the release
49+
echo "RELEASE_NAME=test-release-v`hatch version`" >> $GITHUB_OUTPUT
50+
4051
- name: Build the wheel
4152
run: python3 -m hatch build
4253

@@ -62,5 +73,5 @@ jobs:
6273
- name: Create GitHub Release
6374
env:
6475
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65-
RELEASE_NAME: ${{ steps.create_release_name.outputs.RELEASE_NAME }}
76+
RELEASE_NAME: ${{ steps.create_version_number.outputs.RELEASE_NAME }}
6677
run: gh release create $RELEASE_NAME dist/* --repo $GITHUB_REPO --prerelease --generate-notes

0 commit comments

Comments
 (0)