v3.2.0 #8
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-pypi | |
| on: | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| inputs: | |
| upload: | |
| description: 'Upload to PyPI' | |
| required: false | |
| default: 'true' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Check package version | |
| run: | | |
| set -euo pipefail | |
| # Ensure the version in pyproject.toml matches the release tag being | |
| # published. For manual runs, fall back to the latest published | |
| # release tag. | |
| # Read version from pyproject.toml | |
| PACKAGE_VERSION=$(python -c "import tomllib; f = open('pyproject.toml', 'rb'); data = tomllib.load(f); f.close(); print(data['project']['version'])") | |
| echo "Package version: $PACKAGE_VERSION" | |
| if [ "${GITHUB_EVENT_NAME}" = "release" ]; then | |
| RELEASE_TAG="${GITHUB_REF_NAME}" | |
| else | |
| RELEASE_TAG=$(python - <<'PY' | |
| import json | |
| import urllib.request | |
| with urllib.request.urlopen("https://api.github.com/repos/httpdss/structkit/releases/latest") as response: | |
| print(json.load(response)["tag_name"]) | |
| PY | |
| ) | |
| fi | |
| RELEASE_VERSION=${RELEASE_TAG#v} | |
| echo "Release version: $RELEASE_VERSION" | |
| if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]; then | |
| echo "Error: Package version ($PACKAGE_VERSION) does not match release version ($RELEASE_VERSION)" | |
| exit 1 | |
| fi | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build setuptools wheel | |
| - name: Build distribution | |
| run: python -m build | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: distribution | |
| path: dist/ | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.upload == 'true') | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: distribution | |
| path: dist/ | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Twine | |
| run: pip install twine | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* --skip-existing | |
| - name: Put pypi url on job summary | |
| run: | | |
| echo "## PyPI Package Published" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The package has been published to [PyPI](https://pypi.org/project/structkit/)." >> $GITHUB_STEP_SUMMARY |