|
54 | 54 | description: Command to run after test commands.
|
55 | 55 | required: false
|
56 | 56 | type: string
|
| 57 | + publish_pypi: |
| 58 | + default: false |
| 59 | + description: Whether to publish to PyPI |
| 60 | + required: false |
| 61 | + type: boolean |
57 | 62 | # keep permissions at top level because this is a composite workflow
|
58 | 63 | permissions:
|
59 | 64 | checks: read
|
60 | 65 | contents: read
|
61 |
| - id-token: write |
| 66 | + id-token: write # release |
62 | 67 | packages: write # some tox environments might produce containers
|
63 | 68 | pull-requests: write # allow codenotify to comment on pull-request
|
64 | 69 | env:
|
@@ -247,3 +252,44 @@ jobs:
|
247 | 252 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
248 | 253 | # https://github.com/sourcegraph/codenotify/issues/19
|
249 | 254 | continue-on-error: true
|
| 255 | + |
| 256 | + pypi: |
| 257 | + name: release ${{ github.event.ref }} |
| 258 | + # if: github.ref_type == 'tag' || inputs.publish_pypi == 'true' |
| 259 | + needs: check |
| 260 | + environment: release # keep it here to allow users to prompt for release |
| 261 | + runs-on: ubuntu-24.04 |
| 262 | + steps: |
| 263 | + - name: Switch to using Python 3.12 by default |
| 264 | + uses: actions/setup-python@v5 |
| 265 | + with: |
| 266 | + python-version: "3.12" |
| 267 | + |
| 268 | + - name: Install tox |
| 269 | + run: python3 -m pip install --user "tox>=4.0.0" |
| 270 | + |
| 271 | + - name: Check out src from Git |
| 272 | + uses: actions/checkout@v4 |
| 273 | + with: |
| 274 | + fetch-depth: 0 # needed by setuptools-scm |
| 275 | + |
| 276 | + - name: Build dists |
| 277 | + run: python3 -m tox -e pkg |
| 278 | + |
| 279 | + - name: Fail if secrets are not available |
| 280 | + env: |
| 281 | + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} |
| 282 | + run: | |
| 283 | + if [ -z "${PYPI_API_TOKEN}" ]; then |
| 284 | + echo "PYPI_API_TOKEN is not set, please add it to your repository environment named 'release'." |
| 285 | + exit 1 |
| 286 | + fi |
| 287 | +
|
| 288 | + - name: Publish to pypi.org |
| 289 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 290 | + if: inputs.publish_pypi |
| 291 | + with: |
| 292 | + # trusted publishing is not possible with shared workflows due to |
| 293 | + # https://github.com/pypi/warehouse/issues/11096 so we need to use |
| 294 | + # secrets instead. |
| 295 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments