-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (54 loc) · 2.01 KB
/
Copy pathsync-dashboard.yml
File metadata and controls
67 lines (54 loc) · 2.01 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
name: Sync Dashboard UI
on:
repository_dispatch:
types: [dashboard-ui-updated]
jobs:
sync:
name: Fetch and embed updated UI
runs-on: ubuntu-latest
steps:
- name: Checkout dev
uses: actions/checkout@v4
with:
ref: dev
token: ${{ secrets.GH_PAT }}
- name: Fetch latest ui.html from dashboard-ui
run: |
curl -sSfL \
"https://raw.githubusercontent.com/APIForge-Organisation/dashboard-ui/main/ui.html" \
-o /tmp/ui.html
- name: Embed HTML into dashboard.py
run: |
python3 - << 'PYEOF'
import re
with open('/tmp/ui.html', 'r', encoding='utf-8') as f:
html = f.read()
with open('apiforgepy/dashboard.py', 'r', encoding='utf-8') as f:
content = f.read()
# Escape backslashes and triple-quotes for a Python triple-quoted string
escaped = html.replace('\\', '\\\\').replace('"""', '\\"\\"\\"')
start = '# <<DASHBOARD_UI_START>>'
end = '# <<DASHBOARD_UI_END>>'
block = f'{start}\n_HTML = """\\\n{escaped}\n"""\n{end}'
new_content = re.sub(
re.escape(start) + r'.*?' + re.escape(end),
block,
content,
flags=re.DOTALL,
)
with open('apiforgepy/dashboard.py', 'w', encoding='utf-8') as f:
f.write(new_content)
print('dashboard.py updated.')
PYEOF
- name: Commit and push if changed
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add apiforgepy/dashboard.py
if git diff --staged --quiet; then
echo "No changes — already up to date."
else
git commit -m "chore: sync dashboard UI from dashboard-ui@${{ github.event.client_payload.sha }}"
git push origin dev
echo "Pushed updated dashboard.py to dev."
fi