🐛 fix(ci): isolate thirdparty updater trigger

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