Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/actions/setup-python-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Setup Python and Playwright

inputs:
python-version:
description: Python version to install
required: false
default: '3.11'

runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}

- name: Install Python dependencies
shell: bash
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then
python -m pip install -r requirements.txt
fi

- name: Install Playwright browsers
shell: bash
run: |
python -m playwright install --with-deps chromium
61 changes: 61 additions & 0 deletions .github/scripts/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
from __future__ import annotations

import json
import subprocess
import sys
from pathlib import Path


def truncate(text: str, limit: int = 4000) -> str:
if len(text) <= limit:
return text
return text[: limit - 3] + "..."


def run_pytest() -> dict[str, object]:
cmd = [sys.executable, "-m", "pytest", "tests"]
process = subprocess.run(cmd, capture_output=True, text=True)

stdout = process.stdout.strip()
stderr = process.stderr.strip()

result: dict[str, object] = {
"status": "success" if process.returncode == 0 else "failure",
"exit_code": process.returncode,
"command": " ".join(cmd),
"stdout": truncate(stdout),
"stderr": truncate(stderr),
}

summary_line = ""
for line in reversed(stdout.splitlines()):
if line.startswith("=") and line.endswith("="):
summary_line = line.strip("=").strip()
break
if any(token in line for token in ("passed", "failed", "error", "skipped")):
summary_line = line.strip()
break
if summary_line:
result["summary"] = summary_line

if result["status"] == "failure":
result.setdefault("message", "Pytest exited with a non-zero status code.")
print("::error::Pytest failed")

if stdout:
print(stdout)
if stderr:
print(stderr, file=sys.stderr)

return result


def main() -> int:
result = run_pytest()
Path("test-results.json").write_text(json.dumps(result))
return int(result.get("exit_code", 0))


if __name__ == "__main__":
raise SystemExit(main())
65 changes: 65 additions & 0 deletions .github/scripts/write_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import json
import os
from pathlib import Path
from typing import Any


def load_result(path: Path) -> dict[str, Any] | None:
if not path.exists():
return None
try:
return json.loads(path.read_text())
except json.JSONDecodeError:
return {"status": "unknown", "message": f"Unable to parse {path.name}."}


def format_section(title: str, data: dict[str, Any]) -> str:
status = str(data.get("status", "unknown")).title()
lines = [f"### {title}", "", f"- Status: **{status}**"]

message = data.get("message") or data.get("summary")
if message:
lines.append(f"- Details: {message}")

exit_code = data.get("exit_code")
if exit_code is not None:
lines.append(f"- Exit code: `{exit_code}`")

return "\n".join(lines)


def main() -> int:
parser = argparse.ArgumentParser(description="Write a workflow summary.")
parser.add_argument("--include-build", action="store_true", help="Include build results")
parser.add_argument("--include-tests", action="store_true", help="Include test results")
args = parser.parse_args()

summary_sections: list[str] = []
if args.include_build:
data = load_result(Path("build-results.json"))
if data:
summary_sections.append(format_section("Static site build", data))
if args.include_tests:
data = load_result(Path("test-results.json"))
if data:
summary_sections.append(format_section("Test suite", data))

if not summary_sections:
return 0

summary_content = "\n\n".join(summary_sections) + "\n"

summary_file = os.environ.get("GITHUB_STEP_SUMMARY")
if summary_file:
Path(summary_file).write_text(summary_content)
else:
print(summary_content)
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading