Skip to content

Commit bc11330

Browse files
committed
Improve CI workflow
* Build the package only once, and test on all platforms. * Deploy is now triggered manually via an Action, which is then responsible for tagging the repository after the package has been uploaded successfully.
1 parent 7a0a0e8 commit bc11330

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

.github/workflows/deploy.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
name: deploy
22

33
on:
4-
push:
5-
tags:
6-
# These tags are protected, see:
7-
# https://github.com/pytest-dev/pytest/settings/tag_protection
8-
- "[0-9]+.[0-9]+.[0-9]+"
9-
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Release version'
8+
required: true
9+
default: '1.2.3'
1010

1111

1212
# Set permissions at the job level.
1313
permissions: {}
1414

1515
jobs:
16-
build:
16+
package:
1717
runs-on: ubuntu-latest
18+
env:
19+
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.inputs.version }}
1820
timeout-minutes: 10
21+
1922
steps:
2023
- uses: actions/checkout@v3
2124
with:
2225
fetch-depth: 0
2326
persist-credentials: false
27+
2428
- name: Build and Check Package
2529
uses: hynek/[email protected]
2630

2731
deploy:
2832
if: github.repository == 'pytest-dev/pytest'
29-
needs: [build]
33+
needs: [package]
3034
runs-on: ubuntu-latest
35+
environment: deploy
3136
timeout-minutes: 30
3237
permissions:
3338
id-token: write
@@ -37,9 +42,17 @@ jobs:
3742
with:
3843
name: Packages
3944
path: dist
45+
4046
- name: Publish package to PyPI
4147
uses: pypa/[email protected]
4248

49+
- name: Push tag
50+
run: |
51+
git config user.name "pytest bot"
52+
git config user.email "[email protected]"
53+
git tag --annotate --message=v${{ github.event.inputs.version }} v${{ github.event.inputs.version }} ${{ github.sha }}
54+
git push origin v${{ github.event.inputs.version }}
55+
4356
release-notes:
4457

4558
# todo: generate the content in the build job
@@ -55,11 +68,11 @@ jobs:
5568
with:
5669
fetch-depth: 0
5770
persist-credentials: false
71+
5872
- name: Set up Python
5973
uses: actions/setup-python@v4
6074
with:
61-
python-version: "3.7"
62-
75+
python-version: "3.10"
6376

6477
- name: Install tox
6578
run: |

.github/workflows/test.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ concurrency:
2727
permissions: {}
2828

2929
jobs:
30+
package:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v3
34+
with:
35+
fetch-depth: 0
36+
persist-credentials: false
37+
- name: Build and Check Package
38+
uses: hynek/[email protected]
39+
3040
build:
41+
needs: [package]
42+
3143
runs-on: ${{ matrix.os }}
3244
timeout-minutes: 45
3345
permissions:
@@ -175,6 +187,12 @@ jobs:
175187
fetch-depth: 0
176188
persist-credentials: false
177189

190+
- name: Download Package
191+
uses: actions/download-artifact@v3
192+
with:
193+
name: Packages
194+
path: dist
195+
178196
- name: Set up Python ${{ matrix.python }}
179197
uses: actions/setup-python@v4
180198
with:
@@ -188,11 +206,13 @@ jobs:
188206
189207
- name: Test without coverage
190208
if: "! matrix.use_coverage"
191-
run: "tox -e ${{ matrix.tox_env }}"
209+
shell: bash
210+
run: tox run -e ${{ matrix.tox_env }} --installpkg `find dist/*.tar.gz`
192211

193212
- name: Test with coverage
194213
if: "matrix.use_coverage"
195-
run: "tox -e ${{ matrix.tox_env }}-coverage"
214+
shell: bash
215+
run: tox run -e ${{ matrix.tox_env }}-coverage --installpkg `find dist/*.tar.gz`
196216

197217
- name: Generate coverage report
198218
if: "matrix.use_coverage"
@@ -206,10 +226,3 @@ jobs:
206226
fail_ci_if_error: true
207227
files: ./coverage.xml
208228
verbose: true
209-
210-
check-package:
211-
runs-on: ubuntu-latest
212-
steps:
213-
- uses: actions/checkout@v3
214-
- name: Build and Check Package
215-
uses: hynek/[email protected]

RELEASING.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,11 @@ Releasing
133133

134134
Both automatic and manual processes described above follow the same steps from this point onward.
135135

136-
#. After all tests pass and the PR has been approved, tag the release commit
137-
in the ``release-MAJOR.MINOR.PATCH`` branch and push it. This will publish to PyPI::
136+
#. After all tests pass and the PR has been approved, trigger the ``deploy`` job
137+
in https://github.com/pytest-dev/pytest/actions/workflows/deploy.yml.
138138

139-
git fetch upstream
140-
git tag MAJOR.MINOR.PATCH upstream/release-MAJOR.MINOR.PATCH
141-
git push upstream MAJOR.MINOR.PATCH
142-
143-
Wait for the deploy to complete, then make sure it is `available on PyPI <https://pypi.org/project/pytest>`_.
139+
This job will require approval from ``pytest-dev/core``, after which it will publish to PyPI
140+
and tag the repository.
144141

145142
#. Merge the PR. **Make sure it's not squash-merged**, so that the tagged commit ends up in the main branch.
146143

0 commit comments

Comments
 (0)