|
2 | 2 |
|
3 | 3 | import os |
4 | 4 | import shlex |
| 5 | +import shutil |
5 | 6 | from argparse import ArgumentParser, BooleanOptionalAction |
6 | 7 | from glob import iglob |
7 | 8 | from pathlib import Path |
@@ -45,6 +46,29 @@ def install(session: nox.Session, *args, req: str, **kwargs): |
45 | 46 | session.install("-r", f"tests/{req}.in", *args, **kwargs) |
46 | 47 |
|
47 | 48 |
|
| 49 | +CONTAINER_ENGINES = ("podman", "docker") |
| 50 | +CHOSEN_CONTAINER_ENGINE = os.environ.get("CONTAINER_ENGINE") |
| 51 | +ACTIONLINT_IMAGE = "docker.io/rhysd/actionlint" |
| 52 | + |
| 53 | + |
| 54 | +def _get_container_engine(session: nox.Session) -> str: |
| 55 | + path: str | None = None |
| 56 | + if CHOSEN_CONTAINER_ENGINE: |
| 57 | + path = shutil.which(CHOSEN_CONTAINER_ENGINE) |
| 58 | + if not path: |
| 59 | + session.error( |
| 60 | + f"CONTAINER_ENGINE {CHOSEN_CONTAINER_ENGINE!r} does not exist!" |
| 61 | + ) |
| 62 | + return path |
| 63 | + for engine in CONTAINER_ENGINES: |
| 64 | + if path := shutil.which(engine): |
| 65 | + return path |
| 66 | + session.error( |
| 67 | + f"None of the following container engines were found: {CONTAINER_ENGINES}." |
| 68 | + f" {session.name} requires a container engine installed." |
| 69 | + ) |
| 70 | + |
| 71 | + |
48 | 72 | @nox.session |
49 | 73 | def static(session: nox.Session): |
50 | 74 | """ |
@@ -93,12 +117,35 @@ def spelling(session: nox.Session): |
93 | 117 | ) |
94 | 118 |
|
95 | 119 |
|
| 120 | +@nox.session |
| 121 | +def actionlint(session: nox.Session) -> None: |
| 122 | + """ |
| 123 | + Run actionlint to lint Github Actions workflows. |
| 124 | + The actionlint tool is run in a Podman/Docker container. |
| 125 | + """ |
| 126 | + engine = _get_container_engine(session) |
| 127 | + session.run_always(engine, "pull", ACTIONLINT_IMAGE, external=True) |
| 128 | + session.run( |
| 129 | + engine, |
| 130 | + "run", |
| 131 | + "--rm", |
| 132 | + # fmt: off |
| 133 | + "--volume", f"{Path.cwd()}:/pwd:z", |
| 134 | + "--workdir", "/pwd", |
| 135 | + # fmt: on |
| 136 | + ACTIONLINT_IMAGE, |
| 137 | + *session.posargs, |
| 138 | + external=True, |
| 139 | + ) |
| 140 | + |
| 141 | + |
96 | 142 | @nox.session |
97 | 143 | def lint(session: nox.Session): |
98 | 144 | session.notify("typing") |
99 | 145 | session.notify("static") |
100 | 146 | session.notify("formatters") |
101 | 147 | session.notify("spelling") |
| 148 | + session.notify("actionlint") |
102 | 149 |
|
103 | 150 |
|
104 | 151 | requirements_files = list( |
|
0 commit comments