fix: 对齐生产标签参数与助手当地日期
- 按标签发布时将所选版本传入 RELEASE_TAG,直构记录优先读取实际标签。 - 为模型明确提供上海当地日期,避免跨日后把 UTC 日期当作今天。 - 增加真实标签契约与跨日查询回归。
This commit is contained in:
@@ -276,6 +276,38 @@ describe('DeployExecutionService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('sends the selected tag through RELEASE_TAG for production tag jobs', async () => {
|
||||
const { repository, service, jenkins } = createService({
|
||||
jenkinsHealth: { status: 'ok' },
|
||||
notificationStatus: 'sent',
|
||||
});
|
||||
const tagProject: ProjectSummary = {
|
||||
...project,
|
||||
environments: [
|
||||
{
|
||||
...project.environments[0],
|
||||
name: 'production',
|
||||
releasePolicy: 'tag',
|
||||
jenkinsJobPath: 'prod/access-manage-tag',
|
||||
},
|
||||
],
|
||||
};
|
||||
const { run } = await repository.create({
|
||||
...input,
|
||||
environment: 'production',
|
||||
ref: 'v2026.10.28-stellar.1',
|
||||
idempotencyKey: 'tag-contract',
|
||||
});
|
||||
await service.execute(run, tagProject);
|
||||
expect(jenkins.buildWithParameters).toHaveBeenCalledWith(
|
||||
'prod/access-manage-tag',
|
||||
expect.objectContaining({
|
||||
GIT_REF: 'v2026.10.28-stellar.1',
|
||||
RELEASE_TAG: 'v2026.10.28-stellar.1',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('syncs a queued Jenkins run to success', async () => {
|
||||
const { audit, repository, service } = createService({
|
||||
jenkinsHealth: { status: 'ok' },
|
||||
|
||||
@@ -534,7 +534,7 @@ export class DeployExecutionService {
|
||||
let currentRun = await this.markStep(run, 'jenkins-build', 'running');
|
||||
const queueItem = await this.jenkinsClient.buildWithParameters(
|
||||
environment.jenkinsJobPath,
|
||||
this.buildParameters(run),
|
||||
this.buildParameters(run, environment),
|
||||
);
|
||||
const nextStatus = queueItem.buildNumber ? 'running' : 'queued';
|
||||
currentRun = this.requireRun(
|
||||
@@ -569,7 +569,7 @@ export class DeployExecutionService {
|
||||
queueId: queueItem.queueId,
|
||||
buildNumber: queueItem.buildNumber,
|
||||
},
|
||||
parameterDigest: this.buildParameters(run),
|
||||
parameterDigest: this.buildParameters(run, environment),
|
||||
});
|
||||
|
||||
return { run: currentRun, shouldContinue: false };
|
||||
@@ -696,12 +696,12 @@ export class DeployExecutionService {
|
||||
currentRun.id,
|
||||
await this.deployRunRepository.updateRun(
|
||||
currentRun.id,
|
||||
{
|
||||
status: 'success',
|
||||
finishedAt,
|
||||
},
|
||||
currentRun.version,
|
||||
),
|
||||
{
|
||||
status: 'success',
|
||||
finishedAt,
|
||||
},
|
||||
currentRun.version,
|
||||
),
|
||||
);
|
||||
|
||||
await this.auditService.record({
|
||||
@@ -915,12 +915,16 @@ export class DeployExecutionService {
|
||||
return environment;
|
||||
}
|
||||
|
||||
private buildParameters(run: DeployRunSummary): Record<string, string> {
|
||||
private buildParameters(
|
||||
run: DeployRunSummary,
|
||||
environment: ProjectEnvironmentSummary,
|
||||
): Record<string, string> {
|
||||
return {
|
||||
DEPLOY_RUN_ID: run.id,
|
||||
PROJECT_KEY: run.projectKey,
|
||||
DEPLOY_ENVIRONMENT: run.environment,
|
||||
GIT_REF: run.ref,
|
||||
...(environment.releasePolicy === 'tag' ? { RELEASE_TAG: run.ref } : {}),
|
||||
OPERATOR: run.operator,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1009,6 +1009,42 @@ describe('DeployRunsService', () => {
|
||||
expect(audit.record).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('uses the actual RELEASE_TAG when importing a tag job with a stale default GIT_REF', async () => {
|
||||
const tagProject: ProjectSummary = {
|
||||
...project,
|
||||
environments: [
|
||||
{
|
||||
...project.environments[0],
|
||||
name: 'production',
|
||||
releasePolicy: 'tag',
|
||||
},
|
||||
],
|
||||
};
|
||||
const { service, jenkins, repository } = createService({
|
||||
runs: [],
|
||||
project: tagProject,
|
||||
});
|
||||
jenkins.listRecentBuilds.mockResolvedValueOnce([
|
||||
{
|
||||
jobPath: 'prod/tag',
|
||||
buildNumber: 24,
|
||||
building: false,
|
||||
result: 'SUCCESS',
|
||||
parameters: {
|
||||
GIT_REF: 'develop',
|
||||
RELEASE_TAG: 'v2026.10.28-stellar.1',
|
||||
},
|
||||
},
|
||||
]);
|
||||
await service.importJenkinsBuilds(undefined, true);
|
||||
expect(repository.create).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
environment: 'production',
|
||||
ref: 'v2026.10.28-stellar.1',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('skips Jenkins builds whose platform parameters point to another environment', async () => {
|
||||
const { jenkins, repository, service } = createService();
|
||||
jenkins.listRecentBuilds.mockResolvedValueOnce([
|
||||
|
||||
@@ -752,7 +752,11 @@ export class DeployRunsService {
|
||||
environment: ProjectEnvironmentSummary,
|
||||
build: JenkinsRecentBuild,
|
||||
): { ref: string; source: string } {
|
||||
for (const parameterName of jenkinsExternalRefParameterNames) {
|
||||
const parameterNames =
|
||||
environment.releasePolicy === 'tag'
|
||||
? ['RELEASE_TAG', 'TAG_NAME', ...jenkinsExternalRefParameterNames]
|
||||
: jenkinsExternalRefParameterNames;
|
||||
for (const parameterName of parameterNames) {
|
||||
const parameterValue = this.trimOptional(build.parameters[parameterName]);
|
||||
|
||||
if (parameterValue) {
|
||||
|
||||
Reference in New Issue
Block a user