Skip to content

Commit 93b1036

Browse files
authored
Merge pull request #240 from pytest-dev/ab/add-automated-release
Add CI enhancements for package building, artifact handling, and automated PyPI publishing
2 parents 9999a2f + 0d501fb commit 93b1036

File tree

2 files changed

+70
-7
lines changed

2 files changed

+70
-7
lines changed

.github/workflows/main.yml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,35 @@ on:
66
workflow_dispatch:
77

88
jobs:
9+
build:
10+
name: Build package
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
cache: "pip"
18+
- name: Install pypa/build
19+
run: >-
20+
python3 -m pip install --user
21+
build
22+
twine
23+
- name: Build a binary wheel and a source tarball
24+
run: python3 -m build
25+
- name: Check the distribution files with `twine`
26+
run: twine check --strict dist/*
27+
- name: Upload artifact
28+
id: artifact-upload-step
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: dist-files
32+
path: dist/*
33+
if-no-files-found: error
34+
compression-level: 0 # They are already compressed
935
test-run:
1036
runs-on: ubuntu-latest
37+
needs: build
1138
strategy:
1239
matrix:
1340
include:
@@ -33,7 +60,7 @@ jobs:
3360
ignore-test-outcome: false
3461

3562
steps:
36-
- uses: actions/checkout@v3
63+
- uses: actions/checkout@v4
3764

3865
- name: Set up Python ${{ matrix.python-version }}
3966
uses: actions/setup-python@v4
@@ -61,6 +88,12 @@ jobs:
6188
run: |
6289
python -m poetry install --only=dev
6390
91+
- name: Download artifact
92+
uses: actions/download-artifact@v4
93+
with:
94+
name: dist-files
95+
path: dist/
96+
6497
- name: Type checking
6598
# Ignore errors for older pythons
6699
continue-on-error: ${{ matrix.ignore-typecheck-outcome }}
@@ -73,14 +106,37 @@ jobs:
73106
run: |
74107
source .venv/bin/activate
75108
coverage erase
76-
tox run-parallel -f ${{ matrix.toxfactor }} --parallel-no-spinner --parallel-live
109+
# Using `--parallel 4` as it's the number of CPUs in the GitHub Actions runner
110+
# Using `installpkg dist/*.whl` because we want to install the pre-built package (want to test against that)
111+
tox run-parallel -f ${{ matrix.toxfactor }} --parallel 4 --parallel-no-spinner --parallel-live --installpkg dist/*.whl
77112
coverage combine
78113
coverage xml
79114
80115
- uses: codecov/codecov-action@v4
81116
with:
82-
# Explicitly using the token in order to avoid Codecov rate limit errors
117+
# Explicitly using the token to avoid Codecov rate limit errors
83118
# See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
84119
token: ${{ secrets.CODECOV_TOKEN }}
85-
fail_ci_if_error: true
120+
fail_ci_if_error: false
86121
verbose: true # optional (default = false)
122+
123+
pypi-publish:
124+
name: Upload release to PyPI
125+
runs-on: ubuntu-latest
126+
environment:
127+
name: pypi
128+
url: https://pypi.org/p/pytest-factoryboy
129+
permissions:
130+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
131+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
132+
needs:
133+
- "test-run"
134+
- "build"
135+
steps:
136+
- name: Download artifact
137+
uses: actions/download-artifact@v4
138+
with:
139+
name: dist-files
140+
path: dist/
141+
- name: Publish package distributions to PyPI
142+
uses: pypa/gh-action-pypi-publish@release/v1

RELEASING.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
poetry version <newversion>
66
```
77
2. Update the [CHANGES.rst](CHANGES.rst) file with the release notes and the new version.
8-
3. Build and publish the package:
9-
8+
3. Commit the changes:
9+
```shell
10+
git add pyproject.toml CHANGES.rst
11+
git commit -m "Bump version to <newversion>"
12+
```
13+
4. Create and push a tag:
1014
```shell
11-
poetry publish --build
15+
git tag <newversion>
16+
git push origin <newversion>
1217
```
18+
19+
The GitHub Actions workflow will automatically build and publish the package to PyPI when a tag is pushed.

0 commit comments

Comments
 (0)