# .github/workflows/generate-static-site.yml name: Update Bing & Deploy to page # 触发方式: # - 手动触发(GitHub Actions 界面点击) # - 每天 01:00 UTC(北京时间 09:00) on: workflow_dispatch: # 允许手动运行 schedule: - cron: "0 1 * * *" # 每天 01:00 UTC jobs: deploy: runs-on: ubuntu-latest permissions: contents: write # 必需:允许写入分支(Settings → Actions → Read and write permissions) steps: # 1. 检出 main 分支代码 - name: 🛠️ Checkout main branch uses: actions/checkout@v4 # 2. 设置 Node.js 环境(v20) - name: 🟩 Setup Node.js uses: actions/setup-node@v4 with: node-version: '20.x' # 3. 运行 bing.js 获取最新 Bing 壁纸并生成 images.json - name: 🖼️ Generate Bing images.json run: node ./assets/js/bing.js # 4. 准备静态资源目录(只包含要部署的文件) - name: 📁 Prepare static directory run: | # 清理旧的 static 目录 rm -rf static mkdir -p static/{assets/css,assets/fonts,assets/img,assets/js,assets/json} # 复制指定文件(不包含 bing.js、其他图片等) cp index.html static/ cp 404.html static/ || true # 404.html 可选 cp favicon.ico static/ cp apple-touch-icon.png static/ cp assets/css/*.css static/assets/css/ cp assets/fonts/* static/assets/fonts/ cp assets/img/logo.png static/assets/img/ cp assets/js/main.js static/assets/js/ cp assets/js/fireworks.js static/assets/js/ cp assets/json/images.json static/assets/json/ cp assets/readme.md static/ # 防止 GitHub Pages 启用 Jekyll 处理 touch static/.nojekyll # 输出最终结构,便于调试 echo "📄 Final static structure:" find static -type f | sort # 5. 配置 Git 提交者信息 - name: 🧑‍💻 Configure git run: | git config --global user.email "actions@github.com" git config --global user.name "GitHub Actions" # 6. 部署到 page 分支 - name: 🚀 Update page branch with new content run: | cd static git init git config --global user.name 'GitHub Action' git config --global user.email 'action@github.com' git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" git fetch origin page --depth=1 || true git checkout page || git checkout -b page git add . git commit -m "[skip ci] 🖼️ Auto-update Bing images and deploy $(date +'%%Y-%%m-%%d %%H:%%M:%%S')" --allow-empty git push --force origin page # 👇 新增:主动触发 sync-page-to-cnb.yml echo "✅ Pushed to page branch. Triggering sync to CNB..." curl -X POST \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ -H "Accept: application/vnd.github.v3+json" \ https://api.github.com/repos/${{ github.repository }}/dispatches \ -d '{"event_type": "sync-to-cnb"}'