Skip to content

Commit eff6c0d

Browse files
Test built artifacts in the CI instead of Git src (#682)
This approach helps make sure that what is tested in the project is the same as what the end-users get installed on their machines. It will catch failures to include important failes into the packages that get uploaded to PyPI. Co-authored-by: Abhinav Singh <[email protected]>
1 parent 423e9ce commit eff6c0d

File tree

1 file changed

+118
-14
lines changed

1 file changed

+118
-14
lines changed

.github/workflows/test-library.yml

Lines changed: 118 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
runs-on: ${{ matrix.os }}-latest
1818
name: >-
1919
e2e: 🐍${{ matrix.python }} @ ${{ matrix.os }}
20+
needs:
21+
- build
2022
strategy:
2123
matrix:
2224
os: [macOS, Ubuntu]
@@ -25,40 +27,118 @@ jobs:
2527
fail-fast: false
2628
steps:
2729
- uses: actions/checkout@v2
30+
- name: Make the env clean of non-test files
31+
run: |
32+
shopt -s extglob
33+
mv -v tests/integration/main.sh integration-test.sh
34+
rm -rf !integration-test.sh
35+
shell: bash
2836
- name: Setup Python
2937
uses: actions/setup-python@v2
3038
with:
3139
python-version: ${{ matrix.python }}
40+
- name: Download all the dists
41+
uses: actions/download-artifact@v2
42+
with:
43+
name: python-package-distributions
44+
path: dist/
3245
- name: Integration testing
3346
run: |
34-
pip install -U pip
35-
pip install .
47+
pip install dist/proxy.py-*-py3-none-any.whl
3648
proxy \
3749
--hostname 127.0.0.1 \
3850
--enable-web-server \
3951
--pid-file proxy.pid \
4052
--log-file proxy.log \
4153
&
42-
./tests/integration/main.sh
54+
./integration-test.sh
55+
56+
build:
57+
name: build-dists
58+
59+
runs-on: Ubuntu-latest
60+
61+
env:
62+
PY_COLORS: 1
63+
TOX_PARALLEL_NO_SPINNER: 1
64+
TOXENV: cleanup-dists,build-dists
65+
66+
steps:
67+
- name: Switch to using Python v3.10
68+
uses: actions/setup-python@v2
69+
with:
70+
python-version: '3.10'
71+
- name: >-
72+
Calculate Python interpreter version hash value
73+
for use in the cache key
74+
id: calc-cache-key-py
75+
run: |
76+
from hashlib import sha512
77+
from sys import version
78+
79+
hash = sha512(version.encode()).hexdigest()
80+
print(f'::set-output name=py-hash-key::{hash}')
81+
shell: python
82+
- name: Get pip cache dir
83+
id: pip-cache
84+
run: >-
85+
echo "::set-output name=dir::$(pip cache dir)"
86+
- name: Set up pip cache
87+
uses: actions/[email protected]
88+
with:
89+
path: ${{ steps.pip-cache.outputs.dir }}
90+
key: >-
91+
${{ runner.os }}-pip-${{
92+
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
93+
hashFiles('tox.ini') }}
94+
restore-keys: |
95+
${{ runner.os }}-pip-${{
96+
steps.calc-cache-key-py.outputs.py-hash-key
97+
}}-
98+
${{ runner.os }}-pip-
99+
- name: Install tox
100+
run: >-
101+
python -m
102+
pip install
103+
--user
104+
tox
105+
106+
- name: Grab the source from Git
107+
uses: actions/checkout@v2
108+
109+
- name: Pre-populate the tox env
110+
run: >-
111+
python -m
112+
tox
113+
--parallel auto
114+
--parallel-live
115+
--skip-missing-interpreters false
116+
--notest
117+
- name: Build dists
118+
run: >-
119+
python -m
120+
tox
121+
--parallel auto
122+
--parallel-live
123+
--skip-missing-interpreters false
124+
- name: Store the distribution packages
125+
uses: actions/upload-artifact@v2
126+
with:
127+
name: python-package-distributions
128+
path: dist
129+
retention-days: 30 # Defaults to 90
43130

44131
lint:
45-
name: >-
46-
${{
47-
toJSON(matrix.custom_job_name)
48-
&& matrix.custom_job_name
49-
|| matrix.toxenv
50-
}}
132+
name: ${{ matrix.toxenv }}
133+
needs:
134+
- build
51135

52136
runs-on: Ubuntu-latest
53137
strategy:
54138
matrix:
55139
toxenv:
56140
- lint
57-
custom_job_name:
58-
- ''
59-
include:
60-
- custom_job_name: build-dists
61-
toxenv: cleanup-dists,build-dists,metadata-validation
141+
- metadata-validation
62142
fail-fast: false
63143

64144
env:
@@ -109,6 +189,19 @@ jobs:
109189
- name: Grab the source from Git
110190
uses: actions/checkout@v2
111191

192+
- name: Make the env clean of non-test files
193+
if: matrix.toxenv == 'metadata-validation'
194+
run: |
195+
shopt -s extglob
196+
rm -rf !tox.ini
197+
shell: bash
198+
- name: Download all the dists
199+
if: matrix.toxenv == 'metadata-validation'
200+
uses: actions/download-artifact@v2
201+
with:
202+
name: python-package-distributions
203+
path: dist/
204+
112205
- name: >-
113206
Pre-populate tox envs: `${{ env.TOXENV }}`
114207
run: >-
@@ -129,6 +222,8 @@ jobs:
129222
130223
test:
131224
name: 🐍${{ matrix.python }} @ ${{ matrix.os }}
225+
needs:
226+
- build
132227

133228
runs-on: ${{ matrix.os }}-latest
134229
strategy:
@@ -198,21 +293,30 @@ jobs:
198293
- name: Grab the source from Git
199294
uses: actions/checkout@v2
200295

296+
- name: Download all the dists
297+
uses: actions/download-artifact@v2
298+
with:
299+
name: python-package-distributions
300+
path: dist/
301+
201302
- name: Pre-populate the testing env
202303
run: >-
203304
python -m
204305
tox
205306
--parallel auto
206307
--parallel-live
207308
--skip-missing-interpreters false
309+
--installpkg dist/proxy.py-*-py3-none-any.whl
208310
--notest
311+
shell: bash
209312
- name: Run the testing
210313
run: >-
211314
python -m
212315
tox
213316
--parallel auto
214317
--parallel-live
215318
--skip-missing-interpreters false
319+
--skip-pkg-install
216320
- name: Upload coverage to Codecov
217321
uses: codecov/codecov-action@v2
218322
with:

0 commit comments

Comments
 (0)