|
| 1 | +# Publish to PyPI |
| 2 | +# |
| 3 | +# Uses PyPI trusted publishing (OIDC), so no token is stored here. Requires a trusted |
| 4 | +# publisher on PyPI for this repository, workflow `package.yaml` and environment `pypi`. |
| 5 | +# The man page is generated as part of the build, so the sdist matches `package/roll.sh`. |
| 6 | +name: package |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + release: |
| 10 | + types: [published] |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + if: github.repository == 'python-validators/validators' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + steps: |
| 18 | + # checkout repository (for a release, the tagged commit) |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v7 |
| 21 | + # set up uv and a specific python version |
| 22 | + - name: Set up uv with Python v3.11 |
| 23 | + uses: astral-sh/setup-uv@v10.3.0 |
| 24 | + with: |
| 25 | + python-version: "3.11" |
| 26 | + # build package: generates the man page, then runs `uv build` |
| 27 | + # (`SOURCE_DATE_EPOCH` makes the wheel reproducible) |
| 28 | + - name: Build package |
| 29 | + run: | |
| 30 | + SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)" |
| 31 | + export SOURCE_DATE_EPOCH |
| 32 | + uv run --locked --no-editable --group docs-offline --extra crypto-eth-addresses \ |
| 33 | + python package/export pkg |
| 34 | + - name: Show checksums |
| 35 | + run: sha256sum dist/* |
| 36 | + # upload package as artifact |
| 37 | + - name: Upload artifact |
| 38 | + uses: actions/upload-artifact@v7 |
| 39 | + with: |
| 40 | + name: dist |
| 41 | + path: dist/ |
| 42 | + if-no-files-found: error |
| 43 | + publish: |
| 44 | + needs: build |
| 45 | + runs-on: ubuntu-latest |
| 46 | + environment: |
| 47 | + name: pypi |
| 48 | + url: https://pypi.org/p/validators |
| 49 | + permissions: |
| 50 | + id-token: write |
| 51 | + steps: |
| 52 | + - name: Download artifact |
| 53 | + uses: actions/download-artifact@v8 |
| 54 | + with: |
| 55 | + name: dist |
| 56 | + path: dist/ |
| 57 | + # publish package |
| 58 | + - name: Publish to PyPI |
| 59 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments