-
Notifications
You must be signed in to change notification settings - Fork 14
415 lines (343 loc) · 14.4 KB
/
LuaGenerator.yml
File metadata and controls
415 lines (343 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
name: LuaGenerator Checks
on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- "LuaGenerator/**"
- "ProxyStubGenerator/**"
- ".github/workflows/LuaGenerator.yml"
- ".github/workflows/ProxyStubGenerator.yml"
pull_request:
branches: [ master ]
paths:
- "LuaGenerator/**"
- "ProxyStubGenerator/**"
- ".github/workflows/LuaGenerator.yml"
- ".github/workflows/ProxyStubGenerator.yml"
permissions:
contents: write
pull-requests: write
models: read
concurrency:
group: luagenerator-previews-${{ github.head_ref || github.ref }}
cancel-in-progress: false
jobs:
changes:
runs-on: ubuntu-latest
outputs:
relevant: ${{ steps.check.outputs.relevant }}
steps:
- id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "${{ github.event_name }}" != "pull_request" || "${{ github.event.action }}" != "synchronize" ]]; then
echo "relevant=true" >> "$GITHUB_OUTPUT"
exit 0
fi
relevant=$(gh api \
"repos/${{ github.repository }}/compare/${{ github.event.before }}...${{ github.event.after }}" \
--jq '[.files[].filename] | map(select(startswith("LuaGenerator/") or startswith("ProxyStubGenerator/") or . == ".github/workflows/LuaGenerator.yml" or . == ".github/workflows/ProxyStubGenerator.yml")) | length > 0')
echo "relevant=$relevant" >> "$GITHUB_OUTPUT"
generate_lua:
needs: [changes]
if: needs.changes.outputs.relevant == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout ThunderTools
uses: actions/checkout@v4
with:
path: ThunderTools
- name: Checkout Thunder
uses: actions/checkout@v4
with:
repository: rdkcentral/Thunder
path: Thunder
- name: Checkout ThunderInterfaces
uses: actions/checkout@v4
with:
repository: rdkcentral/ThunderInterfaces
path: ThunderInterfaces
- name: Run LuaGenerator
shell: bash
run: |
set -euo pipefail
# The script expects to run relative to its location or with dependencies nearby
cd ThunderTools/LuaGenerator
# Make sure script is executable
chmod +x GenerateLua.sh
echo "Running GenerateLua.sh..."
./GenerateLua.sh
# Verify output exists
if [[ ! -f "protocol-thunder-comrpc.data" ]]; then
echo "::error::Output file 'protocol-thunder-comrpc.data' was not created!"
ls -la
exit 1
fi
echo "Generation successful."
- name: Prepare Artifacts
shell: bash
run: |
mkdir -p generated_lua
mv ThunderTools/LuaGenerator/protocol-thunder-comrpc.data generated_lua/
- name: Upload Generated Lua Data
uses: actions/upload-artifact@v4
with:
name: LuaGenerator-Output
path: generated_lua/
retention-days: 1
publish_pages:
runs-on: ubuntu-latest
concurrency:
group: gh-pages-deploy
cancel-in-progress: false
needs: generate_lua
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: LuaGenerator-Output
path: generated
- name: Checkout gh-pages (baseline)
if: github.event_name == 'pull_request'
continue-on-error: true
uses: actions/checkout@v4
with:
ref: gh-pages
path: ghpages_baseline
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Build static preview site
id: build_site
shell: bash
env:
TOOL_NAME: "LuaGenerator"
run: |
set -euo pipefail
HAS_DIFF="false"
mkdir -p site
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_DIR="previews/pr-${{ github.event.pull_request.number }}"
else
BASE_DIR="master"
fi
RUN_DIR="${BASE_DIR}/run-${{ github.run_id }}"
# ----- Save for future steps -----
echo "RUN_DIR=$RUN_DIR" >> "$GITHUB_ENV"
# ----- Export for current step -----
export RUN_DIR
export HAS_DIFF
mkdir -p "site/$RUN_DIR"
touch site/.nojekyll
# ----- PR-only: diff vs gh-pages baseline -----
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASELINE_ROOT="${PWD}/ghpages_baseline/${TOOL_NAME}/master/latest_raw"
mkdir -p diffs "site/$RUN_DIR/diff"
if [[ -d "$BASELINE_ROOT" ]]; then
git diff --no-index -U5 \
--src-prefix=baseline/ \
--dst-prefix=generated/ \
-- "$BASELINE_ROOT" "generated" \
> "diffs/combined.diff" || true
else
mkdir empty_dir
git diff --no-index -U5 \
--src-prefix=baseline/ \
--dst-prefix=generated/ \
-- "empty_dir" "generated" \
> "diffs/combined.diff" || true
fi
if [[ -s "diffs/combined.diff" ]]; then
HAS_DIFF="true"
export HAS_DIFF
npx --yes diff2html-cli@5.2.15 -i file -F "site/$RUN_DIR/diff/index.html" -- "diffs/combined.diff"
head -c 50000 diffs/combined.diff > diffs/combined_trunc.diff
else
mkdir -p "site/$RUN_DIR/diff"
echo "<h1>No changes detected</h1>" > "site/$RUN_DIR/diff/index.html"
fi
fi
echo "has_diff=$HAS_DIFF" >> "$GITHUB_OUTPUT"
# ----- Copy files for browsing -----
mkdir -p "site/$RUN_DIR/browse"
cp -r generated/* "site/$RUN_DIR/browse/"
# ----- Generate Site with Python -----
RUN_DIR="$RUN_DIR" HAS_DIFF="$HAS_DIFF" python - <<'PY'
import os
from pathlib import Path
import html
run_dir = os.environ["RUN_DIR"]
has_diff = os.environ.get("HAS_DIFF") == "true"
site_root = Path("site") / run_dir
browse_root = site_root / "browse"
# ----- Generate Dark Theme CSS -----
css_path = site_root / "assets" / "style.css"
css_path.parent.mkdir(parents=True, exist_ok=True)
css_path.write_text("""
:root{color-scheme:dark;--bg:#0d1117;--fg:#c9d1d9;--muted:#8b949e;--link:#58a6ff;--border:#30363d;--card:#161b22;}
body{margin:0;font:18px/1.55 system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--fg)}
a{color:var(--link);text-decoration:none} a:hover{text-decoration:underline}
.container{max-width:1100px;margin:0 auto;padding:24px}
.nav{display:flex;gap:14px;padding:14px 24px;border-bottom:1px solid var(--border);background:rgba(13,17,23,.95);position:sticky;top:0}
.nav a{padding:6px 12px;border:1px solid var(--border);border-radius:6px;background:var(--card)}
ul{list-style:none;padding:0} li{padding:4px 0}
""", encoding="utf-8")
def nav_html(rel_home):
links = [f"<a href='{rel_home}index.html'>Home</a>", f"<a href='{rel_home}browse/index.html'>Browse Files</a>"]
if has_diff:
links.append(f"<a href='{rel_home}diff/index.html'>View Diff</a>")
return "".join(links)
def wrap_page(title, body, rel_path=""):
return f"""<!doctype html>
<html><head><meta charset='utf-8'><title>{title}</title>
<link rel='stylesheet' href='{rel_path}assets/style.css'>
</head><body>
<div class='nav'>{nav_html(rel_path)}</div>
<div class='container'>{body}</div>
</body></html>"""
def generate_index(directory):
items = sorted(directory.iterdir(), key=lambda p: (p.is_file(), p.name))
links = []
if directory != browse_root:
links.append(f"<li><a href='../index.html'>.. (Parent Directory)</a></li>")
for item in items:
if item.name == "index.html": continue
name = item.name + ("/" if item.is_dir() else "")
href = item.name + ("/index.html" if item.is_dir() else "")
links.append(f"<li><a href='{href}'>{name}</a></li>")
body = f"<h1>Index of {html.escape(directory.name)}</h1><ul>{''.join(links)}</ul>"
depth = len(directory.relative_to(site_root).parts)
rel_assets = "../" * depth
(directory / "index.html").write_text(wrap_page(directory.name, body, rel_assets), encoding="utf-8")
for item in items:
if item.is_dir():
generate_index(item)
if browse_root.exists():
generate_index(browse_root)
main_body = """
<h1>LuaGenerator Results</h1>
<p>Generated protocol data from GenerateLua.sh.</p>
<ul>
<li><a href='./browse/index.html'>Browse Generated Files</a></li>
"""
if has_diff:
main_body += "<li><a href='./diff/index.html'>View Diff vs Master</a></li>"
main_body += "</ul>"
(site_root / "index.html").write_text(wrap_page("LuaGenerator Results", main_body, ""), encoding="utf-8")
PY
# ----- Master Push: Update Baseline -----
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
echo "Updating master baseline..."
# Update Browsable Site
rm -rf "site/master/latest"
mkdir -p "site/master/latest"
cp -a "site/$RUN_DIR"/* "site/master/latest/"
# Update Raw Baseline
rm -rf "site/master/latest_raw"
mkdir -p "site/master/latest_raw"
cp -r generated/* "site/master/latest_raw/"
echo "Baseline updated."
fi
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./site
destination_dir: LuaGenerator
keep_files: true
- name: AI Summary
if: github.event_name == 'pull_request' && steps.build_site.outputs.has_diff == 'true'
id: ai
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
python - <<'PY'
import json
import os
import urllib.request
import sys
# ----- Read diff -----
diff_path = "diffs/combined_trunc.diff"
try:
with open(diff_path, "r", encoding="utf-8", errors="ignore") as f:
diff_text = f.read()
except Exception as e:
print(f"::warning::Could not read diff file: {e}")
sys.exit(0)
if not diff_text.strip():
print("::warning::Diff text is empty.")
sys.exit(0)
url = "https://models.github.ai/inference/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.environ['GH_TOKEN']}",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"
}
SAFE_LIMIT = 25000
payload = {
"model": "openai/gpt-4.1",
"messages": [
{"role": "system", "content": "You are a Lua/Data serialization expert. Summarize the changes in this diff. Start with bullet points."},
{"role": "user", "content": diff_text[:SAFE_LIMIT]}
],
"temperature": 0.5
}
try:
req = urllib.request.Request(url, data=json.dumps(payload).encode("utf-8"), headers=headers)
with urllib.request.urlopen(req) as resp:
data = json.load(resp)
summary = data.get("choices", [{}])[0].get("message", {}).get("content", "")
if summary:
with open(os.environ["GITHUB_OUTPUT"], "a") as gh_out:
gh_out.write("summary<<EOF\n")
gh_out.write(summary + "\n")
gh_out.write("EOF\n")
else:
print("::warning::AI returned empty content.")
print(f"Debug response: {json.dumps(data)}")
except urllib.error.HTTPError as e:
print(f"::error::API Request failed: {e.code} {e.reason}")
print(e.read().decode("utf-8", errors="ignore"))
except Exception as e:
print(f"::error::Unexpected error: {e}")
PY
- name: Wait for Pages to be available
if: github.event_name == 'pull_request'
shell: bash
run: |
set -euo pipefail
URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/LuaGenerator/${{ env.RUN_DIR }}/"
echo "Waiting for: $URL"
for i in {1..30}; do
code="$(curl -s -o /dev/null -L -w '%{http_code}' "$URL" || true)"
if [[ "$code" == "200" ]]; then
echo "Pages is live (HTTP $code)"
exit 0
fi
echo "Not live yet (HTTP $code), retrying in 3s..."
sleep 3
done
echo "::warning::Timed out waiting for GitHub Pages. The link might be 404 initially."
exit 0
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v5
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
### LuaGenerator Results
[View Results](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/LuaGenerator/${{ env.RUN_DIR }}/)
${{ steps.build_site.outputs.has_diff == 'true' && '**Changes detected.**' || '**No changes detected.**' }}
${{ steps.build_site.outputs.has_diff == 'true' && steps.ai.outputs.summary || '' }}