Skip to content

Commit 9b3424b

Browse files
committed
simplify CI scripts
1 parent 7bd0449 commit 9b3424b

File tree

6 files changed

+138
-85
lines changed

6 files changed

+138
-85
lines changed

.github/workflows/test.yml

+26-53
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,29 @@ on:
1111
- cron: "0 0 * * *"
1212

1313
jobs:
14-
test-python:
14+
test-python-coverage:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v2
1818
- uses: nanasess/setup-chromedriver@master
1919
- uses: actions/setup-node@v2-beta
2020
with:
21-
node-version: "14.x"
21+
node-version: "14"
2222
- name: Use Latest Python
2323
uses: actions/setup-python@v2
2424
with:
25-
python-version: 3.9
26-
- name: Install latest NPM
27-
run: |
28-
npm install -g [email protected]
29-
npm --version
25+
python-version: "3.10"
3026
- name: Install Python Dependencies
3127
run: pip install -r requirements/test-run.txt
3228
- name: Run Tests
33-
run: nox -s test -- --headless
34-
test-python-versions:
29+
env: {"CI": "true"}
30+
run: nox -s test_python_suite -- --headless
31+
test-python-environments:
3532
runs-on: ${{ matrix.os }}
3633
strategy:
3734
matrix:
38-
python-version: [3.7, 3.8, 3.9]
39-
os: [ubuntu-latest, macos-latest, windows-latest]
35+
python-version: ["3.7", "3.8", "3.9", "3.10"]
36+
os: [macos-latest, windows-latest]
4037
steps:
4138
- uses: actions/checkout@v2
4239
- uses: nanasess/setup-chromedriver@master
@@ -47,60 +44,36 @@ jobs:
4744
uses: actions/setup-python@v2
4845
with:
4946
python-version: ${{ matrix.python-version }}
50-
- name: Install latest NPM
51-
run: |
52-
npm install -g [email protected]
53-
npm --version
5447
- name: Install Python Dependencies
5548
run: pip install -r requirements/test-run.txt
5649
- name: Run Tests
57-
run: nox -s test_short -- --headless --no-cov
58-
test-javascript:
50+
env: {"CI": "true"}
51+
run: nox -s test_python -- --headless --no-cov
52+
test-docs:
5953
runs-on: ubuntu-latest
6054
steps:
6155
- uses: actions/checkout@v2
62-
- uses: actions/setup-node@v2
56+
- uses: actions/setup-node@v2-beta
6357
with:
6458
node-version: "14"
65-
- name: Install latest NPM
66-
run: |
67-
npm install -g [email protected]
68-
npm --version
69-
- name: Test Javascript
70-
working-directory: ./src/client
71-
run: |
72-
npm install
73-
npm test
74-
npm run build
75-
test-documentation-image:
76-
runs-on: ubuntu-latest
77-
steps:
78-
- name: Check out src from Git
79-
uses: actions/checkout@v2
80-
- name: Get history and tags for SCM versioning to work
81-
run: |
82-
git fetch --prune --unshallow
83-
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
84-
- name: Build Docker Image
85-
run: docker build . --file docs/Dockerfile
86-
test-build-package:
59+
- name: Use Latest Python
60+
uses: actions/setup-python@v2
61+
with:
62+
python-version: "3.9"
63+
- name: Install Python Dependencies
64+
run: pip install -r requirements/test-run.txt
65+
- name: Run Tests
66+
env: {"CI": "true"}
67+
run: nox -s test_docs
68+
test-javascript:
8769
runs-on: ubuntu-latest
8870
steps:
8971
- uses: actions/checkout@v2
9072
- uses: actions/setup-node@v2-beta
9173
with:
9274
node-version: "14"
93-
- name: Use Latest Python
94-
uses: actions/setup-python@v2
95-
with:
96-
python-version: 3.9
97-
- name: Install latest NPM
98-
run: |
99-
npm install -g [email protected]
100-
npm --version
10175
- name: Install Python Dependencies
102-
run: |
103-
pip install --upgrade pip
104-
pip install -r requirements/build-pkg.txt
105-
- name: Test Build Creation
106-
run: python setup.py bdist_wheel sdist
76+
run: pip install -r requirements/test-run.txt
77+
- name: Run Tests
78+
env: {"CI": "true"}
79+
run: nox -s test_javascript

docs/source/developing-idom/contributor-guide.rst

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ In order to develop IDOM locally you'll first need to install the following:
9494
* - NPM >= 7.13
9595
- https://docs.npmjs.com/try-the-latest-stable-version-of-npm
9696

97+
* - Docker
98+
- https://docs.docker.com/get-docker/
99+
97100
.. note::
98101

99102
NodeJS distributes a version of NPM, but you'll want to get the latest

noxfile.py

+105-31
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import re
66
from pathlib import Path
7-
from typing import Any, Callable
7+
from typing import Any, Callable, TypeVar
88

99
import nox
1010
from nox.sessions import Session
@@ -13,22 +13,56 @@
1313
ROOT = Path(__file__).parent
1414
SRC = ROOT / "src"
1515
POSARGS_PATTERN = re.compile(r"^(\w+)\[(.+)\]$")
16+
TRUE_VALUES = {"true", "True", "TRUE", "1"}
1617

1718

18-
def apply_standard_pip_upgrades(
19-
function: Callable[[Session], Any]
20-
) -> Callable[[Session], Any]:
21-
@functools.wraps(function)
22-
def wrapper(session: Session) -> None:
23-
session.install("--upgrade", "pip", "setuptools", "wheel")
24-
return function(session)
19+
_Return = TypeVar("_Return")
2520

26-
return wrapper
21+
22+
def do_first(
23+
first_session_func: Callable[[Session], None]
24+
) -> Callable[[Callable[[Session], _Return]], Callable[[Session], _Return]]:
25+
"""Decorator for functions defining session actions that should happen first
26+
27+
>>> @do_first
28+
>>> def setup(session):
29+
>>> ... # do some setup
30+
>>>
31+
>>> @setup
32+
>>> def the_actual_session(session):
33+
>>> ... # so actual work
34+
35+
This makes it quick an easy to define common setup actions.
36+
"""
37+
38+
def setup(
39+
second_session_func: Callable[[Session], _Return]
40+
) -> Callable[[Session], _Return]:
41+
@functools.wraps(second_session_func)
42+
def wrapper(session: Session) -> Any:
43+
first_session_func(session)
44+
return second_session_func(session)
45+
46+
return wrapper
47+
48+
return setup
49+
50+
51+
@do_first
52+
def apply_standard_pip_upgrades(session: Session) -> None:
53+
session.install("--upgrade", "pip")
54+
55+
56+
@do_first
57+
def install_latest_npm_in_ci(session: Session) -> None:
58+
if os.environ.get("CI") in TRUE_VALUES:
59+
session.run("npm", "install", "-g", "npm@latest")
2760

2861

2962
@nox.session(reuse_venv=True)
3063
@apply_standard_pip_upgrades
3164
def format(session: Session) -> None:
65+
"""Auto format Python and Javascript code"""
3266
# format Python
3367
install_requirements_file(session, "check-style")
3468
session.run("black", ".")
@@ -58,6 +92,7 @@ def example(session: Session) -> None:
5892

5993

6094
@nox.session(reuse_venv=True)
95+
@install_latest_npm_in_ci
6196
@apply_standard_pip_upgrades
6297
def docs(session: Session) -> None:
6398
"""Build and display documentation in the browser (automatically reloads on change)"""
@@ -115,23 +150,31 @@ def docs_in_docker(session: Session) -> None:
115150
def test(session: Session) -> None:
116151
"""Run the complete test suite"""
117152
session.notify("test_python", posargs=session.posargs)
118-
session.notify("test_types")
119-
session.notify("test_style")
120153
session.notify("test_docs")
121154
session.notify("test_javascript")
122155

123156

124157
@nox.session
125-
def test_short(session: Session) -> None:
126-
"""Run a shortened version of the test suite"""
127-
session.notify("test_python", posargs=session.posargs)
128-
session.notify("test_docs")
129-
session.notify("test_javascript")
158+
def test_python(session: Session) -> None:
159+
"""Run all Python checks"""
160+
session.notify("test_python_suite", posargs=session.posargs)
161+
session.notify("test_python_types")
162+
session.notify("test_python_style")
163+
session.notify("test_python_build")
164+
165+
166+
@nox.session
167+
def test_javascript(session: Session) -> None:
168+
"""Run all Javascript checks"""
169+
session.notify("test_javascript_suite")
170+
session.notify("test_javascript_build")
171+
session.notify("test_javascript_style")
130172

131173

132174
@nox.session
175+
@install_latest_npm_in_ci
133176
@apply_standard_pip_upgrades
134-
def test_python(session: Session) -> None:
177+
def test_python_suite(session: Session) -> None:
135178
"""Run the Python-based test suite"""
136179
session.env["IDOM_DEBUG_MODE"] = "1"
137180
install_requirements_file(session, "test-env")
@@ -149,8 +192,8 @@ def test_python(session: Session) -> None:
149192

150193
@nox.session
151194
@apply_standard_pip_upgrades
152-
def test_types(session: Session) -> None:
153-
"""Perform a static type analysis of the codebase"""
195+
def test_python_types(session: Session) -> None:
196+
"""Perform a static type analysis of the Python codebase"""
154197
install_requirements_file(session, "check-types")
155198
install_requirements_file(session, "pkg-deps")
156199
install_requirements_file(session, "pkg-extras")
@@ -159,8 +202,8 @@ def test_types(session: Session) -> None:
159202

160203
@nox.session
161204
@apply_standard_pip_upgrades
162-
def test_style(session: Session) -> None:
163-
"""Check that style guidelines are being followed"""
205+
def test_python_style(session: Session) -> None:
206+
"""Check that Python style guidelines are being followed"""
164207
install_requirements_file(session, "check-style")
165208
session.run("flake8", "src/idom", "tests", "docs")
166209
black_default_exclude = r"\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|\.svn|_build|buck-out|build|dist"
@@ -176,6 +219,15 @@ def test_style(session: Session) -> None:
176219

177220
@nox.session
178221
@apply_standard_pip_upgrades
222+
def test_python_build(session: Session) -> None:
223+
"""Test whether the Python package can be build for distribution"""
224+
install_requirements_file(session, "build-pkg")
225+
session.run("python", "setup.py", "bdist_wheel", "sdist")
226+
227+
228+
@nox.session
229+
@install_latest_npm_in_ci
230+
@apply_standard_pip_upgrades
179231
def test_docs(session: Session) -> None:
180232
"""Verify that the docs build and that doctests pass"""
181233
install_requirements_file(session, "build-docs")
@@ -192,19 +244,47 @@ def test_docs(session: Session) -> None:
192244
"docs/build",
193245
)
194246
session.run("sphinx-build", "-b", "doctest", "docs/source", "docs/build")
247+
# ensure docker image build works too
248+
session.run("docker", "build", ".", "--file", "docs/Dockerfile", external=True)
195249

196250

197-
@nox.session
198-
def test_javascript(session: Session) -> None:
199-
"""Run the Javascript-based test suite and ensure it bundles succesfully"""
251+
@do_first
252+
@install_latest_npm_in_ci
253+
def setup_client_env(session: Session) -> None:
200254
session.chdir(SRC / "client")
201255
session.run("npm", "install", external=True)
256+
257+
258+
@nox.session
259+
@setup_client_env
260+
def test_javascript_suite(session: Session) -> None:
261+
"""Run the Javascript-based test suite and ensure it bundles succesfully"""
262+
session.run("npm", "run", "test", external=True)
263+
264+
265+
@nox.session
266+
@setup_client_env
267+
def test_javascript_build(session: Session) -> None:
268+
"""Run the Javascript-based test suite and ensure it bundles succesfully"""
202269
session.run("npm", "run", "test", external=True)
270+
271+
272+
@nox.session
273+
@setup_client_env
274+
def test_javascript_style(session: Session) -> None:
275+
"""Check that Javascript style guidelines are being followed"""
276+
session.run("npm", "run", "check-format", external=True)
277+
278+
279+
@nox.session
280+
def build_js(session: Session) -> None:
281+
"""Build javascript client code"""
282+
session.chdir(SRC / "client")
203283
session.run("npm", "run", "build", external=True)
204284

205285

206286
@nox.session
207-
def tag(session: Session):
287+
def tag(session: Session) -> None:
208288
"""Create a new git tag"""
209289
try:
210290
session.run(
@@ -265,12 +345,6 @@ def update_version(session: Session) -> None:
265345
session.install("-e", ".")
266346

267347

268-
@nox.session
269-
def build_js(session: Session) -> None:
270-
session.chdir(SRC / "client")
271-
session.run("npm", "run", "build", external=True)
272-
273-
274348
@nox.session(reuse_venv=True)
275349
def latest_pull_requests(session: Session) -> None:
276350
"""A basic script for outputing changelog info"""

src/client/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"build": "snowpack build",
1313
"format": "npm --workspaces run format",
1414
"publish": "npm --workspaces publish",
15-
"test": "npm --workspaces test"
15+
"test": "npm --workspaces test",
16+
"check-format": "npm --workspaces run check-format"
1617
},
1718
"version": "0.33.3",
1819
"workspaces": [

src/client/packages/idom-app-react/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"scripts": {
2020
"format": "prettier --write ./src",
21+
"check-format": "prettier --check ./src",
2122
"test": "echo 'no tests'"
2223
},
2324
"version": "0.33.3"

src/client/packages/idom-client-react/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"scripts": {
2828
"format": "prettier --write ./src",
29+
"check-format": "prettier --check ./src",
2930
"test": "uvu tests"
3031
},
3132
"type": "module",

0 commit comments

Comments
 (0)