|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build and validate distributions |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Check out repository |
| 18 | + uses: actions/checkout@v6 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v6 |
| 22 | + with: |
| 23 | + python-version: "3.13" |
| 24 | + cache: pip |
| 25 | + |
| 26 | + - name: Install build tools |
| 27 | + run: python -m pip install --upgrade pip build twine |
| 28 | + |
| 29 | + - name: Check release tag matches package version |
| 30 | + env: |
| 31 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 32 | + run: | |
| 33 | + python - <<'PY' |
| 34 | + import os |
| 35 | + import pathlib |
| 36 | + import tomllib |
| 37 | +
|
| 38 | + project = tomllib.loads( |
| 39 | + pathlib.Path("pyproject.toml").read_text(encoding="utf-8") |
| 40 | + ) |
| 41 | + package_version = project["project"]["version"] |
| 42 | + release_version = os.environ["RELEASE_TAG"].removeprefix("v") |
| 43 | +
|
| 44 | + if package_version != release_version: |
| 45 | + raise SystemExit( |
| 46 | + f"Release tag {release_version!r} does not match " |
| 47 | + f"package version {package_version!r}" |
| 48 | + ) |
| 49 | + PY |
| 50 | +
|
| 51 | + - name: Build distributions |
| 52 | + run: python -m build |
| 53 | + |
| 54 | + - name: Validate distributions |
| 55 | + run: python -m twine check dist/* |
| 56 | + |
| 57 | + - name: Smoke-test wheel |
| 58 | + run: | |
| 59 | + python -m venv /tmp/jamkit-smoke |
| 60 | + /tmp/jamkit-smoke/bin/python -m pip install dist/*.whl |
| 61 | + /tmp/jamkit-smoke/bin/python -c \ |
| 62 | + "from jamkit.hack_the_robot.loader import load_workshop" |
| 63 | +
|
| 64 | + - name: Upload distributions |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: python-distributions |
| 68 | + path: dist/ |
| 69 | + if-no-files-found: error |
| 70 | + |
| 71 | + publish: |
| 72 | + name: Publish to PyPI |
| 73 | + needs: build |
| 74 | + runs-on: ubuntu-latest |
| 75 | + environment: |
| 76 | + name: pypi |
| 77 | + url: https://pypi.org/project/jamkit/ |
| 78 | + permissions: |
| 79 | + id-token: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Download distributions |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + name: python-distributions |
| 86 | + path: dist/ |
| 87 | + |
| 88 | + - name: Publish distributions |
| 89 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments