diff --git a/docs/deliver-to-pypi.md b/docs/deliver-to-pypi.md index 58b3d6a8..b113fcb7 100644 --- a/docs/deliver-to-pypi.md +++ b/docs/deliver-to-pypi.md @@ -61,13 +61,16 @@ well as several useful actions. Alongside your existing job(s) that runs cibuild path: dist/*.tar.gz ``` -Then, you need to publish the artifacts that the previous jobs have built. This final job should run only on release or tag, depending on your preference. It gathers the artifacts from the sdist and wheel jobs and uploads them to PyPI. +Then, you need to publish the artifacts that the previous jobs have built. This final job should run only on release or tag, depending on your preference. It gathers the artifacts from the sdist and wheel jobs and uploads them to PyPI. The release environment (`pypi` in the example below) will be created the first time this workflow runs. -This requires a [PyPI upload token](https://pypi.org/manage/account/token/), stored in your [GitHub repo's secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) as `pypi_password`. +This requires setting this GitHub workflow in your project's PyPI settings (for a [new project](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc)/[existing project](https://docs.pypi.org/trusted-publishers/adding-a-publisher)). ```yaml upload_all: needs: [build_wheels, make_sdist] + environment: pypi + permissions: + id-token: write runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' steps: @@ -76,10 +79,7 @@ This requires a [PyPI upload token](https://pypi.org/manage/account/token/), sto name: artifact path: dist - - uses: pypa/gh-action-pypi-publish@v1.5.0 - with: - user: __token__ - password: ${{ secrets.pypi_password }} + - uses: pypa/gh-action-pypi-publish@release/v1 ``` You should use Dependabot to keep the publish action up to date. In the above diff --git a/examples/github-deploy.yml b/examples/github-deploy.yml index b461a30b..fdb19c08 100644 --- a/examples/github-deploy.yml +++ b/examples/github-deploy.yml @@ -1,14 +1,14 @@ name: Build and upload to PyPI -# Build on every branch push, tag push, and pull request change: -on: [push, pull_request] -# Alternatively, to publish when a (published) GitHub Release is created, use the following: -# on: -# push: -# pull_request: -# release: -# types: -# - published +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + release: + types: + - published jobs: build_wheels: @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-2019, macos-11] + os: [ubuntu-22.04, windows-2022, macos-11] steps: - uses: actions/checkout@v3 @@ -44,10 +44,10 @@ jobs: upload_pypi: needs: [build_wheels, build_sdist] runs-on: ubuntu-latest - # upload to PyPI on every tag starting with 'v' - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - # alternatively, to publish when a GitHub Release is created, use the following rule: - # if: github.event_name == 'release' && github.event.action == 'published' + environment: pypi + permissions: + id-token: write + if: github.event_name == 'release' && github.event.action == 'published' steps: - uses: actions/download-artifact@v3 with: @@ -56,8 +56,6 @@ jobs: name: artifact path: dist - - uses: pypa/gh-action-pypi-publish@v1.5.0 + - uses: pypa/gh-action-pypi-publish@release/v1 with: - user: __token__ - password: ${{ secrets.pypi_password }} # To test: repository_url: https://test.pypi.org/legacy/