Skip to content

Commit 54e0c3e

Browse files
committed
ci: invoke Lychee directly from Bash on Linux
Signed-off-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent c4a6f69 commit 54e0c3e

2 files changed

Lines changed: 15 additions & 52 deletions

File tree

‎.github/workflows/pre-commit.yml‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,18 @@ jobs:
8787

8888
# Keep this offline hook smoke check before network-dependent Lychee steps,
8989
# so hook setup and invocation failures surface before link-check retries.
90-
- name: Smoke-test the configured Lychee hook offline (Linux)
91-
if: runner.os == 'Linux'
92-
env:
93-
PYTHONUTF8: "1"
94-
run: python ci/tools/smoke_test_lychee_precommit.py
95-
9690
# Invoke pre-commit directly to cover each shell's command lookup and quoting.
97-
# All three Windows shells reuse this offline configuration and hook environment.
98-
- name: Prepare offline Lychee configuration (Windows)
99-
if: runner.os == 'Windows'
91+
# Each runner's shells reuse one offline configuration and hook environment.
92+
- name: Prepare offline Lychee configuration
10093
id: lychee-smoke
94+
# pre-commit needs the config on the checkout's drive; spaces exercise quoting.
10195
run: |
10296
directory="$(mktemp -d 'lychee offline smoke XXXXXX')"
10397
echo "directory=$directory" >> "${GITHUB_OUTPUT}"
10498
python ci/tools/smoke_test_lychee_precommit.py --prepare "$directory"
10599
106-
- name: Smoke-test Lychee in Git Bash (Windows)
107-
if: ${{ !cancelled() && runner.os == 'Windows' && steps.lychee-smoke.outcome == 'success' }}
100+
- name: Smoke-test Lychee in ${{ runner.os == 'Windows' && 'Git Bash' || 'Bash' }}
101+
if: ${{ !cancelled() && steps.lychee-smoke.outcome == 'success' }}
108102
shell: bash
109103
env:
110104
LYCHEE_SMOKE_DIR: ${{ steps.lychee-smoke.outputs.directory }}
@@ -137,8 +131,8 @@ jobs:
137131
pre-commit run lychee --config "%LYCHEE_SMOKE_DIR%\pre-commit.yaml" --files README.md --verbose > "%LYCHEE_SMOKE_DIR%\cmd.log" 2>&1
138132
python ci/tools/smoke_test_lychee_precommit.py --verify "%LYCHEE_SMOKE_DIR%\cmd.log" %ERRORLEVEL%
139133
140-
- name: Remove offline Lychee configuration (Windows)
141-
if: ${{ always() && runner.os == 'Windows' && steps.lychee-smoke.outputs.directory != '' }}
134+
- name: Remove offline Lychee configuration
135+
if: ${{ always() && steps.lychee-smoke.outputs.directory != '' }}
142136
env:
143137
LYCHEE_SMOKE_DIR: ${{ steps.lychee-smoke.outputs.directory }}
144138
run: python ci/tools/smoke_test_lychee_precommit.py --cleanup "$LYCHEE_SMOKE_DIR"

‎ci/tools/smoke_test_lychee_precommit.py‎

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,22 @@
1212
from __future__ import annotations
1313

1414
import argparse
15-
import os
1615
import shutil
17-
import subprocess
18-
import sys
1916
from pathlib import Path
20-
from tempfile import TemporaryDirectory
2117

2218
import yaml
2319

2420
ROOT = Path(__file__).resolve().parents[2]
2521

2622

27-
def write_config(directory: Path) -> Path:
23+
def write_config(directory: Path) -> None:
2824
# Use the checked-in hook, including its entry point and pinned dependency.
2925
# PyYAML is already installed as a dependency of pre-commit.
3026
config = yaml.safe_load((ROOT / ".pre-commit-config.yaml").read_text(encoding="utf-8"))
3127
[hook] = [hook for repo in config["repos"] for hook in repo["hooks"] if hook["id"] == "lychee"]
3228
hook.setdefault("args", []).append("--offline")
3329
config_path = directory / "pre-commit.yaml"
3430
config_path.write_text(yaml.safe_dump(config), encoding="utf-8")
35-
return config_path
3631

3732

3833
def verify(output: str, exit_code: int) -> int:
@@ -43,9 +38,9 @@ def verify(output: str, exit_code: int) -> int:
4338

4439

4540
def main() -> int:
46-
# Windows CI uses separate phases so each shell invokes pre-commit directly.
41+
# CI uses separate phases so each shell invokes pre-commit directly.
4742
parser = argparse.ArgumentParser(description=__doc__)
48-
mode = parser.add_mutually_exclusive_group()
43+
mode = parser.add_mutually_exclusive_group(required=True)
4944
mode.add_argument("--prepare", type=Path, metavar="DIRECTORY")
5045
mode.add_argument("--verify", nargs=2, metavar=("LOG", "EXIT_CODE"))
5146
mode.add_argument("--cleanup", type=Path, metavar="DIRECTORY")
@@ -56,37 +51,11 @@ def main() -> int:
5651
if args.verify is not None:
5752
log, exit_code = args.verify
5853
return verify((ROOT / log).read_text(encoding="utf-8"), int(exit_code))
59-
if args.cleanup is not None:
60-
directory = (ROOT / args.cleanup).resolve()
61-
if directory.parent != ROOT or not directory.name.startswith("lychee offline smoke "):
62-
raise SystemExit("Refusing to remove a directory outside the smoke check's temporary files")
63-
shutil.rmtree(directory)
64-
return 0
65-
66-
# pre-commit resolves --config relative to the checkout; keep it on the same drive.
67-
with TemporaryDirectory(prefix="lychee offline smoke ", dir=ROOT) as directory:
68-
config_path = write_config(Path(directory))
69-
result = subprocess.run( # noqa: S603
70-
[
71-
sys.executable,
72-
"-m",
73-
"pre_commit",
74-
"run",
75-
"lychee",
76-
"--config",
77-
str(config_path),
78-
"--files",
79-
"README.md",
80-
"--verbose",
81-
],
82-
cwd=ROOT,
83-
env={**os.environ, "SKIP": "", "PYTHONUTF8": "1"},
84-
stdout=subprocess.PIPE,
85-
stderr=subprocess.STDOUT,
86-
encoding="utf-8",
87-
check=False,
88-
)
89-
return verify(result.stdout, result.returncode)
54+
directory = (ROOT / args.cleanup).resolve()
55+
if directory.parent != ROOT or not directory.name.startswith("lychee offline smoke "):
56+
raise SystemExit("Refusing to remove a directory outside the smoke check's temporary files")
57+
shutil.rmtree(directory)
58+
return 0
9059

9160

9261
if __name__ == "__main__":

0 commit comments

Comments
 (0)