Update sync-branches.yml

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
This commit is contained in:
机械小鸽 2025-02-03 10:08:32 +08:00 committed by GitHub
parent f02a74b225
commit 906b43e2b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,8 @@
name: Sync Branches name: Sync v7-wip10 Branch
on: on:
schedule: schedule:
- cron: '0 10 * * *' # 每天10点UTC - cron: '0 10 * * *' # 每天 UTC 10 点运行
workflow_dispatch: # 允许手动触发 workflow_dispatch: # 允许手动触发
jobs: jobs:
@ -13,8 +13,8 @@ jobs:
- name: Checkout the main repository - name: Checkout the main repository
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
fetch-depth: 0 # 保证完整克隆仓库,包括历史记录 fetch-depth: 0 # 完整克隆仓库,确保所有历史记录
token: ${{ secrets.GH_TOKEN }} # 显式传递 GH_TOKEN token: ${{ secrets.GH_TOKEN }} # 访问 GitHub 需要的令牌
- name: Setup Git - name: Setup Git
run: | run: |
@ -23,15 +23,19 @@ jobs:
- name: Add remote for yysnet/carrotpilot - name: Add remote for yysnet/carrotpilot
run: | run: |
git remote add carrotpilot https://github.com/yysnet/carrotpilot.git || echo "Remote already exists" git remote add carrotpilot https://github.com/yysnet/carrotpilot.git
git fetch carrotpilot v7-wip10 --depth=1 # 只获取该分支的最新提交 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: | run: |
# 检查远程是否有 v7-wip10 分支 # 检查本地是否已有 v7-wip10 分支,如果有则删除
if git ls-remote --heads carrotpilot v7-wip10 | grep -q "refs/heads/v7-wip10"; then if git show-ref --verify --quiet refs/heads/v7-wip10; then
git checkout -B v7-wip10 carrotpilot/v7-wip10 # 强制切换到远程分支 git branch -D v7-wip10
git push origin v7-wip10 --force # 强制推送到自己的仓库
else
echo "Branch v7-wip10 does not exist on carrotpilot, skipping..."
fi fi
# 创建本地 v7-wip10 分支并跟踪远程分支
git checkout -B v7-wip10 carrotpilot/v7-wip10
- name: Push to origin repository
run: |
git push origin v7-wip10 --force