Skip to content

Commit 982ec77

Browse files
committed
ci: add TechAPI homepage PR validation
1 parent 12ae7aa commit 982ec77

1 file changed

Lines changed: 51 additions & 3 deletions

File tree

.github/workflows/techapi-pr-validation-comment.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
TECHAPI_PR_URL: ${{ github.event.client_payload.pr_url || inputs.pr_url }}
4141
REQUESTED_BY: ${{ github.event.client_payload.requested_by || github.actor }}
4242
TECHAPI_DATA_DIR: ${{ github.workspace }}/TechAPI/data
43+
TECHAPI_SITE_DIR: ${{ github.workspace }}/TechAPI/site
4344
steps:
4445
- name: Checkout TechEngine
4546
uses: actions/checkout@v4
@@ -63,6 +64,12 @@ jobs:
6364
python-version: "3.12"
6465
cache: pip
6566

67+
- uses: actions/setup-node@v4
68+
with:
69+
node-version: "22"
70+
cache: npm
71+
cache-dependency-path: TechAPI/site/package-lock.json
72+
6673
- name: Install TechEngine
6774
run: pip install -e .
6875

@@ -97,6 +104,23 @@ jobs:
97104
echo "app_status=${app_status:-1}" >> "$GITHUB_OUTPUT"
98105
echo "integrity_status=${integrity_status:-1}" >> "$GITHUB_OUTPUT"
99106
107+
- name: Build TechAPI homepage
108+
id: site_build
109+
shell: bash
110+
run: |
111+
set +e
112+
site_build_log="${GITHUB_WORKSPACE}/site-build.log"
113+
{
114+
echo "## TechAPI homepage build"
115+
cd "${TECHAPI_SITE_DIR}"
116+
npm ci
117+
npm run build
118+
echo "site_build_status=$?"
119+
} > "${site_build_log}" 2>&1
120+
site_build_status=$(grep "site_build_status=" "${site_build_log}" | tail -n 1 | cut -d= -f2)
121+
sed -i '/site_build_status=/d' "${site_build_log}"
122+
echo "status=${site_build_status:-1}" >> "$GITHUB_OUTPUT"
123+
100124
- name: Build data quality summary
101125
shell: bash
102126
run: |
@@ -342,11 +366,11 @@ jobs:
342366
run: |
343367
short_sha="${TECHAPI_HEAD_SHA:0:7}"
344368
result="PASS"
345-
if [ "${{ steps.validate.outputs.status }}" != "success" ]; then
369+
if [ "${{ steps.validate.outputs.status }}" != "success" ] || [ "${{ steps.site_build.outputs.status }}" != "0" ]; then
346370
result="FAIL"
347371
fi
348372
349-
VALIDATION_STATUS="${{ steps.validate.outputs.status }}" python - <<'PY'
373+
VALIDATION_STATUS="${{ steps.validate.outputs.status }}" SITE_BUILD_STATUS="${{ steps.site_build.outputs.status }}" python - <<'PY'
350374
from __future__ import annotations
351375
352376
import os
@@ -356,6 +380,7 @@ jobs:
356380
log = log_path.read_text(encoding="utf-8", errors="replace")
357381
lines = log.splitlines()
358382
failed = os.environ.get("VALIDATION_STATUS") != "success"
383+
site_failed = os.environ.get("SITE_BUILD_STATUS") != "0"
359384
360385
section_counts: dict[str, int] = {}
361386
current_section: str | None = None
@@ -412,6 +437,28 @@ jobs:
412437
out.append("")
413438
out.append("</details>")
414439
440+
site_log_path = Path("site-build.log")
441+
site_log = site_log_path.read_text(encoding="utf-8", errors="replace") if site_log_path.exists() else ""
442+
if site_failed:
443+
out.append("")
444+
out.append("<details><summary>Detailed homepage build log excerpt</summary>")
445+
out.append("")
446+
out.append("```text")
447+
excerpt = site_log[-12000:] if len(site_log) > 12000 else site_log
448+
out.append(excerpt.rstrip())
449+
out.append("```")
450+
out.append("")
451+
out.append("</details>")
452+
elif site_log:
453+
summary = [line for line in site_log.splitlines() if "Complete!" in line or "page(s) built" in line]
454+
if summary:
455+
out.append("")
456+
out.append("Homepage build:")
457+
out.append("")
458+
out.append("```text")
459+
out.extend(summary[-4:])
460+
out.append("```")
461+
415462
Path("validation-notes.md").write_text("\n".join(out) + "\n", encoding="utf-8")
416463
PY
417464
@@ -429,6 +476,7 @@ jobs:
429476
echo "| --- | --- |"
430477
echo "| \`python -m app.validate\` | $([ "${{ steps.validate.outputs.app_status }}" = "0" ] && echo PASS || echo FAIL) |"
431478
echo "| \`python integrity_check.py TechAPI/data --strict\` | $([ "${{ steps.validate.outputs.integrity_status }}" = "0" ] && echo PASS || echo FAIL) |"
479+
echo "| \`cd TechAPI/site && npm ci && npm run build\` | $([ "${{ steps.site_build.outputs.status }}" = "0" ] && echo PASS || echo FAIL) |"
432480
echo
433481
cat change-review.md
434482
} > change-comment.md
@@ -481,5 +529,5 @@ jobs:
481529
run: echo "::warning::TECHENGINEBOT_TOKEN/TECHAPI_TOKEN is not configured; validation ran but no PR comment was posted."
482530

483531
- name: Fail on validation errors
484-
if: steps.validate.outputs.status != 'success'
532+
if: steps.validate.outputs.status != 'success' || steps.site_build.outputs.status != '0'
485533
run: exit 1

0 commit comments

Comments
 (0)