diff --git a/ci/jenkins/KT-NapCatQQ-Runtime-Release.Jenkinsfile b/ci/jenkins/KT-NapCatQQ-Runtime-Release.Jenkinsfile index 86be13b..1ee9863 100644 --- a/ci/jenkins/KT-NapCatQQ-Runtime-Release.Jenkinsfile +++ b/ci/jenkins/KT-NapCatQQ-Runtime-Release.Jenkinsfile @@ -46,9 +46,6 @@ pipeline { } steps { script { - if (params.CONFIRM_API_PROMOTION_TARGET != 'PROMOTE_KT_TEMPLATE_API_MAIN') { - error('CONFIRM_API_PROMOTION_TARGET must equal PROMOTE_KT_TEMPLATE_API_MAIN before API promotion runs.') - } requireRuntimeOverrides( params.QQBOT_NAPCAT_IMAGE_OVERRIDE, params.QQBOT_NAPCAT_DESKTOP_PROFILE_VERSION_OVERRIDE @@ -72,6 +69,9 @@ pipeline { } steps { script { + if (params.CONFIRM_API_PROMOTION_TARGET != 'PROMOTE_KT_TEMPLATE_API_MAIN') { + error('CONFIRM_API_PROMOTION_TARGET must equal PROMOTE_KT_TEMPLATE_API_MAIN before API promotion runs.') + } requireRuntimeOverrides( params.QQBOT_NAPCAT_IMAGE_OVERRIDE, params.QQBOT_NAPCAT_DESKTOP_PROFILE_VERSION_OVERRIDE diff --git a/src/selfTest.ts b/src/selfTest.ts index 3f12f9f..91f982f 100644 --- a/src/selfTest.ts +++ b/src/selfTest.ts @@ -524,6 +524,62 @@ export async function runSelfTest(): Promise { ); } } + const runtimeImageBuildStageStart = runtimeReleaseJenkinsTemplate.indexOf( + "stage('Runtime image build and publish')", + ); + const apiPromotionStageStart = runtimeReleaseJenkinsTemplate.indexOf( + "stage('API promotion')", + ); + const pipelineEndBeforeRuntimeHelpers = runtimeReleaseJenkinsTemplate.indexOf( + "\n}\n\n/**", + apiPromotionStageStart, + ); + if ( + runtimeImageBuildStageStart === -1 || + apiPromotionStageStart === -1 || + pipelineEndBeforeRuntimeHelpers === -1 || + runtimeImageBuildStageStart > apiPromotionStageStart + ) { + throw new Error("NapCat runtime Jenkins template stage slice self-check failed"); + } + const runtimeImageBuildStage = runtimeReleaseJenkinsTemplate.slice( + runtimeImageBuildStageStart, + apiPromotionStageStart, + ); + const apiPromotionStage = runtimeReleaseJenkinsTemplate.slice( + apiPromotionStageStart, + pipelineEndBeforeRuntimeHelpers, + ); + if (runtimeImageBuildStage.includes("CONFIRM_API_PROMOTION_TARGET")) { + throw new Error( + "NapCat runtime Jenkins runtime image build stage must not check API promotion confirmation", + ); + } + if (!apiPromotionStage.includes("CONFIRM_API_PROMOTION_TARGET")) { + throw new Error( + "NapCat runtime Jenkins API promotion stage missing confirmation target check", + ); + } + if (!apiPromotionStage.includes("PROMOTE_KT_TEMPLATE_API_MAIN")) { + throw new Error( + "NapCat runtime Jenkins API promotion stage missing production confirmation value", + ); + } + const apiPromotionConfirmationIndex = apiPromotionStage.indexOf( + "CONFIRM_API_PROMOTION_TARGET", + ); + const apiPromotionBuildIndex = apiPromotionStage.indexOf( + "build job: params.API_PROMOTION_JOB", + ); + if ( + apiPromotionConfirmationIndex === -1 || + apiPromotionBuildIndex === -1 || + apiPromotionConfirmationIndex > apiPromotionBuildIndex + ) { + throw new Error( + "NapCat runtime Jenkins API promotion confirmation must run before API build job", + ); + } const codexExecutionArtifactRoot = resolveInsideRoot( ".kt-workspace/test-artifacts/napcat-codex-runner-self-test", );