New picture: Lifeforce (Salamander) #301
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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@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 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@v4 | |
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@v4 | |
with: | |
ref: gh-pages | |
- name: Download data JSON | |
uses: actions/download-artifact@v4 | |
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 |