publish-installed-update.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /** Operator entry for separate test binary uploads and fixed-feed publication; default mode is local-only. */
  2. import { parseArgs } from 'node:util'
  3. import { createInterface } from 'node:readline/promises'
  4. import { stdin, stdout } from 'node:process'
  5. import { verifiedInstalledUpdateDistribution, executeInstalledUpdatePublication } from './installed-update-publication.ts'
  6. import { createInstalledUpdateCos } from './installed-update-cos.ts'
  7. async function main(): Promise<void> {
  8. const { values, positionals } = parseArgs({ allowPositionals: true, options: {
  9. execute: { type: 'boolean', default: false }, journals: { type: 'string' },
  10. } })
  11. const [action, manifest, version, receipt, ...extra] = positionals
  12. if ((action !== 'upload-binaries' && action !== 'publish-feed') || !manifest || !version || !receipt || extra.length) {
  13. throw new Error('invalid invocation')
  14. }
  15. const prepared = await verifiedInstalledUpdateDistribution(manifest, version, receipt)
  16. console.log(JSON.stringify({ action, version, runId: prepared.run.id, destination: prepared.distribution,
  17. mode: values.execute ? 'awaiting-operator' : 'local-check', networkStarted: false }, null, 2))
  18. if (!values.execute) return
  19. if (!stdin.isTTY || !stdout.isTTY) throw new Error('operator terminal required')
  20. const expected = `${action === 'upload-binaries' ? 'UPLOAD' : 'PUBLISH'} ${version} ${prepared.run.id}`
  21. const terminal = createInterface({ input: stdin, output: stdout })
  22. let confirmed = false
  23. try {
  24. console.log(action === 'upload-binaries'
  25. ? '仅授权此批次 test 二进制上传。确认没有其他发布者;会完整回读安装包,可能产生较大下载流量。'
  26. : '仅授权此批次 test 清单发布。确认没有其他发布者;复用成功上传回执,仅回读清单,不重复下载安装包。')
  27. if (action === 'publish-feed' && version === prepared.run.versions[1]) {
  28. console.log('确认版本 1 已通过安装后的入口启动并仍在运行;必须提供该批次 journals 目录。')
  29. }
  30. confirmed = (await terminal.question(`请输入 ${expected}:`)) === expected
  31. } finally { terminal.close() }
  32. if (!confirmed) throw new Error('operator declined')
  33. console.log(await executeInstalledUpdatePublication(manifest, version, receipt, action, createInstalledUpdateCos(), values.journals))
  34. }
  35. main().catch(() => {
  36. console.error('installed update: upload/publication stopped. Review local prerequisites and any retained operation record; no automatic retry.')
  37. process.exitCode = 1
  38. })