Skip to content

Commit b5836f6

Browse files
authored
Merge pull request #731 from pytest-dev/test-on-the-built-artifact
Upload to PyPI the same dist that we tested on
2 parents dcafea0 + f8c2a01 commit b5836f6

File tree

3 files changed

+97
-67
lines changed

3 files changed

+97
-67
lines changed

.github/workflows/main.yml

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,32 @@ 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+
- name: Build a binary wheel and a source tarball
23+
run: python3 -m build
24+
- name: Upload artifact
25+
id: artifact-upload-step
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: dist-files
29+
path: dist/*
30+
if-no-files-found: error
31+
compression-level: 0 # They are already compressed
932
test-run:
1033
runs-on: ubuntu-latest
34+
needs: build
1135
strategy:
1236
matrix:
1337
include:
@@ -33,57 +57,64 @@ jobs:
3357
ignore-test-outcome: false
3458

3559
steps:
36-
- uses: actions/checkout@v3
60+
- uses: actions/checkout@v4
61+
62+
- name: Set up Python ${{ matrix.python-version }}
63+
uses: actions/setup-python@v4
64+
id: setup-python
65+
with:
66+
python-version: ${{ matrix.python-version }}
3767

38-
- name: Set up Python ${{ matrix.python-version }}
39-
uses: actions/setup-python@v4
40-
id: setup-python
41-
with:
42-
python-version: ${{ matrix.python-version }}
68+
- name: Install poetry
69+
run: |
70+
python -m pip install poetry==1.8.3
4371
44-
- name: Install poetry
45-
run: |
46-
python -m pip install poetry==1.8.3
72+
- name: Configure poetry
73+
run: |
74+
python -m poetry config virtualenvs.in-project true
4775
48-
- name: Configure poetry
49-
run: |
50-
python -m poetry config virtualenvs.in-project true
76+
- name: Cache the virtualenv
77+
id: poetry-dependencies-cache
78+
uses: actions/cache@v3
79+
with:
80+
path: ./.venv
81+
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
5182

52-
- name: Cache the virtualenv
53-
id: poetry-dependencies-cache
54-
uses: actions/cache@v3
55-
with:
56-
path: ./.venv
57-
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
83+
- name: Install dev dependencies
84+
if: steps.poetry-dependencies-cache.outputs.cache-hit != 'true'
85+
run: |
86+
python -m poetry install --only=dev
5887
59-
- name: Install dev dependencies
60-
if: steps.poetry-dependencies-cache.outputs.cache-hit != 'true'
61-
run: |
62-
python -m poetry install --only=dev
88+
- name: Download artifact
89+
uses: actions/download-artifact@v4
90+
with:
91+
name: dist-files
92+
path: dist/
6393

64-
- name: Type checking
65-
# Ignore errors for older pythons
66-
continue-on-error: ${{ matrix.ignore-typecheck-outcome }}
67-
run: |
68-
source .venv/bin/activate
69-
tox -e mypy
94+
- name: Type checking
95+
# Ignore errors for older pythons
96+
continue-on-error: ${{ matrix.ignore-typecheck-outcome }}
97+
run: |
98+
source .venv/bin/activate
99+
tox -e mypy
70100
71-
- name: Test with tox
72-
continue-on-error: ${{ matrix.ignore-test-outcome }}
73-
run: |
74-
source .venv/bin/activate
75-
coverage erase
76-
tox run-parallel -f ${{ matrix.toxfactor }} --parallel-no-spinner --parallel-live
77-
coverage combine
78-
coverage xml
101+
- name: Test with tox
102+
continue-on-error: ${{ matrix.ignore-test-outcome }}
103+
run: |
104+
source .venv/bin/activate
105+
coverage erase
106+
# Using `installpkg dist/*.tar.gz` because we want to install the pre-built package (want to test against that)
107+
tox run-parallel -f ${{ matrix.toxfactor }} --parallel-no-spinner --parallel-live --installpkg dist/*.whl
108+
coverage combine
109+
coverage xml
79110
80-
- uses: codecov/codecov-action@v4
81-
with:
82-
# Explicitly using the token to avoid Codecov rate limit errors
83-
# See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
84-
token: ${{ secrets.CODECOV_TOKEN }}
85-
fail_ci_if_error: false
86-
verbose: true # optional (default = false)
111+
- uses: codecov/codecov-action@v4
112+
with:
113+
# Explicitly using the token to avoid Codecov rate limit errors
114+
# See https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
115+
token: ${{ secrets.CODECOV_TOKEN }}
116+
fail_ci_if_error: false
117+
verbose: true # optional (default = false)
87118

88119
pypi-publish:
89120
name: Upload release to PyPI
@@ -94,18 +125,14 @@ jobs:
94125
permissions:
95126
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
96127
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
97-
needs: test-run
128+
needs:
129+
- "test-run"
130+
- "build"
98131
steps:
99-
- uses: actions/checkout@v4
100-
- name: Set up Python
101-
uses: actions/setup-python@v5
102-
- name: Install pypa/build
103-
run: >-
104-
python3 -m
105-
pip install
106-
build
107-
--user
108-
- name: Build a binary wheel and a source tarball
109-
run: python3 -m build
132+
- name: Download artifact
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: dist-files
136+
path: dist/
110137
- name: Publish package distributions to PyPI
111138
uses: pypa/gh-action-pypi-publish@release/v1

poetry.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tox.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ deps =
2525
commands = {env:_PYTEST_CMD:pytest} {env:_PYTEST_MORE_ARGS:} {posargs:-vvl}
2626

2727
[testenv:mypy]
28-
skip_install = true
29-
allowlist_externals = poetry
28+
deps = poetry
29+
allowlist_externals = sh
3030
commands_pre =
31-
poetry install --with=dev
31+
sh -c "\
32+
poetry export --only=dev --format requirements.txt > requirements.txt && \
33+
pip install -r requirements.txt && \
34+
:"
3235
commands = mypy

0 commit comments

Comments
 (0)