Repository navigation
102 lines (88 loc) · 3.67 KB
/
Copy pathdeploy.yml
File metadata and controls
102 lines (88 loc) · 3.67 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
name: Deploy site
on:
push:
branches: [main]
schedule:
# stars, contributors and the activity feed every day
- cron: "17 21 * * *"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Actions are pinned to commits; the token is not left in .git/config for later steps.
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
# main is protected, so the bot cannot commit the stats back. They are refreshed into this build on
# every deploy instead; the data/stats.json in the repository is only the fallback.
- name: Refresh GitHub stats
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python3 scripts/update_stats.py data/stats.json
- name: Build the activity feed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python3 scripts/build_activity.py data/activity.json || echo "activity feed kept as is"
- name: Copy the web book glossary
run: python3 scripts/build_glossary.py
- name: Check data files
run: python3 scripts/check_data.py
- name: Build Builder pages and badges
run: python3 scripts/build_builders.py
- name: Build sitemap
run: python3 scripts/build_sitemap.py
- name: Collect site files
run: |
mkdir _site
cp -r index.html article.html game.html lab.html library.html 404.html .nojekyll robots.txt sitemap.xml assets data articles builders badges _site/
# The Iterglow public SDK key lives in the ITERGLOW_SDK_KEY secret, not in the repo. It is added to the
# published experiments.json only while an experiment is switched on; with no key, experiments stay off.
- name: Add the Iterglow key
env:
ITERGLOW_SDK_KEY: ${{ secrets.ITERGLOW_SDK_KEY }}
run: |
python3 - <<'PY'
import json, os
path = "_site/data/experiments.json"
with open(path, encoding="utf-8") as f:
cfg = json.load(f)
key = os.environ.get("ITERGLOW_SDK_KEY", "").strip()
if not cfg.get("enabled"):
print("experiments off")
elif key.startswith("pk_"):
cfg["apiKey"] = key
print("experiments on")
else:
cfg["enabled"] = False
print("::warning::experiments.json is enabled but the ITERGLOW_SDK_KEY secret is missing; experiments stay off")
with open(path, "w", encoding="utf-8") as f:
json.dump(cfg, f, ensure_ascii=False, indent=2)
f.write("\n")
PY
# Browsers keep scripts and styles for up to ten minutes; a version on their URLs makes each deploy load
# its own files instead of new HTML running last deploy's scripts.
- name: Version script and style URLs
run: |
python3 - "${GITHUB_SHA::8}" <<'PY'
import pathlib, re, sys
v = sys.argv[1]
pat = re.compile(r'((?:src|href)="(?:\.\./|/)?assets/(?:js|css)/[\w.-]+\.(?:js|css))"')
for p in pathlib.Path("_site").rglob("*.html"):
t = p.read_text(encoding="utf-8")
n = pat.sub(lambda m: f'{m.group(1)}?v={v}"', t)
if n != t:
p.write_text(n, encoding="utf-8")
PY
- name: Publish to gh-pages
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
publish_branch: gh-pages
force_orphan: true