From c7fd17df3578a1e1f0ae447040fd513fa7c99ed5 Mon Sep 17 00:00:00 2001 From: WuYongJie Date: Sat, 29 Aug 2026 21:07:44 +0800 Subject: [PATCH] fix: upgrade notification compose incrementally --- scripts/git-build-deploy.ps1 | 24 ++++++++++++++---------- src/__tests__/deployment.test.ts | 3 +++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/git-build-deploy.ps1 b/scripts/git-build-deploy.ps1 index e35155c..36ba4e7 100644 --- a/scripts/git-build-deploy.ps1 +++ b/scripts/git-build-deploy.ps1 @@ -138,16 +138,20 @@ compose_required = [ ' YYD_NOTIFICATION_ADMIN_API_SECRET: ${YYD_NOTIFICATION_ADMIN_API_SECRET}', ' YYD_NOTIFICATION_CONFIG_ENCRYPTION_KEY: ${YYD_NOTIFICATION_CONFIG_ENCRYPTION_KEY}', ] -present = [line in compose_text for line in compose_required] -if any(present) and not all(present): - raise SystemExit('通知中心 Compose 管理环境映射不完整,拒绝猜测性修改') -if not all(present): - if compose_text.count(compose_marker) != 1: - raise SystemExit('通知中心 Compose 项目配置锚点不唯一,拒绝修改') - compose_text = compose_text.replace( - compose_marker, - compose_marker + '\n' + '\n'.join(compose_required), - ) +if compose_text.count(compose_marker) != 1: + raise SystemExit('通知中心 Compose 项目配置锚点不唯一,拒绝修改') +compose_changed = False +for line in compose_required: + if compose_text.count(line) > 1: + raise SystemExit('通知中心 Compose 环境映射重复,拒绝修改') + if line in compose_text: + continue + variable_name = line.strip().split(':', 1)[0] + if any(candidate.strip().startswith(variable_name + ':') for candidate in compose_text.splitlines()): + raise SystemExit(f'通知中心 Compose {variable_name} 存在不同映射,拒绝猜测性修改') + compose_text = compose_text.replace(compose_marker, compose_marker + '\n' + line, 1) + compose_changed = True +if compose_changed: compose_path.write_text(compose_text, encoding='utf-8') env_path = Path('.env') diff --git a/src/__tests__/deployment.test.ts b/src/__tests__/deployment.test.ts index f52c0e3..16def7b 100644 --- a/src/__tests__/deployment.test.ts +++ b/src/__tests__/deployment.test.ts @@ -23,6 +23,9 @@ test('生产发布面透传免登配置并保留已有项目 login', () => { assert.match(example, /YYD_NOTIFICATION_DIRECTORY_URL/) assert.match(deploy, /YYD_NOTIFICATION_DIRECTORY_URL/) assert.match(gitDeploy, /YYD_NOTIFICATION_DIRECTORY_URL/) + assert.match(gitDeploy, /for line in compose_required:/) + assert.match(gitDeploy, /compose_changed = True/) + assert.doesNotMatch(gitDeploy, /any\(present\) and not all\(present\)/) assert.match(deploy, /old_login = by_code\.get\(code, \{\}\)\.get\('login'\)/) assert.match(deploy, /def project_with_preserved_login/) assert.match(deploy, /project\['login'\] = login/)