Skip to content

Commit

Permalink
add sphinx v8 to CI
Browse files Browse the repository at this point in the history
reduce combinations of CI test matrix

group nox sessions' output in CI logs

skip uploading a non-existent coverage HTML report in CI job
  • Loading branch information
2bndy5 committed Jul 30, 2024
1 parent 04e1ff2 commit a20a6a4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
sphinx-version:
- "sphinx4"
- "sphinx5"
- "sphinx6"
- "sphinx7"
node-version:
- "16.x"
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -185,13 +180,14 @@ jobs:
- name: Run Python tests
env:
SPHINX_IMMATERIAL_EXTERNAL_RESOURCE_CACHE_DIR: ${{ github.workspace }}/theme_build_cache
COVERAGE_FILE: .coverage.${{ github.run_id }}.${{ github.run_attempt }}.${{ runner.os }}.${{ matrix.python-version }}.${{ matrix.sphinx-version }}
COVERAGE_FILE: .coverage.${{ github.run_id }}.${{ github.run_attempt }}.${{ runner.os }}.${{ matrix.python-version }}
PY_COLORS: 1
# `coverage run` cmd adds the working dir to python path, so no need to install pkg here
run: pipx run nox -s "tests-${{ matrix.python-version }}(${{ matrix.sphinx-version }})"
run: pipx run nox -s tests --forcecolor --python ${{ matrix.python-version }}
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.sphinx-version }}
name: coverage-data-${{ runner.os }}-py${{ matrix.python-version }}
path: .coverage*

coverage-report:
Expand All @@ -211,11 +207,6 @@ jobs:
python-version: "3.x"
- name: Create coverage report
run: pipx run nox -s coverage
- name: Upload comprehensive coverage HTML report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov/
- name: Post coverage summary
uses: codecov/codecov-action@v4
env:
Expand Down
44 changes: 34 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import os
import logging
import pathlib
import re
from typing import Optional, List
import sys
from typing import Optional, List, cast
import nox

ci_logger = logging.getLogger("CI logger")
ci_handler = logging.StreamHandler(stream=sys.stdout)
ci_handler.formatter = logging.Formatter("%(msg)s")
ci_logger.handlers.append(ci_handler)
ci_logger.propagate = False

nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = [
"ruff_format",
Expand Down Expand Up @@ -161,7 +169,7 @@ def dist(session: nox.Session, cmd: str):
session.run("pip", "install", "wheel", "setuptools_scm", "setuptools>=42")
github_output = os.environ.get("GITHUB_OUTPUT", None)
if cmd == "--version":
version: str = session.run("python", "setup.py", "--version", silent=True)
version = cast(str, session.run("python", "setup.py", "--version", silent=True))
version = version.splitlines()[-1].strip()
if github_output is not None:
with open(github_output, "a", encoding="utf-8") as output:
Expand All @@ -185,6 +193,7 @@ def dist(session: nox.Session, cmd: str):
)
def docs(session: nox.Session, builder: str):
"""Build docs."""
ci_logger.info(f"::group::Using {builder} builder")
session.run("pip", "install", "-r", "docs/requirements.txt")
session.run(
"sphinx-build",
Expand All @@ -196,35 +205,50 @@ def docs(session: nox.Session, builder: str):
"docs",
f"docs/_build/{builder}",
)
ci_logger.info("::endgroup::")


SUPPORTED_SPHINX = [4, 5, 6, 7, 8]


@nox.session(python=SUPPORTED_PY_VER)
@nox.session
@nox.parametrize(
"sphinx",
[">=4.5,<5", ">=5,<6", ">=6,<7", ">=7,<8"],
ids=["sphinx4", "sphinx5", "sphinx6", "sphinx7"],
"python,sphinx",
[
(py, sphinx)
for py in SUPPORTED_PY_VER
for sphinx in SUPPORTED_SPHINX
if (sphinx, py) != (8, "3.9") # python v3.9 support dropped in sphinx v8
],
)
def tests(session: nox.Session, sphinx: str):
def tests(session: nox.Session, sphinx: int):
"""Run unit tests and collect code coverage analysis."""
ci_logger.info(f"::group::Using sphinx v{sphinx} and python v{session.python}")
if not pathlib.Path("node_modules").exists():
session.run("npm", "install", external=True)
if not list(pathlib.Path().glob("sphinx_immaterial/*.html")):
session.run("npm", "run", "build", external=True)
session.install(f"sphinx{sphinx}")
if sphinx.endswith("<5"):
sphinx_version = "sphinx>={},<{}".format(
str(sphinx) if sphinx > 4 else "4.5", sphinx + 1
)
session.install(sphinx_version)
if sphinx < 5:
# sphinxcontrib deps that dropped support for sphinx v4.x
session.install("-r", "tests/requirements-sphinx4.txt")
session.install("-r", "tests/requirements.txt")
session.run("coverage", "run", "-m", "pytest", "-vv", "-s", "--durations=5")
# session.notify("docs") <- only calls docs(html), not dirhtml or latex builders
ci_logger.info("::endgroup::")


@nox.session
def coverage(session: nox.Session):
"""Create coverage report."""
session.install("coverage[toml]>=7.0")
session.run("coverage", "combine")
total = int(session.run("coverage", "report", "--format=total", silent=True))
total = int(
cast(str, session.run("coverage", "report", "--format=total", silent=True))
)
md = session.run("coverage", "report", "--format=markdown", silent=True)
pathlib.Path(".coverage_.md").write_text(
f"<details><summary>Coverage is {total}%</summary>\n\n{md}\n\n</details>",
Expand Down

0 comments on commit a20a6a4

Please sign in to comment.