|
| 1 | +# Build and publish jsonpointer to PyPI when a GitHub release is published. |
| 2 | +# |
| 3 | +# Uses PyPI Trusted Publishing (OIDC), so no API token is stored in GitHub. |
| 4 | +# |
| 5 | +# One-time setup: |
| 6 | +# |
| 7 | +# 1. On PyPI, open https://pypi.org/manage/project/jsonpointer/settings/publishing/ |
| 8 | +# and add a GitHub trusted publisher with: |
| 9 | +# Owner: stefankoegl |
| 10 | +# Repository name: python-json-pointer |
| 11 | +# Workflow name: publish.yml |
| 12 | +# Environment name: pypi |
| 13 | +# |
| 14 | +# 2. In GitHub, go to Settings -> Environments -> New environment and create |
| 15 | +# an environment named "pypi". Optionally add yourself as a required |
| 16 | +# reviewer so every upload needs a manual approval, and restrict |
| 17 | +# deployments to tags (e.g. "v*"). |
| 18 | +# |
| 19 | +# 3. (Optional) Repeat steps 1 and 2 on https://test.pypi.org with the |
| 20 | +# environment name "testpypi" to enable test uploads via manual runs. |
| 21 | +# |
| 22 | +# Releasing: |
| 23 | +# |
| 24 | +# Bump __version__ in jsonpointer.py, commit, tag, push the tag, and publish |
| 25 | +# a GitHub release for that tag. The workflow builds the sdist and wheel and |
| 26 | +# uploads them to PyPI. Running the workflow manually ("Run workflow") uploads |
| 27 | +# to TestPyPI instead. |
| 28 | + |
| 29 | +name: Publish to PyPI |
| 30 | + |
| 31 | +on: |
| 32 | + release: |
| 33 | + types: [published] |
| 34 | + workflow_dispatch: |
| 35 | + |
| 36 | +jobs: |
| 37 | + build: |
| 38 | + name: Build distributions |
| 39 | + runs-on: ubuntu-latest |
| 40 | + permissions: |
| 41 | + contents: read |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Set up Python |
| 46 | + uses: actions/setup-python@v5 |
| 47 | + with: |
| 48 | + python-version: "3.13" |
| 49 | + |
| 50 | + - name: Install build tools |
| 51 | + run: | |
| 52 | + python -m pip install --upgrade pip |
| 53 | + pip install build twine |
| 54 | +
|
| 55 | + - name: Build sdist and wheel |
| 56 | + run: python -m build |
| 57 | + |
| 58 | + - name: Check distributions |
| 59 | + run: twine check --strict dist/* |
| 60 | + |
| 61 | + - uses: actions/upload-artifact@v4 |
| 62 | + with: |
| 63 | + name: dist |
| 64 | + path: dist/ |
| 65 | + |
| 66 | + publish-pypi: |
| 67 | + name: Publish to PyPI |
| 68 | + if: github.event_name == 'release' |
| 69 | + needs: [build] |
| 70 | + runs-on: ubuntu-latest |
| 71 | + environment: |
| 72 | + name: pypi |
| 73 | + url: https://pypi.org/project/jsonpointer/ |
| 74 | + permissions: |
| 75 | + id-token: write |
| 76 | + steps: |
| 77 | + - uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: dist |
| 80 | + path: dist/ |
| 81 | + |
| 82 | + - name: Publish to PyPI |
| 83 | + uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1 |
| 84 | + |
| 85 | + publish-testpypi: |
| 86 | + name: Publish to TestPyPI |
| 87 | + if: github.event_name == 'workflow_dispatch' |
| 88 | + needs: [build] |
| 89 | + runs-on: ubuntu-latest |
| 90 | + environment: |
| 91 | + name: testpypi |
| 92 | + url: https://test.pypi.org/project/jsonpointer/ |
| 93 | + permissions: |
| 94 | + id-token: write |
| 95 | + steps: |
| 96 | + - uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + name: dist |
| 99 | + path: dist/ |
| 100 | + |
| 101 | + - name: Publish to TestPyPI |
| 102 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 103 | + with: |
| 104 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments