From ed61d102cd9d8ce987502ccfb622a80f8615ff63 Mon Sep 17 00:00:00 2001 From: csh Date: Tue, 25 Aug 2026 17:40:25 +0800 Subject: [PATCH] :bug: fix(ci): isolate thirdparty updater trigger --- .gitea/workflows/prepare.yml | 2 +- .gitea/workflows/update-thirdparty-skills.yml | 44 +++++++++++-------- test/README.md | 5 ++- test/test_thirdparty_skills_pipeline.py | 14 +++--- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.gitea/workflows/prepare.yml b/.gitea/workflows/prepare.yml index 58cd69b9..4241ac7a 100644 --- a/.gitea/workflows/prepare.yml +++ b/.gitea/workflows/prepare.yml @@ -2,7 +2,7 @@ name: 🧰 准备环境 on: push: - # 主分支:下游 sync / thirdparty 消费者只关心 main。 + # 主分支:下游 checks / TSL Playbook 发布只关心 main。 # 其它分支(含 ci bot 推送的 tsl-playbook / thirdparty/skill 分支)跑 Prepare 纯属空耗,故在此过滤。 branches: - main diff --git a/.gitea/workflows/update-thirdparty-skills.yml b/.gitea/workflows/update-thirdparty-skills.yml index ebed7354..ddf80e70 100644 --- a/.gitea/workflows/update-thirdparty-skills.yml +++ b/.gitea/workflows/update-thirdparty-skills.yml @@ -1,15 +1,11 @@ name: ♻️ 更新第三方 Skills on: - # Gitea 1.27 不会从 schedule 触发的 Prepare 继续派生 workflow_run。 - # 定时刷新因此由 updater 直接拥有;push / PR 仍在 Prepare 成功后进入。 + # updater 是独立维护任务,不随普通 push / PR 自动运行。 schedule: - # 北京时间(UTC+8)每日 06:00。 - - cron: "0 22 * * *" - workflow_run: - workflows: ["🧰 准备环境"] - types: - - completed + # 北京时间(UTC+8)每日 05:00。 + - cron: "0 21 * * *" + workflow_dispatch: concurrency: group: update-thirdparty-${{ github.repository }} @@ -27,8 +23,7 @@ env: jobs: update_and_sync: - # schedule 直接进入;workflow_run 需要 Prepare 成功且来自主分支。 - if: ${{ github.event_name == 'schedule' || (github.event.workflow_run.conclusion == 'success' && (github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'master')) }} + # 仅由定时任务或主分支上的手动运行进入。 name: 📥 更新快照并同步 main runs-on: standard-ubuntu-22 permissions: @@ -43,14 +38,27 @@ jobs: echo "❌ 未配置 WORKFLOW secret,无法 fetch/push" >&2 exit 1 fi - if [ "$GITHUB_EVENT_NAME" = "schedule" ]; then - SOURCE_BRANCH="$GITHUB_REF_NAME" - SOURCE_SHA="$GITHUB_SHA" - echo "🌟 定时运行;目标分支: $SOURCE_BRANCH,提交: $SOURCE_SHA" - else - SOURCE_BRANCH="${{ github.event.workflow_run.head_branch }}" - SOURCE_SHA="${{ github.event.workflow_run.head_sha }}" - fi + SOURCE_BRANCH="$GITHUB_REF_NAME" + SOURCE_SHA="$GITHUB_SHA" + case "$SOURCE_BRANCH" in + main|master) ;; + *) + echo "仅允许在主分支运行 thirdparty updater: $SOURCE_BRANCH" >&2 + exit 1 + ;; + esac + case "$GITHUB_EVENT_NAME" in + schedule) + echo "🌟 定时运行;目标分支: $SOURCE_BRANCH,提交: $SOURCE_SHA" + ;; + workflow_dispatch) + echo "👆 手动运行;目标分支: $SOURCE_BRANCH,提交: $SOURCE_SHA" + ;; + *) + echo "不支持的触发事件: $GITHUB_EVENT_NAME" >&2 + exit 1 + ;; + esac echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> "$GITHUB_ENV" echo "SOURCE_SHA=$SOURCE_SHA" >> "$GITHUB_ENV" echo "✅ Token 已配置" diff --git a/test/README.md b/test/README.md index 5eb11704..f18cc5c4 100644 --- a/test/README.md +++ b/test/README.md @@ -39,8 +39,9 @@ python test/integration/check_doc_links.py - **触发方式**:`workflow_run`——「🧰 准备环境」(`prepare.yml`)完成后触发。 Prepare 监听 `push:main`、`pull_request` 与 `workflow_dispatch`;推送到 main、 - 对 main 开 PR 或手动运行 Prepare 都会经 Prepare 传导到测试。每日 `schedule` - 只属于 thirdparty updater,不会触发这套提交验证。 + 对 main 开 PR 或手动运行 Prepare 都会经 Prepare 传导到测试。thirdparty + updater 仅由每日 `schedule` 或 `workflow_dispatch` 直接运行;如果它向 main + 推送了同步提交,该 push 会正常进入 Prepare 和这套提交验证。 - **运行平台**:standard-ubuntu-22 - **注**:同一 job 先校验 commit message,再运行全量测试。 diff --git a/test/test_thirdparty_skills_pipeline.py b/test/test_thirdparty_skills_pipeline.py index 02027168..543a141f 100644 --- a/test/test_thirdparty_skills_pipeline.py +++ b/test/test_thirdparty_skills_pipeline.py @@ -228,7 +228,7 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase): self.assertIn("update_thirdparty_snapshots", text) self.assertIn("sync_thirdparty_skills", text) - def test_schedule_runs_updater_without_changing_prepare_run_shape(self): + def test_schedule_and_manual_dispatch_run_updater_without_prepare(self): prepare_text = PREPARE_WORKFLOW.read_text(encoding="utf-8") updater_text = WORKFLOW.read_text(encoding="utf-8") @@ -239,19 +239,19 @@ class ThirdpartySkillsPipelineTests(unittest.TestCase): ) self.assertEqual( workflow_mapping_keys(updater_text, "on"), - ["schedule", "workflow_run"], + ["schedule", "workflow_dispatch"], ) self.assertNotIn("update_thirdparty_scheduled", prepare_text) self.assertNotIn("uses: ./.gitea/workflows/", prepare_text) self.assertNotIn(" schedule:", prepare_text) self.assertNotIn(" workflow_call:", updater_text) - self.assertIn(' - cron: "0 22 * * *"', updater_text) - self.assertIn("github.event_name == 'schedule' ||", updater_text) - self.assertNotIn("github.event.workflow_run.event != 'schedule'", updater_text) + self.assertIn(' - cron: "0 21 * * *"', updater_text) + self.assertNotIn("workflow_run:", updater_text) + self.assertNotIn("github.event.workflow_run", updater_text) self.assertIn('SOURCE_BRANCH="$GITHUB_REF_NAME"', updater_text) self.assertIn('SOURCE_SHA="$GITHUB_SHA"', updater_text) - self.assertIn('SOURCE_BRANCH="${{ github.event.workflow_run.head_branch }}"', updater_text) - self.assertIn('SOURCE_SHA="${{ github.event.workflow_run.head_sha }}"', updater_text) + self.assertIn('main|master) ;;', updater_text) + self.assertIn('workflow_dispatch)', updater_text) self.assertIn('echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> "$GITHUB_ENV"', updater_text) self.assertIn('echo "SOURCE_SHA=$SOURCE_SHA" >> "$GITHUB_ENV"', updater_text) self.assertIn('HEAD_SHA="$SOURCE_SHA"', updater_text)