Files
JayuCloud/.gitea/scripts/assert-nacos-release.mjs
xiaowang ac84f8f206
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 1s
重整三环境发布与回退工作流
2026-10-15 11:26:28 +08:00

19 lines
1.4 KiB
JavaScript

import { createHash } from 'node:crypto';
import { access, readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { envName, latestSuccess, recordsRoot, snapshotRoot } from './release-store.mjs';
const environment = envName(process.env.RELEASE_ENVIRONMENT);
const commitSha = process.env.RELEASE_SHA;
const record = await latestSuccess(environment, 'nacos');
if (!commitSha || record.commitSha !== commitSha || record.status !== 'success') throw new Error(`没有提交 ${commitSha} 对应的成功 Nacos 发布`);
if (!record.activeSnapshotId || !record.snapshotId || !Array.isArray(record.files) || record.files.length === 0 || record.files.some((file) => !file.sha256 || !file.dataId || !file.namespace)) throw new Error('Nacos 发布记录不完整');
const destinations = environment === 'prod' ? ['prod-center1', 'prod-center2'] : [environment];
for (const destination of destinations) for (const file of record.files) {
const path = join(snapshotRoot(environment, record.activeSnapshotId), destination, file.namespace, 'DEFAULT_GROUP', file.dataId);
const content = await readFile(path, 'utf8');
if (createHash('sha256').update(content, 'utf8').digest('hex') !== file.sha256) throw new Error(`Nacos 发布快照摘要不匹配:${destination}/${file.namespace}/${file.dataId}`);
}
await access(join(recordsRoot(environment), 'latest-success-nacos.json'));
console.log(JSON.stringify(record));