fix: upgrade notification compose incrementally

This commit is contained in:
WuYongJie 2026-08-29 21:07:44 +08:00
parent 1badf9ad68
commit c7fd17df35
2 changed files with 17 additions and 10 deletions

View File

@ -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),
)
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')

View File

@ -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/)