feat: 接入精确回滚与确认后执行的运维操作
- 生成绑定操作者与 SHA 的签名计划,确认后复用发布、取消和重试服务,限制过期、并发与重复提交。 - 从真实历史构建核实回滚目标,升级纳管 Jenkins 任务以锁定提交并保留原参数选择器。 - Agent 只准备操作卡片,不直接执行;补充权限、回放、历史令牌与实际部署参数回归。
This commit is contained in:
@@ -308,6 +308,27 @@ describe('DeployExecutionService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('passes an immutable historical commit through the real deployment workflow', async () => {
|
||||
const { repository, service, jenkins } = createService({
|
||||
jenkinsHealth: { status: 'ok' },
|
||||
notificationStatus: 'sent',
|
||||
});
|
||||
const { run } = await repository.create({
|
||||
...input,
|
||||
idempotencyKey: 'pinned-rollback',
|
||||
resolvedCommit: 'a'.repeat(40),
|
||||
operationKind: 'rollback',
|
||||
sourceRunId: 'historical-run',
|
||||
});
|
||||
await service.execute(run, project);
|
||||
expect(jenkins.buildWithParameters).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.objectContaining({ DEPLOY_COMMIT: 'a'.repeat(40) }),
|
||||
);
|
||||
expect(
|
||||
(await repository.findByOperationKey('pinned-rollback'))?.resolvedCommit,
|
||||
).toBe('a'.repeat(40));
|
||||
});
|
||||
it('syncs a queued Jenkins run to success', async () => {
|
||||
const { audit, repository, service } = createService({
|
||||
jenkinsHealth: { status: 'ok' },
|
||||
|
||||
@@ -924,6 +924,7 @@ export class DeployExecutionService {
|
||||
PROJECT_KEY: run.projectKey,
|
||||
DEPLOY_ENVIRONMENT: run.environment,
|
||||
GIT_REF: run.ref,
|
||||
...(run.resolvedCommit ? { DEPLOY_COMMIT: run.resolvedCommit } : {}),
|
||||
...(environment.releasePolicy === 'tag' ? { RELEASE_TAG: run.ref } : {}),
|
||||
OPERATOR: run.operator,
|
||||
};
|
||||
|
||||
@@ -62,6 +62,9 @@ type DeployRunMetadata = Prisma.InputJsonObject & {
|
||||
jenkinsBuildUrl?: string;
|
||||
remark?: string;
|
||||
productionConfirmation?: Prisma.InputJsonObject;
|
||||
resolvedCommit?: string;
|
||||
operationKind?: 'deploy' | 'rollback' | 'retry';
|
||||
sourceRunId?: string;
|
||||
};
|
||||
|
||||
type RunStepMetadata = Prisma.InputJsonObject & {
|
||||
@@ -313,6 +316,77 @@ export class DeployRunRepository {
|
||||
return run ? this.toSummary(run) : null;
|
||||
}
|
||||
|
||||
async findByOperationKey(key: string): Promise<DeployRunSummary | null> {
|
||||
if (!this.useDatabase())
|
||||
return this.memoryRuns.find((run) => run.id === key) ?? null;
|
||||
const record = await this.findRecordByIdempotencyKey(key);
|
||||
return record ? this.toSummary(record) : null;
|
||||
}
|
||||
|
||||
async findOperationRuns(
|
||||
projectKey: string,
|
||||
environment: 'test' | 'production',
|
||||
): Promise<DeployRunSummary[]> {
|
||||
const sort = (runs: DeployRunSummary[]) =>
|
||||
runs.sort(
|
||||
(a, b) =>
|
||||
Date.parse(b.startedAt || b.createdAt) -
|
||||
Date.parse(a.startedAt || a.createdAt),
|
||||
);
|
||||
if (!this.useDatabase())
|
||||
return sort(
|
||||
this.memoryRuns.filter(
|
||||
(run) =>
|
||||
run.projectKey === projectKey && run.environment === environment,
|
||||
),
|
||||
).slice(0, 25);
|
||||
const where = {
|
||||
project: { key: projectKey },
|
||||
environment: {
|
||||
name:
|
||||
environment === 'test'
|
||||
? EnvironmentKind.TEST
|
||||
: EnvironmentKind.PRODUCTION,
|
||||
},
|
||||
};
|
||||
const include = {
|
||||
project: true,
|
||||
environment: true,
|
||||
steps: { orderBy: { order: 'asc' as const }, take: 12 },
|
||||
} as const;
|
||||
const [recent, active] = await Promise.all([
|
||||
this.prisma.deployRun.findMany({
|
||||
where,
|
||||
include,
|
||||
orderBy: [{ startedAt: 'desc' }, { createdAt: 'desc' }],
|
||||
take: 20,
|
||||
}),
|
||||
this.prisma.deployRun.findMany({
|
||||
where: {
|
||||
...where,
|
||||
status: {
|
||||
in: [
|
||||
PrismaDeployRunStatus.PENDING,
|
||||
PrismaDeployRunStatus.QUEUED,
|
||||
PrismaDeployRunStatus.RUNNING,
|
||||
],
|
||||
},
|
||||
},
|
||||
include,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 5,
|
||||
}),
|
||||
]);
|
||||
return sort([
|
||||
...new Map(
|
||||
[...recent, ...active].map((record) => [
|
||||
record.id,
|
||||
this.toSummary(record),
|
||||
]),
|
||||
).values(),
|
||||
]);
|
||||
}
|
||||
|
||||
async findByJenkinsBuild(
|
||||
projectKey: string,
|
||||
environment: DeployRunSummary['environment'],
|
||||
@@ -825,6 +899,9 @@ export class DeployRunRepository {
|
||||
projectKey: input.projectKey,
|
||||
environment: input.environment,
|
||||
ref: input.ref,
|
||||
resolvedCommit: input.resolvedCommit,
|
||||
operationKind: input.operationKind,
|
||||
sourceRunId: input.sourceRunId,
|
||||
status: 'pending',
|
||||
trigger: input.trigger ?? 'manual',
|
||||
operator: input.operator,
|
||||
@@ -1015,6 +1092,9 @@ export class DeployRunRepository {
|
||||
projectKey: run.project.key,
|
||||
environment: run.environment.name === 'TEST' ? 'test' : 'production',
|
||||
ref: run.ref,
|
||||
resolvedCommit: metadata.resolvedCommit,
|
||||
operationKind: metadata.operationKind,
|
||||
sourceRunId: metadata.sourceRunId,
|
||||
status: run.status.toLowerCase() as DeployRunStatus,
|
||||
trigger: run.trigger.toLowerCase() as DeployRunSummary['trigger'],
|
||||
operator: run.operator,
|
||||
@@ -1058,6 +1138,9 @@ export class DeployRunRepository {
|
||||
|
||||
private inputMetadata(input: CreateDeployRunInput): Prisma.InputJsonObject {
|
||||
const metadata: DeployRunMetadata = {};
|
||||
if (input.resolvedCommit) metadata.resolvedCommit = input.resolvedCommit;
|
||||
if (input.operationKind) metadata.operationKind = input.operationKind;
|
||||
if (input.sourceRunId) metadata.sourceRunId = input.sourceRunId;
|
||||
|
||||
if (input.remark) {
|
||||
metadata.remark = input.remark;
|
||||
|
||||
@@ -37,6 +37,9 @@ export type DeployRunSummary = {
|
||||
startedAt?: string;
|
||||
finishedAt?: string;
|
||||
createdAt: string;
|
||||
resolvedCommit?: string;
|
||||
operationKind?: 'deploy' | 'rollback' | 'retry';
|
||||
sourceRunId?: string;
|
||||
steps: DeployRunStepSummary[];
|
||||
};
|
||||
|
||||
@@ -55,6 +58,9 @@ export type CreateDeployRunInput = {
|
||||
idempotencyKey?: string;
|
||||
trigger?: DeployRunSummary['trigger'];
|
||||
productionConfirmation?: ProductionDeployConfirmation;
|
||||
resolvedCommit?: string;
|
||||
operationKind?: 'deploy' | 'rollback' | 'retry';
|
||||
sourceRunId?: string;
|
||||
};
|
||||
|
||||
export type DeployRunJenkinsSyncError = {
|
||||
|
||||
Reference in New Issue
Block a user