Skip to content

Commit 6178349

Browse files
committed
ci: verify the Lychee smoke check using its JSON report
Signed-off-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent 54e0c3e commit 6178349

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎.github/actions/check-doc-links/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
shell: bash --noprofile --norc -euo pipefail {0}
2626
env:
2727
KIND: ${{ inputs.kind }}
28-
LYCHEE_VERSION: v0.24.2 # Must match the pinned rev in .pre-commit-config.yaml
28+
LYCHEE_VERSION: v0.24.2 # Must match lychee-bin in .pre-commit-config.yaml
2929
POLICY_HASH: ${{ hashFiles('lychee.toml', '.github/actions/check-doc-links/action.yml', 'ci/tools/prepare_lychee_inputs.py', 'ci/tools/retry_lychee.py') }}
3030
# The first pass and all retries use the same inputs and cache policy.
3131
LYCHEE_ARGS: >-

‎ci/tools/smoke_test_lychee_precommit.py‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,36 @@
1616
from pathlib import Path
1717

1818
import yaml
19+
from retry_lychee import read_report
1920

2021
ROOT = Path(__file__).resolve().parents[2]
22+
REPORT_NAME = "lychee.json"
2123

2224

2325
def write_config(directory: Path) -> None:
2426
# Use the checked-in hook, including its entry point and pinned dependency.
2527
# PyYAML is already installed as a dependency of pre-commit.
2628
config = yaml.safe_load((ROOT / ".pre-commit-config.yaml").read_text(encoding="utf-8"))
2729
[hook] = [hook for repo in config["repos"] for hook in repo["hooks"] if hook["id"] == "lychee"]
28-
hook.setdefault("args", []).append("--offline")
30+
report = directory / REPORT_NAME
31+
hook.setdefault("args", []).extend(["--offline", "--format", "json", "--output", str(report)])
2932
config_path = directory / "pre-commit.yaml"
3033
config_path.write_text(yaml.safe_dump(config), encoding="utf-8")
3134

3235

33-
def verify(output: str, exit_code: int) -> int:
34-
print(output, end="")
35-
if exit_code == 0 and ("- hook id: lychee" not in output or "Skipped" in output):
36-
raise SystemExit("The configured Lychee hook did not run")
37-
return exit_code
36+
def verify(log: Path, exit_code: int) -> int:
37+
report = log.with_name(REPORT_NAME)
38+
try:
39+
print(log.read_text(encoding="utf-8"), end="")
40+
if exit_code != 0:
41+
return exit_code
42+
if not report.is_file():
43+
raise SystemExit(f"The configured Lychee hook produced no report ({report}); was it skipped?")
44+
read_report(report, exit_code)
45+
return 0
46+
finally:
47+
# Consume each shell's report so a later skipped hook cannot reuse it.
48+
report.unlink(missing_ok=True)
3849

3950

4051
def main() -> int:
@@ -50,7 +61,7 @@ def main() -> int:
5061
return 0
5162
if args.verify is not None:
5263
log, exit_code = args.verify
53-
return verify((ROOT / log).read_text(encoding="utf-8"), int(exit_code))
64+
return verify(ROOT / log, int(exit_code))
5465
directory = (ROOT / args.cleanup).resolve()
5566
if directory.parent != ROOT or not directory.name.startswith("lychee offline smoke "):
5667
raise SystemExit("Refusing to remove a directory outside the smoke check's temporary files")

0 commit comments

Comments
 (0)