Skip to content

Commit 37b9dbd

Browse files
nicoddemusbluetech
andauthored
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 <[email protected]>
1 parent be1d5c4 commit 37b9dbd

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

.github/workflows/deploy.yml

+35-21
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
name: deploy
22

33
on:
4-
push:
5-
tags:
6-
- "v*"
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Release version'
8+
required: true
9+
default: '1.2.3'
710

811
jobs:
9-
deploy:
1012

13+
package:
1114
runs-on: ubuntu-latest
15+
env:
16+
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.inputs.version }}
1217

1318
steps:
1419
- uses: actions/checkout@v3
20+
21+
- name: Build and Check Package
22+
uses: hynek/[email protected]
23+
24+
deploy:
25+
needs: package
26+
runs-on: ubuntu-latest
27+
environment: deploy
28+
permissions:
29+
id-token: write # For PyPI trusted publishers.
30+
contents: write # For tag.
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
35+
- name: Download Package
36+
uses: actions/download-artifact@v3
1537
with:
16-
# Needed to fetch tags, which are required by setuptools-scm.
17-
fetch-depth: 0
18-
- name: Set up Python
19-
uses: actions/setup-python@v2
20-
with:
21-
python-version: "3.10"
22-
- name: Install build
23-
run: |
24-
python -m pip install --upgrade pip
25-
pip install build
26-
- name: Build package
27-
run: |
28-
python -m build
38+
name: Packages
39+
path: dist
40+
2941
- name: Publish package to PyPI
30-
uses: pypa/gh-action-pypi-publish@release/v1
31-
with:
32-
user: __token__
33-
password: ${{ secrets.pypi_token }}
42+
uses: pypa/[email protected]
43+
44+
- name: Push tag
45+
run: |
46+
git tag --annotate --message=v${{ github.event.inputs.version }} v${{ github.event.inputs.version }} ${{ github.sha }}
47+
git push origin v${{ github.event.inputs.version }}

RELEASING.rst

+3-9
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@ To publish a new release ``X.Y.Z``, the steps are as follows:
3232

3333
$ tox -e release -- X.Y.Z
3434

35-
#. Commit and push the branch for review.
35+
#. Commit and push the branch to ``upstream`` and open a PR.
3636

37-
#. Once PR is **green** and **approved**, create and push a tag::
37+
#. Once the PR is **green** and **approved**, start the ``deploy`` workflow manually from the branch ``release-VERSION``, passing ``VERSION`` as parameter.
3838

39-
$ export VERSION=X.Y.Z
40-
$ git tag v$VERSION release-$VERSION
41-
$ git push [email protected]:pytest-dev/pytest-xdist.git v$VERSION
42-
43-
That will build the package and publish it on ``PyPI`` automatically.
44-
45-
#. Merge the release PR to `master`.
39+
#. Merge the release PR to ``master``.

0 commit comments

Comments
 (0)