Skip to content

Commit 74d7217

Browse files
committed
build: upload unique pypi test versions
PyPi doesn't allow to overwrite existing releases. Thus every single upload needs to unique. Use the git describe to come up with an id. Signed-off-by: Daniel Wagner <[email protected]>
1 parent a3f8f83 commit 74d7217

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

.github/workflows/release-python.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,46 @@ jobs:
4646
permissions:
4747
id-token: write
4848
steps:
49+
- name: Check out repository (with tags)
50+
uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0 # Required for `git describe`
53+
54+
- name: Allow workspace
55+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
56+
4957
- uses: actions/download-artifact@v4
5058
with:
5159
name: artifact
5260
path: dist
5361

62+
- name: Extract sdist for patching
63+
run: |
64+
mkdir sdist && tar -xzf dist/*.tar.gz -C sdist --strip-components=1
65+
66+
- name: Compute dev version from git
67+
id: version
68+
run: |
69+
TAG=$(git describe --tags --abbrev=0)
70+
REV=$(git rev-list "$TAG"..HEAD --count)
71+
BASE_VERSION="${TAG#v}"
72+
VERSION="${BASE_VERSION}.dev${REV}"
73+
echo "dev_version=$VERSION" >> $GITHUB_OUTPUT
74+
echo "Computed dev version: $VERSION"
75+
76+
- name: Patch version in pyproject.toml
77+
run: |
78+
sed -i "s/^version = .*/version = \"${{ steps.version.outputs.dev_version }}\"/" sdist/pyproject.toml
79+
80+
- name: Rebuild sdist with dev version
81+
run: |
82+
cd sdist
83+
pipx run build --sdist
84+
mv dist/*.tar.gz ../dist/
85+
86+
- name: Validate rebuilt sdist
87+
run: pipx run twine check dist/*.tar.gz
88+
5489
- name: Publish package to TestPyPI
5590
uses: pypa/[email protected]
5691
with:

0 commit comments

Comments
 (0)