Skip to content

Commit ee3a1db

Browse files
authored
Merge pull request #18 from Unity-Lab-AI/codex/analyze-github-pages-deployment-issue-0q1244
Inline assets to fix GitHub Pages layout
2 parents 3ca58b9 + 4e5466b commit ee3a1db

4 files changed

Lines changed: 97 additions & 33 deletions

File tree

.github/workflows/main-branch.yml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,7 @@ jobs:
3030
pip install -r requirements.txt
3131
3232
- name: Build static site bundle
33-
run: |
34-
python - <<'PY'
35-
import json
36-
import shutil
37-
import time
38-
from pathlib import Path
39-
40-
start = time.perf_counter()
41-
root = Path('.')
42-
dist = Path('dist')
43-
if dist.exists():
44-
shutil.rmtree(dist)
45-
dist.mkdir(parents=True, exist_ok=True)
46-
47-
for asset in ['index.html', 'style.css', 'app.js', 'ai-instruct.txt']:
48-
shutil.copy2(root / asset, dist / asset)
49-
50-
duration = time.perf_counter() - start
51-
report_dir = Path('ci_reports')
52-
report_dir.mkdir(parents=True, exist_ok=True)
53-
(report_dir / 'build_status.json').write_text(
54-
json.dumps(
55-
{
56-
'status': 'succeeded',
57-
'artifact': 'github-pages',
58-
'duration': duration,
59-
},
60-
indent=2,
61-
)
62-
)
63-
PY
33+
run: python scripts/build_static.py
6434

6535
- name: Upload static artifact
6636
uses: actions/upload-pages-artifact@v3

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ Two separate GitHub Actions workflows keep deployments fast and informative:
3333

3434
- **Main Branch Delivery** (`.github/workflows/main-branch.yml`)
3535
- Triggers on pushes to `main` and manual dispatches.
36-
- Builds the static bundle, uploads the GitHub Pages artifact, and records a
37-
machine-readable build summary.
36+
- Runs `scripts/build_static.py`, which inlines the CSS and JavaScript so the
37+
GitHub Pages artifact is a self-contained `index.html` (eliminating missing
38+
asset issues on the published site).
39+
- Uploads the bundle artifact and records a machine-readable build summary.
3840
- Executes the same test suite and reports results without blocking deploys.
3941
- Deploys successful builds to GitHub Pages.
4042

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Unity Voice Chat</title>
7+
<!-- build:css -->
78
<link rel="stylesheet" href="./style.css">
9+
<!-- endbuild css -->
10+
<!-- build:js -->
811
<script defer src="./app.js"></script>
12+
<!-- endbuild js -->
913
</head>
1014
<body>
1115
<div id="background" aria-hidden="true"></div>

scripts/build_static.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""Build the GitHub Pages bundle with inlined assets."""
2+
from __future__ import annotations
3+
4+
import json
5+
import shutil
6+
import time
7+
from pathlib import Path
8+
9+
ROOT = Path(__file__).resolve().parents[1]
10+
DIST = ROOT / "dist"
11+
CI_REPORTS = ROOT / "ci_reports"
12+
13+
CSS_START = "<!-- build:css -->"
14+
CSS_END = "<!-- endbuild css -->"
15+
JS_START = "<!-- build:js -->"
16+
JS_END = "<!-- endbuild js -->"
17+
18+
19+
def replace_block(source: str, start_marker: str, end_marker: str, replacement: str) -> str:
20+
"""Replace the block delimited by the provided markers.
21+
22+
Raises a ValueError when the markers are missing so the workflow fails fast
23+
instead of silently producing a broken bundle.
24+
"""
25+
26+
try:
27+
start_index = source.index(start_marker) + len(start_marker)
28+
end_index = source.index(end_marker)
29+
except ValueError as exc: # pragma: no cover - defensive guard
30+
raise ValueError(
31+
"Build markers missing in index.html. Ensure the start and end "
32+
f"markers {start_marker!r} and {end_marker!r} exist."
33+
) from exc
34+
35+
before = source[:start_index]
36+
after = source[end_index:]
37+
return f"{before}\n{replacement}\n{after}"
38+
39+
40+
def build() -> None:
41+
start = time.perf_counter()
42+
43+
if DIST.exists():
44+
shutil.rmtree(DIST)
45+
DIST.mkdir(parents=True, exist_ok=True)
46+
47+
index_html = (ROOT / "index.html").read_text(encoding="utf-8")
48+
css = (ROOT / "style.css").read_text(encoding="utf-8")
49+
javascript = (ROOT / "app.js").read_text(encoding="utf-8")
50+
51+
inlined_index = replace_block(
52+
index_html,
53+
CSS_START,
54+
CSS_END,
55+
f"<style>\n{css}\n</style>",
56+
)
57+
inlined_index = replace_block(
58+
inlined_index,
59+
JS_START,
60+
JS_END,
61+
f"<script>\n{javascript}\n</script>",
62+
)
63+
64+
(DIST / "index.html").write_text(inlined_index, encoding="utf-8")
65+
66+
# Keep the original assets alongside the inlined bundle for local debugging
67+
# and to avoid breaking any bookmarked resources.
68+
shutil.copy2(ROOT / "style.css", DIST / "style.css")
69+
shutil.copy2(ROOT / "app.js", DIST / "app.js")
70+
shutil.copy2(ROOT / "ai-instruct.txt", DIST / "ai-instruct.txt")
71+
72+
duration = time.perf_counter() - start
73+
CI_REPORTS.mkdir(parents=True, exist_ok=True)
74+
(CI_REPORTS / "build_status.json").write_text(
75+
json.dumps(
76+
{
77+
"status": "succeeded",
78+
"artifact": "github-pages",
79+
"duration": duration,
80+
},
81+
indent=2,
82+
),
83+
encoding="utf-8",
84+
)
85+
86+
87+
if __name__ == "__main__":
88+
build()

0 commit comments

Comments
 (0)