Skip to content

Commit c91cd5d

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

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

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

Lines changed: 50 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,22 @@ 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+
{
113+
echo "## TechAPI homepage build"
114+
cd "${TECHAPI_SITE_DIR}"
115+
npm ci
116+
npm run build
117+
echo "site_build_status=$?"
118+
} > site-build.log 2>&1
119+
site_build_status=$(grep "site_build_status=" site-build.log | tail -n 1 | cut -d= -f2)
120+
sed -i '/site_build_status=/d' site-build.log
121+
echo "status=${site_build_status:-1}" >> "$GITHUB_OUTPUT"
122+
100123
- name: Build data quality summary
101124
shell: bash
102125
run: |
@@ -342,11 +365,11 @@ jobs:
342365
run: |
343366
short_sha="${TECHAPI_HEAD_SHA:0:7}"
344367
result="PASS"
345-
if [ "${{ steps.validate.outputs.status }}" != "success" ]; then
368+
if [ "${{ steps.validate.outputs.status }}" != "success" ] || [ "${{ steps.site_build.outputs.status }}" != "0" ]; then
346369
result="FAIL"
347370
fi
348371
349-
VALIDATION_STATUS="${{ steps.validate.outputs.status }}" python - <<'PY'
372+
VALIDATION_STATUS="${{ steps.validate.outputs.status }}" SITE_BUILD_STATUS="${{ steps.site_build.outputs.status }}" python - <<'PY'
350373
from __future__ import annotations
351374
352375
import os
@@ -356,6 +379,7 @@ jobs:
356379
log = log_path.read_text(encoding="utf-8", errors="replace")
357380
lines = log.splitlines()
358381
failed = os.environ.get("VALIDATION_STATUS") != "success"
382+
site_failed = os.environ.get("SITE_BUILD_STATUS") != "0"
359383
360384
section_counts: dict[str, int] = {}
361385
current_section: str | None = None
@@ -412,6 +436,28 @@ jobs:
412436
out.append("")
413437
out.append("</details>")
414438
439+
site_log_path = Path("site-build.log")
440+
site_log = site_log_path.read_text(encoding="utf-8", errors="replace") if site_log_path.exists() else ""
441+
if site_failed:
442+
out.append("")
443+
out.append("<details><summary>Detailed homepage build log excerpt</summary>")
444+
out.append("")
445+
out.append("```text")
446+
excerpt = site_log[-12000:] if len(site_log) > 12000 else site_log
447+
out.append(excerpt.rstrip())
448+
out.append("```")
449+
out.append("")
450+
out.append("</details>")
451+
elif site_log:
452+
summary = [line for line in site_log.splitlines() if "Complete!" in line or "page(s) built" in line]
453+
if summary:
454+
out.append("")
455+
out.append("Homepage build:")
456+
out.append("")
457+
out.append("```text")
458+
out.extend(summary[-4:])
459+
out.append("```")
460+
415461
Path("validation-notes.md").write_text("\n".join(out) + "\n", encoding="utf-8")
416462
PY
417463
@@ -429,6 +475,7 @@ jobs:
429475
echo "| --- | --- |"
430476
echo "| \`python -m app.validate\` | $([ "${{ steps.validate.outputs.app_status }}" = "0" ] && echo PASS || echo FAIL) |"
431477
echo "| \`python integrity_check.py TechAPI/data --strict\` | $([ "${{ steps.validate.outputs.integrity_status }}" = "0" ] && echo PASS || echo FAIL) |"
478+
echo "| \`cd TechAPI/site && npm ci && npm run build\` | $([ "${{ steps.site_build.outputs.status }}" = "0" ] && echo PASS || echo FAIL) |"
432479
echo
433480
cat change-review.md
434481
} > change-comment.md
@@ -481,5 +528,5 @@ jobs:
481528
run: echo "::warning::TECHENGINEBOT_TOKEN/TECHAPI_TOKEN is not configured; validation ran but no PR comment was posted."
482529

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

0 commit comments

Comments
 (0)