Remove local version identifier from dev builds for PyPI compatibility #11
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 dev build to PyPI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build dev distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.x" | |
| - name: Bump version to dev (in version.py) | |
| run: | | |
| python - <<'PY' | |
| import re, pathlib, os, datetime | |
| p = pathlib.Path('version.py') | |
| s = p.read_text() | |
| m = re.search(r"__version__\s*=\s*\"([^\"]+)\"", s) | |
| if not m: | |
| raise SystemExit('version.py: __version__ not found') | |
| base = m.group(1) | |
| # strip any existing suffix | |
| base = re.sub(r"(\.dev.*|\+.*)$", "", base) | |
| ts = datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S') | |
| new = f"{base}.dev{ts}" | |
| s2 = re.sub(r"__version__\s*=\s*\"[^\"]+\"", f"__version__ = \"{new}\"", s) | |
| p.write_text(s2) | |
| print('Set dev version:', new) | |
| PY | |
| - name: Install build deps | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Check distribution | |
| run: twine check dist/* | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-dev-distributions | |
| path: dist/ | |
| pypi-publish: | |
| name: Upload to PyPI | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-dev-distributions | |
| path: dist/ | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| skip-existing: true |