Sync to Gitee after gh-pages build #19
This file contains 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: Sync to Gitee after gh-pages build | |
# 当指定的工作流完成时触发此工作流 | |
on: | |
workflow_run: | |
workflows: ["pages-build-deployment"] # 替换为你的 gh-pages 构建工作流名称 | |
types: | |
- completed | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. 检出代码,确保获取所有分支和历史 | |
- name: Checkout code with full history | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
# 2. 同步到 Gitee | |
- name: Push main and gh-pages branches to Gitee | |
env: | |
GITEE_REPO: jiajunlin/open-course | |
GITEE_USERNAME: ${{ secrets.GITEE_USERNAME }} | |
GITEE_EMAIL: ${{ secrets.GITEE_EMAIL }} | |
GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }} | |
run: | | |
# 设置 Git 用户信息 | |
git config user.name "$GITEE_USERNAME" | |
git config user.email "$GITEE_EMAIL" | |
# 添加 Gitee 为远程地址 | |
git remote add gitee https://$GITEE_USERNAME:[email protected]/$GITEE_REPO.git | |
# 推送 main 分支到 Gitee | |
git checkout main | |
git push gitee main | |
# 推送 gh-pages 分支到 Gitee | |
git checkout gh-pages | |
git pull | |
git push gitee gh-pages --force | |
# 3. 触发 Gitee Pages 重建 , 需要pro用户,才可以调用api | |
# - name: Trigger Gitee Pages Rebuild | |
# env: | |
# GITEE_REPO: jiajunlin/open-course | |
# GITEE_USERNAME: ${{ secrets.GITEE_USERNAME }} | |
# GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }} | |
# run: | | |
# curl -X POST https://gitee.com/api/v5/repos/$GITEE_USERNAME/$GITEE_REPO/pages/builds \ | |
# -H 'Content-Type: application/json;charset=UTF-8' \ | |
# -d '{"access_token": "$GITEE_TOKEN"}' |