Repository navigation
79 lines (68 loc) · 2.72 KB
/
Copy pathdeploy.yml
File metadata and controls
79 lines (68 loc) · 2.72 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
name: Deploy site
on:
push:
branches: [main]
schedule:
# stats once a week (Monday), the activity feed every day
- cron: "17 0 * * 1"
- 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
- name: Refresh GitHub stats
if: github.event_name == 'workflow_dispatch' || github.event.schedule == '17 0 * * 1'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 scripts/update_stats.py data/stats.json
if ! git diff --quiet data/stats.json; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add data/stats.json
git commit -m "Update GitHub stats"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" HEAD:main
fi
- 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: Check data files
run: python3 scripts/check_data.py
- name: Build Builder pages and badges
run: python3 scripts/build_builders.py
- name: Collect site files
run: |
mkdir _site
cp -r index.html article.html game.html lab.html 404.html .nojekyll assets data articles builders badges _site/
# 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