Ultima attività 2 months ago

更新 Bing 图片并发送到 page 分支,然后同步到CNB,最后推送到服务器

Revisione ae54c1b9a9e4d3289f0d38a31ef5af1962aa4be7

generate-static-site-bk.yml Raw
1# .github/workflows/generate-static-site.yml
2name: Update Bing & Deploy to page
3
4# 触发方式:
5# - 手动触发(GitHub Actions 界面点击)
6# - 每天 01:00 UTC(北京时间 09:00)
7on:
8 workflow_dispatch: # 允许手动运行
9 schedule:
10 - cron: "0 1 * * *" # 每天 01:00 UTC
11
12jobs:
13 deploy:
14 runs-on: ubuntu-latest
15 permissions:
16 contents: write # 必需:允许写入分支(Settings → Actions → Read and write permissions)
17
18 steps:
19 # 1. 检出 main 分支代码
20 - name: 🛠️ Checkout main branch
21 uses: actions/checkout@v4
22
23 # 2. 设置 Node.js 环境(v20)
24 - name: 🟩 Setup Node.js
25 uses: actions/setup-node@v4
26 with:
27 node-version: '20.x'
28
29 # 3. 运行 bing.js 获取最新 Bing 壁纸并生成 images.json
30 - name: 🖼️ Generate Bing images.json
31 run: node ./assets/js/bing.js
32
33 # 4. 准备静态资源目录(只包含要部署的文件)
34 - name: 📁 Prepare static directory
35 run: |
36 # 清理旧的 static 目录
37 rm -rf static
38 mkdir -p static/{assets/css,assets/fonts,assets/img,assets/js,assets/json}
39
40 # 复制指定文件(不包含 bing.js、其他图片等)
41 cp index.html static/
42 cp 404.html static/ || true # 404.html 可选
43 cp favicon.ico static/
44 cp apple-touch-icon.png static/
45
46 cp assets/css/*.css static/assets/css/
47 cp assets/fonts/* static/assets/fonts/
48 cp assets/img/logo.png static/assets/img/
49 cp assets/js/main.js static/assets/js/
50 cp assets/js/fireworks.js static/assets/js/
51 cp assets/json/images.json static/assets/json/
52 cp assets/readme.md static/
53
54 # 防止 GitHub Pages 启用 Jekyll 处理
55 touch static/.nojekyll
56
57 # 输出最终结构,便于调试
58 echo "📄 Final static structure:"
59 find static -type f | sort
60
61 # 5. 配置 Git 提交者信息
62 - name: 🧑‍💻 Configure git
63 run: |
64 git config --global user.email "actions@github.com"
65 git config --global user.name "GitHub Actions"
66
67 # 6. 部署到 page 分支
68 - name: 🚀 Commit and push to page
69 run: |
70 cd static
71 git init
72 git checkout -b page
73 git add .
74 # 使用 [skip ci] 防止 page 推送再次触发 CI
75 git commit -m "[skip ci] 🖼️ Auto-update Bing images and deploy"
76 git push --force "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" page