Skip to content

Commit

Permalink
Deploy via a protected environment and using PyPI trusted publishers (#…
Browse files Browse the repository at this point in the history
…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 <ran@unusedvar.com>
  • Loading branch information
nicoddemus and bluetech committed May 12, 2023
1 parent be1d5c4 commit 37b9dbd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
56 changes: 35 additions & 21 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
12 changes: 3 additions & 9 deletions RELEASING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

0 comments on commit 37b9dbd

Please sign in to comment.