-
Notifications
You must be signed in to change notification settings - Fork 2
84 lines (72 loc) · 2.25 KB
/
publish_github_pages.yml
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
# Publish new set of GitHub Pages when new GSC or XBM pictures are committed to main
on:
workflow_dispatch:
push:
branches:
- main
paths:
- ".github/workflows/publish_github_pages.yml"
- "**/*.gsc"
- "**/*.xbm"
name: Publish GitHub Pages
jobs:
generate_data_js:
name: Generate Data JSON
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v2
- name: Generate data.js
env:
GIT_SHA: ${{ github.sha }}
run: |
import glob
import json
import os
from datetime import datetime
PIC_ROOT = "Pictures/"
pics = {}
for pic_type in ["gsc", "xbm"]:
for file in glob.glob(f"**/*.{pic_type}", recursive=True):
if os.path.islink(file):
continue
path, core = os.path.split(file.replace(PIC_ROOT, ""))
if path not in pics:
pics[path] = []
pics[path].append(core)
with open("data_pics.json", "w") as outfile:
data = {
"pictures": pics,
"version": {
"date": datetime.now().isoformat(),
"sha": os.environ.get("GIT_SHA", "unknown")[:7],
},
}
json.dump(data, outfile)
shell: python
- name: Archive data JSON
uses: actions/upload-artifact@v2
with:
name: data-pics-json
path: data_pics.json
retention-days: 5
update_gh_pages:
name: Update Data on GitHub Pages
needs: generate_data_js
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v2
with:
ref: gh-pages
- name: Download data JSON
uses: actions/download-artifact@v2
with:
name: data-pics-json
- name: Commit data json
run: |
git config --local user.name 'github-actions[bot]'
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add data_pics.json
git commit -am "automated update of json data"
git push