mirror of
https://github.com/lucaszhongsj/ps5-payloads-atlas.git
synced 2026-10-06 05:00:26 +02:00
118 lines
3.7 KiB
YAML
118 lines
3.7 KiB
YAML
name: Refresh Catalogue and Deploy Pages
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '7 */3 * * *' # 每 3 小时一次 (UTC :07),东八区 08:07/11:07/14:07/17:07/20:07/23:07
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: write
|
|
pages: write
|
|
id-token: write
|
|
|
|
concurrency:
|
|
group: refresh-and-deploy
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
refresh:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.x'
|
|
|
|
- name: Aggregate catalogue
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: python update_payloads.py
|
|
|
|
- name: Commit and push
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add payloads.json README.md
|
|
# git diff --cached --quiet 区分"有变更需提交"与"无变更",避免静默掩盖。
|
|
if git diff --cached --quiet; then
|
|
echo "No changes to commit"
|
|
else
|
|
git commit -m "Auto-refresh payload catalogue"
|
|
git push
|
|
fi
|
|
|
|
deploy:
|
|
needs: refresh
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.deploy.outputs.page_url }}
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
# refresh job 可能刚 push 了新 commit,拉最新而非 workflow 触发时的快照。
|
|
ref: ${{ github.ref }}
|
|
|
|
- name: Render README to HTML
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
mkdir -p _site
|
|
# Use GitHub's markdown API so rendering matches the repo README 1:1.
|
|
PAYLOAD=$(jq -Rs '{text: ., mode: "gfm"}' < README.md)
|
|
BODY=$(curl -sS -X POST https://api.github.com/markdown \
|
|
-H "Authorization: bearer $GH_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$PAYLOAD")
|
|
# Inline the JSON payload to python via stdin to avoid shell-escape pain.
|
|
printf '%s' "$BODY" > _site/_body.html
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
import re
|
|
body = Path("_site/_body.html").read_text(encoding="utf-8")
|
|
# Extract the first H1 as page title.
|
|
m = re.search(r"<h1[^>]*>(.*?)</h1>", body, re.DOTALL)
|
|
title = re.sub(r"<[^>]+>", "", m.group(1)).strip() if m else "ps5-payloads-atlas"
|
|
page = f"""<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{title}</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5/github-markdown-light.css">
|
|
<style>
|
|
body {{ box-sizing: border-box; max-width: 980px; margin: 0 auto; padding: 32px 16px; }}
|
|
@media (max-width: 767px) {{ body {{ padding: 16px; }} }}
|
|
</style>
|
|
</head>
|
|
<body class="markdown-body">
|
|
{body}
|
|
</body>
|
|
</html>
|
|
"""
|
|
Path("_site/index.html").write_text(page, encoding="utf-8")
|
|
Path("_site/_body.html").unlink()
|
|
PY
|
|
|
|
- name: Stage static files
|
|
run: |
|
|
cp payloads.json _site/
|
|
cp sources.json _site/
|
|
cp LICENSE _site/
|
|
|
|
- name: Setup Pages
|
|
uses: actions/configure-pages@v5
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-pages-artifact@v3
|
|
with:
|
|
path: _site
|
|
|
|
- name: Deploy to GitHub Pages
|
|
id: deploy
|
|
uses: actions/deploy-pages@v5
|