# .github/workflows/sync-page-to-cnb.yml name: Sync Page Branch to CNB (Auto Deploy) # 避免并发堆积 concurrency: group: ${{ github.ref }} cancel-in-progress: true on: repository_dispatch: types: [sync-to-cnb] # 👈 监听来自 generate-static-site.yml 的事件 workflow_dispatch: inputs: reason: description: '测试部署' required: false default: 'Manual run' jobs: sync: runs-on: ubuntu-latest steps: # 🔍 1. 检出 page 分支内容 - name: 📥 Checkout page branch uses: actions/checkout@v5 with: ref: page token: ${{ secrets.GITHUB_TOKEN }} fetch-depth: 0 # 获取完整历史记录,确保 git diff 能正常工作 # 🔍 2. 强制部署(不再检查变更) - name: 🔁 Always deploy id: check run: | echo "✅ Page branch updated with new commit. Forcing deployment to CNB." echo "skip=false" >> $GITHUB_OUTPUT # 🚀 3. 推送到 CNB - name: 🚀 Push to CNB & Trigger Deployment if: steps.check.outputs.skip == 'false' env: CNB_USERNAME: ${{ secrets.CNB_USERNAME }} CNB_TOKEN: ${{ secrets.CNB_TOKEN }} run: | echo "🧹 Cleaning old Git metadata..." rm -rf .git echo "🌱 Initializing new Git repository..." git init git config --global user.name 'GitHub Action' git config --global user.email 'action@github.com' echo "💾 Adding all static files to staging area..." git add . echo "📝 Committing with timestamp..." git commit -m "[skip ci] 🖼️ Auto-update Bing images and deploy $(date +'%%Y-%%m-%%d %%H:%%M:%%S')" echo "🔗 Setting remote to CNB repository..." git remote add origin "https://${{ secrets.CNB_USERNAME }}:${{ secrets.CNB_TOKEN }}@cnb.cool/gyhwd.top/AhHui-Homepage.git" echo "🚀 Forcing push to main branch on CNB..." git branch -M main git push --force --quiet origin main echo "🎉 Successfully pushed to CNB: wojack/AhHui-Homepage" # 4.👇 触发服务器部署 - name: 🔔 Trigger server deployment uses: actions/github-script@v7 with: script: | await github.rest.repos.createDispatchEvent({ owner: context.repo.owner, repo: context.repo.repo, event_type: 'deploy-to-server', client_payload: { message: 'CNB updated, triggering server sync', commit: context.sha } })