From 37b9dbdbf4cdb1508d859f77f929ef0b75ee3aa4 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 12 May 2023 12:17:55 -0300 Subject: [PATCH] Deploy via a protected environment and using PyPI trusted publishers (#902) Following recent discussions, this changes the development process as follows: 1. The deploy is now manually triggered after the release PR is approved. 2. The deploy workflow tags the repository only after the package has been published to PyPI. 3. Use PyPI trusted publishers instead of API tokens. Co-authored-by: Ran Benita --- .github/workflows/deploy.yml | 56 ++++++++++++++++++++++-------------- RELEASING.rst | 12 ++------ 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d30f508..6111ae1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,33 +1,47 @@ name: deploy on: - push: - tags: - - "v*" + workflow_dispatch: + inputs: + version: + description: 'Release version' + required: true + default: '1.2.3' jobs: - deploy: + package: runs-on: ubuntu-latest + env: + SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.inputs.version }} steps: - uses: actions/checkout@v3 + + - name: Build and Check Package + uses: hynek/build-and-inspect-python-package@v1.5 + + deploy: + needs: package + runs-on: ubuntu-latest + environment: deploy + permissions: + id-token: write # For PyPI trusted publishers. + contents: write # For tag. + + steps: + - uses: actions/checkout@v3 + + - name: Download Package + uses: actions/download-artifact@v3 with: - # Needed to fetch tags, which are required by setuptools-scm. - fetch-depth: 0 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.10" - - name: Install build - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: | - python -m build + name: Packages + path: dist + - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.pypi_token }} + uses: pypa/gh-action-pypi-publish@v1.8.5 + + - name: Push tag + run: | + git tag --annotate --message=v${{ github.event.inputs.version }} v${{ github.event.inputs.version }} ${{ github.sha }} + git push origin v${{ github.event.inputs.version }} diff --git a/RELEASING.rst b/RELEASING.rst index 5cfd7c0..62ce003 100644 --- a/RELEASING.rst +++ b/RELEASING.rst @@ -32,14 +32,8 @@ To publish a new release ``X.Y.Z``, the steps are as follows: $ tox -e release -- X.Y.Z -#. Commit and push the branch for review. +#. Commit and push the branch to ``upstream`` and open a PR. -#. Once PR is **green** and **approved**, create and push a tag:: +#. Once the PR is **green** and **approved**, start the ``deploy`` workflow manually from the branch ``release-VERSION``, passing ``VERSION`` as parameter. - $ export VERSION=X.Y.Z - $ git tag v$VERSION release-$VERSION - $ git push git@github.com:pytest-dev/pytest-xdist.git v$VERSION - -That will build the package and publish it on ``PyPI`` automatically. - -#. Merge the release PR to `master`. +#. Merge the release PR to ``master``.