-
Notifications
You must be signed in to change notification settings - Fork 5
85 lines (74 loc) · 2.28 KB
/
publish_pix_data.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
85
# Publish new set of GitHub Pages when new pictures are committed to main
on:
workflow_dispatch:
push:
branches:
- main
paths:
- ".github/workflows/publish_pix_data.yml"
- "**/*.pix"
name: Generate Pix List for Viewer
jobs:
generate_data_json:
name: Generate Data JSON
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
- 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 file in glob.glob(f"{PIC_ROOT}**/*.pix", 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)
try:
pics.pop("templates")
except Exception:
pass
with open(f"data_i2c_pix.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@v4
with:
name: data-i2c-pix-json
path: data_i2c_pix.json
retention-days: 5
update_gh_pages:
name: Update Data on GitHub Pages
needs: generate_data_json
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Download data JSON
uses: actions/download-artifact@v4
with:
name: data-i2c-pix-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_i2c_pix.json
git commit -am "automated update of json data"
git push