Deploy to GitHub Pages #449
This file contains hidden or 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
| name: Deploy to GitHub Pages | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'site/**' | |
| - 'data/**' | |
| workflow_run: | |
| workflows: ["6-Hour AI Data Aggregation"] | |
| types: [completed] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' | |
| concurrency: | |
| group: ai-hot-pages-deploy | |
| cancel-in-progress: true | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Hugo | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: 'latest' | |
| extended: true | |
| - name: Refresh meta timestamp (Asia/Shanghai) | |
| run: | | |
| python - <<'PY' | |
| import json | |
| from pathlib import Path | |
| from datetime import datetime | |
| from zoneinfo import ZoneInfo | |
| meta_path = Path('data/meta.json') | |
| meta = {} | |
| if meta_path.exists(): | |
| meta = json.loads(meta_path.read_text(encoding='utf-8')) | |
| meta['last_update'] = datetime.now(ZoneInfo('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S') | |
| meta.setdefault('version', '3.0') | |
| results = meta.get('results') or {} | |
| results['网站部署'] = f"✅ GitHub Pages 发布 {meta['last_update']}" | |
| meta['results'] = results | |
| meta_path.write_text(json.dumps(meta, ensure_ascii=False, indent=2), encoding='utf-8') | |
| PY | |
| - name: Sync data to Hugo | |
| run: cp -r data/* site/data/ | |
| - name: Build | |
| working-directory: site | |
| run: hugo --minify | |
| - name: Create CNAME | |
| run: echo "aihot.bt199.com" > site/public/CNAME | |
| - name: Deploy | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: site/public |