From 906b43e2b6c04218a8d2b08727577aef2341c51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BA=E6=A2=B0=E5=B0=8F=E9=B8=BD?= <128568434+jixiexiaoge@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:08:32 +0800 Subject: [PATCH] Update sync-branches.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name: Sync v7-wip10 Branch on: schedule: - cron: '0 10 * * *' # 每天 UTC 10 点运行 workflow_dispatch: # 允许手动触发 jobs: sync: runs-on: ubuntu-latest steps: - name: Checkout the main repository uses: actions/checkout@v3 with: fetch-depth: 0 # 完整克隆仓库,确保所有历史记录 token: ${{ secrets.GH_TOKEN }} # 访问 GitHub 需要的令牌 - name: Setup Git run: | git config --global user.name "GitHub Actions" git config --global user.email "github-actions@github.com" - name: Add remote for yysnet/carrotpilot run: | git remote add carrotpilot https://github.com/yysnet/carrotpilot.git git fetch carrotpilot +refs/heads/v7-wip10:refs/remotes/carrotpilot/v7-wip10 - name: Ensure local branch matches remote run: | # 检查本地是否已有 v7-wip10 分支,如果有则删除 if git show-ref --verify --quiet refs/heads/v7-wip10; then git branch -D v7-wip10 fi # 创建本地 v7-wip10 分支并跟踪远程分支 git checkout -B v7-wip10 carrotpilot/v7-wip10 - name: Push to origin repository run: | git push origin v7-wip10 --force --- .github/workflows/sync-branches.yml | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/sync-branches.yml b/.github/workflows/sync-branches.yml index a7d7aa1..49a634a 100644 --- a/.github/workflows/sync-branches.yml +++ b/.github/workflows/sync-branches.yml @@ -1,8 +1,8 @@ -name: Sync Branches +name: Sync v7-wip10 Branch on: schedule: - - cron: '0 10 * * *' # 每天10点UTC + - cron: '0 10 * * *' # 每天 UTC 10 点运行 workflow_dispatch: # 允许手动触发 jobs: @@ -13,8 +13,8 @@ jobs: - name: Checkout the main repository uses: actions/checkout@v3 with: - fetch-depth: 0 # 保证完整克隆仓库,包括历史记录 - token: ${{ secrets.GH_TOKEN }} # 显式传递 GH_TOKEN + fetch-depth: 0 # 完整克隆仓库,确保所有历史记录 + token: ${{ secrets.GH_TOKEN }} # 访问 GitHub 需要的令牌 - name: Setup Git run: | @@ -23,15 +23,19 @@ jobs: - name: Add remote for yysnet/carrotpilot run: | - git remote add carrotpilot https://github.com/yysnet/carrotpilot.git || echo "Remote already exists" - git fetch carrotpilot v7-wip10 --depth=1 # 只获取该分支的最新提交 + git remote add carrotpilot https://github.com/yysnet/carrotpilot.git + git fetch carrotpilot +refs/heads/v7-wip10:refs/remotes/carrotpilot/v7-wip10 - - name: Sync v7-wip10 from carrotpilot + - name: Ensure local branch matches remote run: | - # 检查远程是否有 v7-wip10 分支 - if git ls-remote --heads carrotpilot v7-wip10 | grep -q "refs/heads/v7-wip10"; then - git checkout -B v7-wip10 carrotpilot/v7-wip10 # 强制切换到远程分支 - git push origin v7-wip10 --force # 强制推送到自己的仓库 - else - echo "Branch v7-wip10 does not exist on carrotpilot, skipping..." + # 检查本地是否已有 v7-wip10 分支,如果有则删除 + if git show-ref --verify --quiet refs/heads/v7-wip10; then + git branch -D v7-wip10 fi + + # 创建本地 v7-wip10 分支并跟踪远程分支 + git checkout -B v7-wip10 carrotpilot/v7-wip10 + + - name: Push to origin repository + run: | + git push origin v7-wip10 --force