Publish to PyPI #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to PyPI | |
| on: | |
| push: | |
| tags: | |
| - "[0-9]*.[0-9]*.[0-9]*" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: astral-sh/setup-uv@v5 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Validate version | |
| run: | | |
| VERSION=$(sed -n "s/^__version__ = '\(.*\)'/\1/p" clastic/__init__.py) | |
| echo "Package version: $VERSION" | |
| if echo "$VERSION" | grep -qi 'dev'; then | |
| echo "::error::Version $VERSION contains dev suffix." | |
| exit 1 | |
| fi | |
| TAG=${GITHUB_REF#refs/tags/} | |
| if [ "$VERSION" != "$TAG" ]; then | |
| echo "::error::Tag $TAG does not match __version__ ($VERSION)" | |
| exit 1 | |
| fi | |
| - name: Build package | |
| run: uv build | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/clastic | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - uses: pypa/gh-action-pypi-publish@release/v1 | |
| verify: | |
| needs: publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: astral-sh/setup-uv@v5 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Wait for PyPI | |
| run: | | |
| TAG=${GITHUB_REF#refs/tags/} | |
| for i in $(seq 1 30); do | |
| if curl -s -f "https://pypi.org/pypi/clastic/$TAG/json" > /dev/null; then | |
| echo "clastic $TAG available on PyPI" | |
| break | |
| fi | |
| echo "Waiting for PyPI propagation (attempt $i/30)..." | |
| sleep 10 | |
| done | |
| - name: Install from PyPI and verify | |
| run: | | |
| TAG=${GITHUB_REF#refs/tags/} | |
| uv pip install --system clastic==$TAG --index-url https://pypi.org/simple/ | |
| INSTALLED=$(cd /tmp && python -c "import clastic; print(clastic.__version__)") | |
| echo "Installed version: $INSTALLED" | |
| if [ "$INSTALLED" != "$TAG" ]; then | |
| echo "::error::Installed version $INSTALLED does not match tag $TAG" | |
| exit 1 | |
| fi | |
| - name: Run tests | |
| run: | | |
| uv pip install --system pytest chameleon Mako psutil | |
| pytest clastic/tests/ -v |