Skip to content

Commit fce0812

Browse files
committed
Test sdist contents instead of Git checkout in CI
This patch helps make sure that sdist contents is enough to run tests downstream. It also includes a smoke test for whether all the tests present in Git have been included into the sdist. Suggested by Kyle Altendorf [[1]] [[2]]. [1]: #2541 (comment) [2]: https://github.com/Chia-Network/chia-blockchain/blob/6dfcd51/.github/workflows/test-single.yml#L208-L243
1 parent 0f270f9 commit fce0812

File tree

2 files changed

+172
-10
lines changed

2 files changed

+172
-10
lines changed

.github/workflows/ci.yml

Lines changed: 165 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,133 @@ concurrency:
1414
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && format('-{0}', github.sha) || '' }}
1515
cancel-in-progress: true
1616

17+
env:
18+
dists-artifact-name: python-package-distributions
19+
dist-name: trio
20+
1721
jobs:
22+
build:
23+
name: 👷 dists
24+
25+
runs-on: ubuntu-latest
26+
27+
outputs:
28+
dist-version: ${{ steps.dist-version.outputs.version }}
29+
sdist-artifact-name: ${{ steps.artifact-name.outputs.sdist }}
30+
wheel-artifact-name: ${{ steps.artifact-name.outputs.wheel }}
31+
32+
steps:
33+
- name: Switch to using Python 3.11
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: 3.11
37+
38+
- name: Grab the source from Git
39+
uses: actions/checkout@v4
40+
41+
- name: Get the dist version
42+
id: dist-version
43+
run: >-
44+
echo "version=$(
45+
grep ^__version__ src/trio/_version.py
46+
| sed 's#__version__ = "\([^"]\+\)"#\1#'
47+
)"
48+
>> "${GITHUB_OUTPUT}"
49+
50+
- name: Set the expected dist artifact names
51+
id: artifact-name
52+
run: |
53+
echo 'sdist=${{ env.dist-name }}-*.tar.gz' >> "${GITHUB_OUTPUT}"
54+
echo 'wheel=${{
55+
env.dist-name
56+
}}-*-py3-none-any.whl' >> "${GITHUB_OUTPUT}"
57+
58+
- name: Install build
59+
run: python -Im pip install build
60+
61+
- name: Build dists
62+
run: python -Im build
63+
- name: Verify that the artifacts with expected names got created
64+
run: >-
65+
ls -1
66+
dist/${{ steps.artifact-name.outputs.sdist }}
67+
dist/${{ steps.artifact-name.outputs.wheel }}
68+
- name: Store the distribution packages
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: ${{ env.dists-artifact-name }}
72+
# NOTE: Exact expected file names are specified here
73+
# NOTE: as a safety measure — if anything weird ends
74+
# NOTE: up being in this dir or not all dists will be
75+
# NOTE: produced, this will fail the workflow.
76+
path: |
77+
dist/${{ steps.artifact-name.outputs.sdist }}
78+
dist/${{ steps.artifact-name.outputs.wheel }}
79+
retention-days: 5
80+
81+
- name: >-
82+
Smoke-test:
83+
retrieve the project source from an sdist inside the GHA artifact
84+
uses: re-actors/checkout-python-sdist@release/v2
85+
with:
86+
source-tarball-name: ${{ steps.artifact-name.outputs.sdist }}
87+
workflow-artifact-name: ${{ env.dists-artifact-name }}
88+
89+
- name: >-
90+
Smoke-test: move the sdist-retrieved dir into sdist-src
91+
run: |
92+
mv -v '${{ github.workspace }}' '${{ runner.temp }}/sdist-src'
93+
mkdir -pv '${{ github.workspace }}'
94+
mv -v '${{ runner.temp }}/sdist-src' '${{ github.workspace }}/sdist-src'
95+
shell: bash -eEuo pipefail {0}
96+
97+
- name: >-
98+
Smoke-test: grab the source from Git into git-src
99+
uses: actions/checkout@v4
100+
with:
101+
path: git-src
102+
103+
- name: >-
104+
Smoke-test: install test requirements from the Git repo
105+
run: >-
106+
python -Im
107+
pip install -c test-requirements.txt -r test-requirements.txt
108+
shell: bash -eEuo pipefail {0}
109+
working-directory: git-src
110+
111+
- name: >-
112+
Smoke-test: collect tests from the Git repo
113+
env:
114+
PYTHONPATH: src/
115+
run: >-
116+
pytest --collect-only -qq .
117+
| sort
118+
| tee collected-tests
119+
shell: bash -eEuo pipefail {0}
120+
working-directory: git-src
121+
122+
- name: >-
123+
Smoke-test: collect tests from the sdist tarball
124+
env:
125+
PYTHONPATH: src/
126+
run: >-
127+
pytest --collect-only -qq .
128+
| sort
129+
| tee collected-tests
130+
shell: bash -eEuo pipefail {0}
131+
working-directory: sdist-src
132+
133+
- name: >-
134+
Smoke-test:
135+
verify that all the tests from Git are included in the sdist
136+
run: diff --unified sdist-src/collected-tests git-src/collected-tests
137+
shell: bash -eEuo pipefail {0}
138+
18139
Windows:
19140
name: 'Windows (${{ matrix.python }}, ${{ matrix.arch }}${{ matrix.extra_name }})'
141+
needs:
142+
- build
143+
20144
timeout-minutes: 20
21145
runs-on: 'windows-latest'
22146
strategy:
@@ -58,8 +182,11 @@ jobs:
58182
|| false
59183
}}
60184
steps:
61-
- name: Checkout
62-
uses: actions/checkout@v4
185+
- name: Retrieve the project source from an sdist inside the GHA artifact
186+
uses: re-actors/checkout-python-sdist@release/v2
187+
with:
188+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
189+
workflow-artifact-name: ${{ env.dists-artifact-name }}
63190
- name: Setup python
64191
uses: actions/setup-python@v5
65192
with:
@@ -94,6 +221,9 @@ jobs:
94221

95222
Ubuntu:
96223
name: 'Ubuntu (${{ matrix.python }}${{ matrix.extra_name }})'
224+
needs:
225+
- build
226+
97227
timeout-minutes: 10
98228
runs-on: 'ubuntu-latest'
99229
strategy:
@@ -121,7 +251,14 @@ jobs:
121251
|| false
122252
}}
123253
steps:
124-
- name: Checkout
254+
- name: Retrieve the project source from an sdist inside the GHA artifact
255+
if: matrix.check_formatting != '1'
256+
uses: re-actors/checkout-python-sdist@release/v2
257+
with:
258+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
259+
workflow-artifact-name: ${{ env.dists-artifact-name }}
260+
- name: Grab the source from Git
261+
if: matrix.check_formatting == '1'
125262
uses: actions/checkout@v4
126263
- name: Setup python
127264
uses: actions/setup-python@v5
@@ -146,6 +283,9 @@ jobs:
146283
147284
macOS:
148285
name: 'macOS (${{ matrix.python }})'
286+
needs:
287+
- build
288+
149289
timeout-minutes: 15
150290
runs-on: 'macos-latest'
151291
strategy:
@@ -162,8 +302,11 @@ jobs:
162302
|| false
163303
}}
164304
steps:
165-
- name: Checkout
166-
uses: actions/checkout@v4
305+
- name: Retrieve the project source from an sdist inside the GHA artifact
306+
uses: re-actors/checkout-python-sdist@release/v2
307+
with:
308+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
309+
workflow-artifact-name: ${{ env.dists-artifact-name }}
167310
- name: Setup python
168311
uses: actions/setup-python@v5
169312
with:
@@ -183,17 +326,24 @@ jobs:
183326
# run CI on a musl linux
184327
Alpine:
185328
name: "Alpine"
329+
needs:
330+
- build
331+
186332
runs-on: ubuntu-latest
187333
container: alpine
188334
steps:
189-
- name: Checkout
190-
uses: actions/checkout@v4
191335
- name: Install necessary packages
192336
# can't use setup-python because that python doesn't seem to work;
193337
# `python3-dev` (rather than `python:alpine`) for some ctypes reason,
194338
# `nodejs` for pyright (`node-env` pulls in nodejs but that takes a while and can time out the test).
195339
# `perl` for a platform independent `sed -i` alternative
196340
run: apk update && apk add python3-dev bash nodejs perl
341+
- name: Retrieve the project source from an sdist inside the GHA artifact
342+
# must be after `apk add` because it relies on `bash` existing
343+
uses: re-actors/checkout-python-sdist@release/v2
344+
with:
345+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
346+
workflow-artifact-name: ${{ env.dists-artifact-name }}
197347
- name: Enter virtual environment
198348
run: python -m venv .venv
199349
- name: Run tests
@@ -211,6 +361,9 @@ jobs:
211361

212362
Cython:
213363
name: "Cython"
364+
needs:
365+
- build
366+
214367
runs-on: ubuntu-latest
215368
strategy:
216369
fail-fast: false
@@ -225,8 +378,11 @@ jobs:
225378
- python: '3.13' # We support running cython3 on 3.13
226379
cython: '>=3' # cython 3 (or greater)
227380
steps:
228-
- name: Checkout
229-
uses: actions/checkout@v4
381+
- name: Retrieve the project source from an sdist inside the GHA artifact
382+
uses: re-actors/checkout-python-sdist@release/v2
383+
with:
384+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
385+
workflow-artifact-name: ${{ env.dists-artifact-name }}
230386
- name: Setup python
231387
uses: actions/setup-python@v5
232388
with:

MANIFEST.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
include .codecov.yml
2+
include check.sh
3+
include ci.sh
14
include LICENSE LICENSE.MIT LICENSE.APACHE2
25
include README.rst
36
include CODE_OF_CONDUCT.md CONTRIBUTING.md
4-
include test-requirements.txt
7+
include *-requirements.in
8+
include *-requirements.txt
59
include src/trio/py.typed
10+
include src/trio/_tests/astrill-codesigning-cert.cer
611
recursive-include src/trio/_tests/test_ssl_certs *.pem
712
recursive-include docs *
13+
recursive-include tests *
814
prune docs/build

0 commit comments

Comments
 (0)