Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit bff5336

Browse files
committed
Enhance CD workflow and version metadata handling
1 parent 5afc733 commit bff5336

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

.github/workflows/cd.yml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: CD
22

33
on:
44
push:
5-
branches-ignore:
6-
- 'dependabot/**'
5+
branches:
6+
- main
77
tags:
88
- '[0-9]+.[0-9]+.[0-9]+'
99
pull_request:
@@ -37,6 +37,7 @@ jobs:
3737
uses: actions/checkout@v4
3838
with:
3939
fetch-depth: 0
40+
fetch-tags: true
4041

4142
- name: Set up Python ${{ matrix.python }}
4243
id: setup-python
@@ -77,24 +78,37 @@ jobs:
7778
restore-keys: |
7879
pip-build-${{ runner.os }}-
7980
80-
- name: Test package installation
81+
- name: Verify package
8182
run: |
83+
pip install twine
84+
twine check dist/*
85+
# Install the package and check version
8286
pip install dist/*.whl
87+
PKG_VERSION=$(python -c "import importlib.metadata; print(importlib.metadata.version('clusx'))")
88+
echo "Package version: $PKG_VERSION"
89+
# Verify version is PyPI-compatible
90+
if [[ "$PKG_VERSION" == *"+"* ]]; then
91+
echo "Error: Version contains '+' which is not allowed by PyPI"
92+
exit 1
93+
fi
94+
# Show version for verification
8395
clusx --version
8496
8597
- name: Upload Build Artifacts
8698
uses: actions/upload-artifact@v4
8799
with:
88100
name: dist
89101
path: dist/clusx-*.*
102+
retention-days: 7
90103

91-
upload_pypi:
92-
name: Upload to PyPI
104+
upload_test_pypi:
105+
name: Upload to Test PyPI
93106
runs-on: ubuntu-latest
94107

95108
needs: [build]
96109

97-
environment: pypi
110+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'pull_request'
111+
environment: test-pypi
98112

99113
permissions:
100114
id-token: write
@@ -107,17 +121,35 @@ jobs:
107121
path: dist
108122
merge-multiple: true
109123

110-
- name: Publish package distributions to Test PyPI
124+
- name: Publish to Test PyPI
111125
uses: pypa/gh-action-pypi-publish@release/v1
112126
with:
113127
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
114128
repository-url: https://test.pypi.org/legacy/
115129
verbose: true
116130

131+
upload_pypi:
132+
name: Upload to PyPI
133+
runs-on: ubuntu-latest
134+
135+
needs: [build]
136+
137+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
138+
environment: production-pypi
139+
140+
permissions:
141+
id-token: write
142+
143+
steps:
144+
- name: Download build artifacts
145+
uses: actions/download-artifact@v4
146+
with:
147+
name: dist
148+
path: dist
149+
merge-multiple: true
117150

118-
- name: Publish package distributions to PyPI
151+
- name: Publish to PyPI
119152
uses: pypa/gh-action-pypi-publish@release/v1
120-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
121153
with:
122154
password: ${{ secrets.PYPI_API_TOKEN }}
123155
repository-url: https://pypi.org/legacy/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ vcs = "git"
100100
# Disable the local version part (the part after +) for PyPI compatibility
101101
pattern = "^(?P<base>\\d+\\.\\d+\\.\\d+)$"
102102
# Only include metadata for non-tagged versions
103-
format-jinja = "{% if distance == 0 %}{{ base }}{% else %}{{ base }}.post{{ distance }}{% endif %}"
103+
format-jinja = "{% if distance == 0 %}{{ base }}{% else %}{{ base }}.dev{{ distance }}{% endif %}"
104104

105105
[tool.black]
106106
line-length = 88

0 commit comments

Comments
 (0)