Skip to content

Commit ee8818b

Browse files
committed
build: cache python dependencies for tests
1 parent 2de0e5d commit ee8818b

File tree

9 files changed

+178
-38
lines changed

9 files changed

+178
-38
lines changed

.github/workflows/build.yml

Lines changed: 93 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,29 @@ jobs:
3838
runs-on: ubuntu-22.04
3939
steps:
4040
- uses: actions/checkout@v3
41-
with:
42-
submodules: true
4341

4442
- uses: actions/setup-python@v4
4543
with:
46-
python-version: 3.7
44+
python-version: 3.11
45+
cache: 'pip'
46+
cache-dependency-path: '**/requirements-*.txt'
4747

4848
- name: Start background server
4949
run: |
50-
python -m pip install flask
50+
python -m pip install -r ./css-inline/tests/requirements-test.txt
5151
# Starts the server in background
5252
python ./css-inline/tests/server.py &
53+
5354
- uses: actions-rs/toolchain@v1
5455
with:
5556
profile: minimal
5657
toolchain: stable
5758
override: true
59+
60+
- uses: Swatinem/rust-cache@v2
61+
with:
62+
workspaces: css-inline
63+
5864
- run: cargo test --no-fail-fast
5965
working-directory: ./css-inline
6066

@@ -63,12 +69,14 @@ jobs:
6369
runs-on: ubuntu-22.04
6470
steps:
6571
- uses: actions/checkout@v3
72+
6673
- uses: actions-rs/toolchain@v1
6774
with:
6875
profile: minimal
6976
toolchain: stable
7077
override: true
7178
components: rustfmt
79+
7280
- run: cargo fmt --all -- --check
7381
working-directory: ./css-inline
7482

@@ -77,15 +85,33 @@ jobs:
7785
runs-on: ubuntu-22.04
7886
steps:
7987
- uses: actions/checkout@v3
88+
8089
- uses: actions-rs/toolchain@v1
8190
with:
8291
profile: minimal
8392
toolchain: stable
8493
override: true
8594
components: clippy
86-
- run: cargo clippy -- -D warnings
95+
96+
- uses: Swatinem/rust-cache@v2
97+
with:
98+
workspaces: |
99+
css-inline
100+
bindings/python
101+
bindings/wasm
102+
103+
- name: Rust
104+
run: cargo clippy -- -D warnings
87105
working-directory: ./css-inline
88106

107+
- name: Python
108+
run: cargo clippy -- -D warnings
109+
working-directory: ./bindings/python
110+
111+
- name: WASM
112+
run: cargo clippy -- -D warnings
113+
working-directory: ./bindings/wasm
114+
89115
msrv:
90116
name: MSRV
91117
runs-on: ubuntu-22.04
@@ -96,35 +122,45 @@ jobs:
96122
profile: minimal
97123
toolchain: "1.60"
98124
override: true
125+
- uses: Swatinem/rust-cache@v2
126+
with:
127+
workspaces: css-inline
99128
- run: cargo build
100129
working-directory: ./css-inline
101130

102131
test-python:
103132
strategy:
104133
fail-fast: false
105134
matrix:
106-
os: [ubuntu-22.04, macos-11, windows-2019]
135+
os: [ubuntu-22.04, macos-12, windows-2022]
107136
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
108137

109138
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
110139
runs-on: ${{ matrix.os }}
111140
steps:
112141
- uses: actions/checkout@v3
142+
143+
- uses: actions-rs/toolchain@v1
144+
with:
145+
profile: minimal
146+
toolchain: stable
147+
override: true
148+
149+
- uses: Swatinem/rust-cache@v2
113150
with:
114-
submodules: true
151+
workspaces: bindings/python
152+
key: ${{ matrix.os }}-${{ matrix.python-version }}
153+
115154
- uses: actions/setup-python@v4
116155
with:
117156
python-version: ${{ matrix.python-version }}
118157
architecture: x64
158+
cache: 'pip'
159+
cache-dependency-path: '**/requirements-*.txt'
119160

120-
- run: python -m pip install tox
161+
- run: python -m pip install -r requirements-dev.txt
121162
working-directory: ./bindings/python
122163

123-
- uses: actions-rs/toolchain@v1
124-
with:
125-
toolchain: stable
126-
override: true
127-
128164
- name: Run ${{ matrix.python }} tox job
129165
run: tox -e py
130166
working-directory: ./bindings/python
@@ -134,18 +170,24 @@ jobs:
134170
runs-on: ubuntu-22.04
135171
steps:
136172
- uses: actions/checkout@v3
137-
with:
138-
submodules: true
173+
139174
- uses: actions-rs/toolchain@v1
140175
with:
141176
profile: minimal
142177
toolchain: stable
143178
override: true
179+
180+
- uses: Swatinem/rust-cache@v2
181+
with:
182+
workspaces: bindings/wasm
183+
cache-all-crates: "true"
184+
144185
- name: Install wasm-pack
145186
uses: actions-rs/cargo@v1
146187
with:
147188
command: install
148189
args: wasm-pack
190+
149191
- name: Run tests
150192
run: wasm-pack test --node --release
151193
working-directory: ./bindings/wasm
@@ -155,24 +197,34 @@ jobs:
155197
runs-on: ubuntu-22.04
156198
steps:
157199
- uses: actions/checkout@v3
158-
with:
159-
submodules: true
200+
160201
- uses: actions-rs/toolchain@v1
161202
with:
162203
profile: minimal
163204
toolchain: stable
164205
override: true
206+
207+
- uses: Swatinem/rust-cache@v2
208+
with:
209+
workspaces: |
210+
css-inline
211+
bindings/wasm
212+
cache-all-crates: "true"
213+
165214
- name: Install wasm-pack
166215
uses: actions-rs/cargo@v1
167216
with:
168217
command: install
169218
args: wasm-pack
219+
170220
- name: Build package
171221
run: wasm-pack build -t nodejs
172222
working-directory: ./bindings/wasm
223+
173224
- name: Install dependencies
174225
run: npm install
175226
working-directory: ./bindings/wasm
227+
176228
- name: Run tests
177229
run: npm run test
178230
working-directory: ./bindings/wasm
@@ -182,14 +234,20 @@ jobs:
182234
runs-on: ubuntu-22.04
183235
steps:
184236
- uses: actions/checkout@v3
185-
with:
186-
submodules: true
237+
187238
- uses: actions-rs/toolchain@v1
188239
with:
189240
profile: minimal
190241
toolchain: stable
191242
override: true
243+
244+
- uses: Swatinem/rust-cache@v2
245+
with:
246+
workspaces: css-inline
247+
cache-all-crates: "true"
248+
192249
- uses: taiki-e/install-action@cargo-hack
250+
193251
- run: cargo hack check --feature-powerset --lib
194252
working-directory: ./css-inline
195253

@@ -198,23 +256,17 @@ jobs:
198256
runs-on: ubuntu-22.04
199257
steps:
200258
- uses: actions/checkout@v3
201-
with:
202-
submodules: true
203259

204260
- uses: actions-rs/toolchain@v1
205261
with:
206262
profile: minimal
207263
toolchain: stable
208264
override: true
209265

210-
- name: Cache cargo
211-
uses: actions/cache@v3
266+
- uses: Swatinem/rust-cache@v2
212267
with:
213-
path: |
214-
~/.cargo/registry
215-
~/.cargo/git
216-
target
217-
key: coverage-cargo-cache
268+
workspaces: css-inline
269+
cache-all-crates: "true"
218270

219271
- name: Install cargo-llvm-cov
220272
uses: taiki-e/install-action@cargo-llvm-cov
@@ -223,16 +275,18 @@ jobs:
223275

224276
- uses: actions/setup-python@v4
225277
with:
226-
python-version: 3.7
278+
python-version: 3.11
279+
cache: 'pip'
280+
cache-dependency-path: '**/requirements-*.txt'
227281

228282
- name: Start background server
229283
run: |
230-
python -m pip install flask
284+
python -m pip install -r ./css-inline/tests/requirements-test.txt
231285
# Starts the server in background
232286
python ./css-inline/tests/server.py &
233287
234288
- name: Run tests
235-
run: cargo hack llvm-cov --no-report
289+
run: cargo hack llvm-cov --no-report --feature-powerset
236290
working-directory: ./css-inline
237291

238292
- name: Generate coverage reports
@@ -253,7 +307,15 @@ jobs:
253307
runs-on: ubuntu-22.04
254308
steps:
255309
- uses: actions/checkout@v3
310+
256311
- uses: dtolnay/rust-toolchain@nightly
312+
313+
- uses: Swatinem/rust-cache@v2
314+
with:
315+
workspaces: css-inline
316+
cache-all-crates: "true"
317+
257318
- run: cargo install cargo-fuzz
319+
258320
- run: cargo fuzz run inline -- -max_total_time=60
259321
working-directory: ./css-inline

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.3.0
6+
rev: v4.4.0
77
hooks:
88
- id: check-yaml
99
- id: end-of-file-fixer
@@ -14,17 +14,17 @@ repos:
1414
- id: check-merge-conflict
1515

1616
- repo: https://github.com/jorisroovers/gitlint
17-
rev: v0.17.0
17+
rev: v0.19.1
1818
hooks:
1919
- id: gitlint
2020

2121
- repo: https://github.com/adrienverge/yamllint
22-
rev: v1.28.0
22+
rev: v1.32.0
2323
hooks:
2424
- id: yamllint
2525

2626
- repo: https://github.com/ambv/black
27-
rev: 22.10.0
27+
rev: 23.3.0
2828
hooks:
2929
- id: black
3030
types: [python]

bindings/python/requirements-dev.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tox

bindings/python/requirements-dev.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --resolver=backtracking requirements-dev.in
6+
#
7+
cachetools==5.3.1
8+
# via tox
9+
chardet==5.1.0
10+
# via tox
11+
colorama==0.4.6
12+
# via tox
13+
distlib==0.3.6
14+
# via virtualenv
15+
filelock==3.12.2
16+
# via
17+
# tox
18+
# virtualenv
19+
packaging==23.1
20+
# via
21+
# pyproject-api
22+
# tox
23+
platformdirs==3.5.3
24+
# via
25+
# tox
26+
# virtualenv
27+
pluggy==1.0.0
28+
# via tox
29+
pyproject-api==1.5.2
30+
# via tox
31+
tox==4.6.0
32+
# via -r requirements-dev.in
33+
virtualenv==20.23.0
34+
# via tox

bindings/python/requirements-test.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest
2+
hypothesis

bindings/python/requirements-test.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# pip-compile --resolver=backtracking requirements-test.in
6+
#
7+
attrs==23.1.0
8+
# via hypothesis
9+
hypothesis==6.78.2
10+
# via -r requirements-test.in
11+
iniconfig==2.0.0
12+
# via pytest
13+
packaging==23.1
14+
# via pytest
15+
pluggy==1.0.0
16+
# via pytest
17+
pytest==7.3.2
18+
# via -r requirements-test.in
19+
sortedcontainers==2.4.0
20+
# via hypothesis

bindings/python/tox.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ skipsdist = True
33
envlist = py{37,38,39,310,311}
44

55
[testenv]
6-
deps =
7-
pytest
8-
hypothesis
6+
deps = -rrequirements-test.txt
97
commands =
108
pip install .
119
python -m pytest tests-py {posargs:}

css-inline/tests/requirements-test.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

0 commit comments

Comments
 (0)