From 8fdca696c37fcf29d0f26bf6b61eb039a131e683 Mon Sep 17 00:00:00 2001 From: qjjer <113751794+qjjer@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:29:07 +0800 Subject: [PATCH 1/4] Add workflow to sync upstream and trigger deploy --- .github/workflows/sync-upstream.yml | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/sync-upstream.yml diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml new file mode 100644 index 0000000000..5b56a55976 --- /dev/null +++ b/.github/workflows/sync-upstream.yml @@ -0,0 +1,53 @@ +name: Sync Upstream and Trigger Deploy + +on: + schedule: + - cron: '0 0 * * *' # 每天 UTC 0:00 运行 + workflow_dispatch: + +permissions: + contents: write + actions: write + +jobs: + sync: +连续的:Ubuntu-最新 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + - name: Add upstream + run: git远程添加上游https://github.com/maillab/cloud-mail.git + + - name: Fetch upstream + run: git fetch upstream main + +-姓名: Check changes + id: check + run: | + if["$(git rev-parse HEAD)"!="$(git rev-parse上游/主)"];则 +echo"changes=true">>$GITHUB_OUTPUT + fi + + - name: Merge and push + if: steps.check.outputs.changes == 'true' + run: | +git配置user.name"github操作[bot]" +git配置user.email"41898282+github-action[bot]@users。nore reply。GitHub。com" +git合并上游/主要--no-ff-m"合并上游更新" + git push origin main + + - name: 触发器部署 + if: steps.check.outputs.changes == 'true' + uses: actions/github-script@v7 + with: + script: | +等待github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, +workflow_id:'deploy-cloudflare.yml', +参考:'main' + }); From cf684b00703122cc2a12a1a97456d43adf1e4428 Mon Sep 17 00:00:00 2001 From: qjjer <113751794+qjjer@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:41:56 +0800 Subject: [PATCH 2/4] Refactor GitHub Actions workflow for upstream sync --- .github/workflows/sync-upstream.yml | 85 ++++++++++++++--------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index 5b56a55976..2549a8e9ec 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -1,53 +1,48 @@ -name: Sync Upstream and Trigger Deploy - -on: - schedule: - - cron: '0 0 * * *' # 每天 UTC 0:00 运行 - workflow_dispatch: +name: Upstream Sync permissions: contents: write - actions: write + +on: + schedule: + - cron: "0 0 * * *" # 每天 UTC 时间 0:00 运行 + workflow_dispatch: # 允许手动触发 jobs: - sync: -连续的:Ubuntu-最新 + sync_latest_from_upstream: + name: Sync latest commits from upstream repo + runs-on: ubuntu-latest + if: ${{ github.event.repository.fork }} # 仅在 fork 仓库中运行 + steps: - - name: Checkout - uses: actions/checkout@v4 + # Step 1: 检出当前仓库代码 + - name: Checkout target repo + uses: actions/checkout@v6 + + # Step 2: 同步上游仓库的更新 + - name: Sync upstream changes + id: sync + uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 with: - token: ${{ secrets.GITHUB_TOKEN }} - fetch-depth: 0 - - - name: Add upstream - run: git远程添加上游https://github.com/maillab/cloud-mail.git - - - name: Fetch upstream - run: git fetch upstream main - --姓名: Check changes - id: check + upstream_sync_repo: maillab/cloud-mail + upstream_sync_branch: main + target_sync_branch: main + target_repo_token: ${{ secrets.GITHUB_TOKEN }} + test_mode: false + + # Step 3: 同步失败时的错误提示(适用于一般冲突场景) + - name: Sync check + if: failure() run: | - if["$(git rev-parse HEAD)"!="$(git rev-parse上游/主)"];则 -echo"changes=true">>$GITHUB_OUTPUT - fi - - - name: Merge and push - if: steps.check.outputs.changes == 'true' - run: | -git配置user.name"github操作[bot]" -git配置user.email"41898282+github-action[bot]@users。nore reply。GitHub。com" -git合并上游/主要--no-ff-m"合并上游更新" - git push origin main - - - name: 触发器部署 - if: steps.check.outputs.changes == 'true' - uses: actions/github-script@v7 - with: - script: | -等待github.rest.actions.createWorkflowDispatch({ - owner: context.repo.owner, - repo: context.repo.repo, -workflow_id:'deploy-cloudflare.yml', -参考:'main' - }); + echo "[Error] 自动同步失败,可能是因为:" + echo " 1. 您的 fork 仓库与上游仓库存在代码冲突" + echo " 2. 网络或权限问题" + echo "" + echo "[Solution] 请手动解决冲突:" + echo " 1. 在 GitHub 上点击 'Sync fork' 按钮" + echo " 2. 或使用命令行:" + echo " git remote add upstream https://github.com/maillab/cloud-mail.git" + echo " git fetch upstream" + echo " git merge upstream/main" + echo " 解决冲突后 git push" + exit 1 From f2b1e6ec103cb6fa7dad37f601b29f8c063b0084 Mon Sep 17 00:00:00 2001 From: qjjer <113751794+qjjer@users.noreply.github.com> Date: Sat, 15 Aug 2026 13:44:39 +0800 Subject: [PATCH 3/4] Enhance upstream sync workflow with deployment trigger Added a step to trigger the deployment workflow if upstream changes are detected. --- .github/workflows/sync-upstream.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index 2549a8e9ec..dcb3fc7df5 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -2,24 +2,23 @@ name: Upstream Sync permissions: contents: write + actions: write # 触发其他工作流需要 on: schedule: - - cron: "0 0 * * *" # 每天 UTC 时间 0:00 运行 - workflow_dispatch: # 允许手动触发 + - cron: "0 0 * * *" + workflow_dispatch: jobs: sync_latest_from_upstream: name: Sync latest commits from upstream repo runs-on: ubuntu-latest - if: ${{ github.event.repository.fork }} # 仅在 fork 仓库中运行 + if: ${{ github.event.repository.fork }} # 如果是 fork 则保留,否则删除 steps: - # Step 1: 检出当前仓库代码 - name: Checkout target repo uses: actions/checkout@v6 - # Step 2: 同步上游仓库的更新 - name: Sync upstream changes id: sync uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 @@ -30,7 +29,20 @@ jobs: target_repo_token: ${{ secrets.GITHUB_TOKEN }} test_mode: false - # Step 3: 同步失败时的错误提示(适用于一般冲突场景) + # 新增:如果同步有变更,触发部署工作流 + - name: Trigger deploy-cloudflare.yml + if: steps.sync.outputs.has_changed == 'true' + uses: actions/github-script@v7 + with: + script: | + await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'deploy-cloudflare.yml', + ref: 'main' + }); + + # 同步失败时的错误提示(保留你的原逻辑) - name: Sync check if: failure() run: | From ab4f946b6f23b38319af71a12c61d7984e46961e Mon Sep 17 00:00:00 2001 From: qjjer <113751794+qjjer@users.noreply.github.com> Date: Sun, 16 Aug 2026 08:58:04 +0800 Subject: [PATCH 4/4] Update sync-upstream.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit token权限不足,需更换PAT个人令牌(除非你不更新workflows) --- .github/workflows/sync-upstream.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index dcb3fc7df5..53442bc21a 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -26,7 +26,7 @@ jobs: upstream_sync_repo: maillab/cloud-mail upstream_sync_branch: main target_sync_branch: main - target_repo_token: ${{ secrets.GITHUB_TOKEN }} + target_repo_token: ${{ secrets.PAT }} test_mode: false # 新增:如果同步有变更,触发部署工作流