@catladder/pipeline 1.144.1 → 1.146.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bash/BashExpression.d.ts +40 -0
- package/dist/bash/BashExpression.js +124 -0
- package/dist/bash/bashExpressionPerPipelineType.d.ts +6 -0
- package/dist/bash/bashExpressionPerPipelineType.js +11 -0
- package/dist/bash/bashYaml.d.ts +10 -0
- package/dist/bash/bashYaml.js +46 -0
- package/dist/bash/getInjectVarsScript.d.ts +2 -0
- package/dist/bash/getInjectVarsScript.js +45 -0
- package/dist/bash/replaceAsync.d.ts +2 -0
- package/dist/{pipeline/commitInfo/getCommitInfo.js → bash/replaceAsync.js} +49 -21
- package/dist/build/base/__tests__/createArtifactsConfig.test.js +3 -1
- package/dist/build/base/constants.js +3 -1
- package/dist/build/base/createAppBuildJob.d.ts +2 -1
- package/dist/build/base/createAppBuildJob.js +10 -6
- package/dist/build/base/createArtifactsConfig.d.ts +1 -1
- package/dist/build/base/createArtifactsConfig.js +3 -1
- package/dist/build/base/index.js +3 -1
- package/dist/build/base/writeBuildInfo.js +4 -3
- package/dist/build/base/writeDotEnv.js +12 -3
- package/dist/build/custom/__tests__/testJob.test.js +3 -1
- package/dist/build/custom/buildJob.js +4 -12
- package/dist/build/custom/index.js +3 -1
- package/dist/build/custom/testJob.d.ts +1 -1
- package/dist/build/custom/testJob.js +18 -14
- package/dist/build/docker.d.ts +5 -31
- package/dist/build/docker.js +16 -9
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +13 -7
- package/dist/build/node/buildJob.js +4 -12
- package/dist/build/node/cache.js +6 -3
- package/dist/build/node/constants.js +3 -1
- package/dist/build/node/index.js +3 -1
- package/dist/build/node/meteor.js +5 -2
- package/dist/build/node/testJob.js +18 -14
- package/dist/build/node/yarn.d.ts +3 -2
- package/dist/build/node/yarn.js +6 -3
- package/dist/build/rails/build.js +3 -1
- package/dist/build/rails/index.js +3 -1
- package/dist/build/rails/test.js +15 -11
- package/dist/build/sbom.js +3 -1
- package/dist/build/types.d.ts +24 -18
- package/dist/build/types.js +3 -1
- package/dist/bundles/catladder-gitlab/index.js +3 -3
- package/dist/catladder-gitlab.js +10 -54
- package/dist/config/__tests__/configruedEnvs.test.js +3 -1
- package/dist/config/configruedEnvs.js +3 -1
- package/dist/config/index.js +13 -7
- package/dist/config/readConfig.js +6 -5
- package/dist/constants.js +5 -3
- package/dist/context/__tests__/resolveReferences.test.js +40 -8
- package/dist/context/getBuildInfoVariables.d.ts +7 -0
- package/dist/context/getBuildInfoVariables.js +29 -0
- package/dist/context/getEnvConfig.js +3 -1
- package/dist/context/getEnvType.js +3 -1
- package/dist/context/getEnvironment.d.ts +3 -3
- package/dist/context/getEnvironment.js +10 -14
- package/dist/context/getEnvironmentContext.d.ts +7 -3
- package/dist/context/getEnvironmentContext.js +21 -11
- package/dist/context/getEnvironmentVariables.d.ts +26 -5
- package/dist/context/getEnvironmentVariables.js +40 -25
- package/dist/context/getLabels.js +4 -2
- package/dist/context/getReviewSlug.d.ts +4 -0
- package/dist/context/getReviewSlug.js +22 -0
- package/dist/context/index.d.ts +12 -3
- package/dist/context/index.js +21 -15
- package/dist/context/resolveReferences.d.ts +3 -1
- package/dist/context/resolveReferences.js +53 -21
- package/dist/context/transformJobOnlyVars.d.ts +5 -2
- package/dist/context/transformJobOnlyVars.js +4 -2
- package/dist/context/utils/envVars.d.ts +1 -1
- package/dist/context/utils/envVars.js +5 -2
- package/dist/defaults/index.js +3 -1
- package/dist/deploy/base/deploy.d.ts +1 -1
- package/dist/deploy/base/deploy.js +12 -11
- package/dist/deploy/base/index.js +3 -1
- package/dist/deploy/base/rollback.d.ts +1 -1
- package/dist/deploy/base/rollback.js +13 -9
- package/dist/deploy/base/stop.d.ts +1 -1
- package/dist/deploy/base/stop.js +16 -11
- package/dist/deploy/base/types.d.ts +1 -1
- package/dist/deploy/base/types.js +3 -1
- package/dist/deploy/base/variables.js +3 -1
- package/dist/deploy/cloudRun/artifactsRegistry.d.ts +2 -1
- package/dist/deploy/cloudRun/artifactsRegistry.js +6 -4
- package/dist/deploy/cloudRun/cleanup.js +3 -1
- package/dist/deploy/cloudRun/cloudRunRevisions.js +3 -1
- package/dist/deploy/cloudRun/createJobs/cloudRunJobs.js +8 -5
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +2 -2
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +6 -3
- package/dist/deploy/cloudRun/createJobs/common.d.ts +3 -3
- package/dist/deploy/cloudRun/createJobs/common.js +3 -1
- package/dist/deploy/cloudRun/createJobs/constants.d.ts +1 -0
- package/dist/deploy/cloudRun/createJobs/constants.js +7 -0
- package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +10 -4
- package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +3 -1
- package/dist/deploy/cloudRun/createJobs/index.js +25 -8
- package/dist/deploy/cloudRun/createJobs/volumes.js +3 -1
- package/dist/deploy/cloudRun/index.js +5 -3
- package/dist/deploy/cloudRun/utils/createArgsString.d.ts +2 -1
- package/dist/deploy/cloudRun/utils/createArgsString.js +3 -1
- package/dist/deploy/cloudRun/utils/database.js +13 -13
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +3 -1
- package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
- package/dist/deploy/cloudRun/utils/getServiceName.js +3 -1
- package/dist/deploy/cloudRun/utils/jobName.d.ts +2 -1
- package/dist/deploy/cloudRun/utils/jobName.js +4 -2
- package/dist/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.js +3 -1
- package/dist/deploy/cloudSql/utils.d.ts +2 -1
- package/dist/deploy/cloudSql/utils.js +7 -2
- package/dist/deploy/custom/deployJob.js +3 -1
- package/dist/deploy/custom/index.js +3 -1
- package/dist/deploy/dockerTag/deployJob.js +3 -1
- package/dist/deploy/dockerTag/index.js +3 -1
- package/dist/deploy/index.d.ts +4 -3
- package/dist/deploy/index.js +13 -7
- package/dist/deploy/kubernetes/additionalSecretKeys.js +3 -1
- package/dist/deploy/kubernetes/cloudSql/index.d.ts +3 -2
- package/dist/deploy/kubernetes/cloudSql/index.js +6 -4
- package/dist/deploy/kubernetes/deployJob.js +22 -15
- package/dist/deploy/kubernetes/index.js +51 -14
- package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -2
- package/dist/deploy/kubernetes/kubeEnv.js +7 -4
- package/dist/deploy/kubernetes/kubeValues.d.ts +2 -2
- package/dist/deploy/kubernetes/kubeValues.js +4 -5
- package/dist/deploy/kubernetes/mongodb.js +3 -1
- package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +2 -1
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +3 -1
- package/dist/deploy/sbom.js +3 -1
- package/dist/deploy/types/base.d.ts +8 -2
- package/dist/deploy/types/base.js +3 -1
- package/dist/deploy/types/custom.d.ts +1 -1
- package/dist/deploy/types/custom.js +3 -1
- package/dist/deploy/types/dockerTag.d.ts +1 -1
- package/dist/deploy/types/dockerTag.js +3 -1
- package/dist/deploy/types/googleCloudRun.d.ts +19 -18
- package/dist/deploy/types/googleCloudRun.js +3 -1
- package/dist/deploy/types/index.d.ts +6 -6
- package/dist/deploy/types/index.js +13 -7
- package/dist/deploy/types/kubernetes.d.ts +22 -22
- package/dist/deploy/types/kubernetes.js +3 -1
- package/dist/deploy/utils.js +3 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +16 -9
- package/dist/packageInfos.d.ts +2 -0
- package/dist/packageInfos.js +14 -0
- package/dist/pipeline/createAllJobs.d.ts +13 -5
- package/dist/pipeline/createAllJobs.js +21 -10
- package/dist/pipeline/createChildPipeline.d.ts +1 -1
- package/dist/pipeline/createChildPipeline.js +24 -7
- package/dist/pipeline/createJobsForComponent.d.ts +3 -3
- package/dist/pipeline/createJobsForComponent.js +19 -18
- package/dist/pipeline/createMainPipeline.d.ts +3 -0
- package/dist/pipeline/createMainPipeline.js +248 -0
- package/dist/pipeline/generatePipelineFiles.d.ts +2 -0
- package/dist/pipeline/generatePipelineFiles.js +178 -0
- package/dist/pipeline/getPipelineStages.js +3 -1
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +15 -5
- package/dist/pipeline/gitlab/createGitlabJobs.js +98 -25
- package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +7 -2
- package/dist/pipeline/gitlab/createGitlabPipeline.js +34 -17
- package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +1 -0
- package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +29 -0
- package/dist/pipeline/gitlab/gitlabReleaseJobs.d.ts +33 -0
- package/dist/pipeline/gitlab/gitlabReleaseJobs.js +24 -0
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +16 -8
- package/dist/pipeline/packageManager.js +4 -2
- package/dist/pipeline/yarn/yarnUtils.js +6 -4
- package/dist/rules/index.d.ts +4 -1
- package/dist/rules/index.js +25 -18
- package/dist/runner/index.d.ts +1 -1
- package/dist/runner/index.js +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +18 -15
- package/dist/types/config.js +5 -2
- package/dist/types/context.d.ts +37 -32
- package/dist/types/context.js +3 -1
- package/dist/types/environmentContext.d.ts +11 -7
- package/dist/types/environmentContext.js +3 -1
- package/dist/types/gitlab-ci-yml.d.ts +30 -30
- package/dist/types/gitlab-ci-yml.js +3 -2
- package/dist/types/gitlab-types.d.ts +4 -6
- package/dist/types/gitlab-types.js +3 -1
- package/dist/types/index.js +13 -7
- package/dist/types/jobs.d.ts +23 -6
- package/dist/types/jobs.js +3 -1
- package/dist/types/pipeline.d.ts +4 -3
- package/dist/types/pipeline.js +3 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.js +3 -1
- package/dist/utils/gitlab.js +3 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/writeFiles.d.ts +7 -0
- package/dist/{pipeline/commitInfo/getBuildId.js → utils/writeFiles.js} +39 -22
- package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +480 -384
- package/examples/__snapshots__/cloud-run-meteor-with-worker.ts.snap +462 -366
- package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +480 -384
- package/examples/__snapshots__/cloud-run-no-service.ts.snap +501 -393
- package/examples/__snapshots__/cloud-run-non-public.ts.snap +480 -384
- package/examples/__snapshots__/cloud-run-post-stop-job.ts.snap +489 -392
- package/examples/__snapshots__/cloud-run-service-gen2.ts.snap +480 -384
- package/examples/__snapshots__/cloud-run-service-with-volumes.ts.snap +501 -401
- package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +1155 -915
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +1116 -888
- package/examples/__snapshots__/cloud-run-with-worker.ts.snap +482 -386
- package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +452 -356
- package/examples/__snapshots__/custom-build-job.ts.snap +434 -350
- package/examples/__snapshots__/custom-deploy.ts.snap +319 -223
- package/examples/__snapshots__/custom-envs.ts.snap +123 -81
- package/examples/__snapshots__/custom-sbom-java.ts.snap +434 -350
- package/examples/__snapshots__/kubernetes-application-customization.ts.snap +846 -969
- package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +886 -957
- package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +894 -969
- package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +1626 -1728
- package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +974 -1137
- package/examples/__snapshots__/local-dot-env.ts.snap +480 -384
- package/examples/__snapshots__/meteor-kubernetes.ts.snap +906 -1069
- package/examples/__snapshots__/multiline-var.ts.snap +4500 -0
- package/examples/__snapshots__/native-app.ts.snap +706 -578
- package/examples/__snapshots__/node-build-with-custom-image.ts.snap +480 -384
- package/examples/__snapshots__/node-build-with-docker-additions.ts.snap +488 -384
- package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1656 -1942
- package/examples/__snapshots__/wait-for-other-deploy.ts.snap +287 -231
- package/examples/__utils__/helpers.ts +2 -2
- package/examples/custom-deploy.ts +7 -7
- package/examples/multiline-var.ts +64 -0
- package/package.json +5 -8
- package/scripts/generate-gitlab-ci-types.ts +2 -2
- package/src/bash/BashExpression.ts +81 -0
- package/src/bash/bashExpressionPerPipelineType.ts +16 -0
- package/src/bash/bashYaml.ts +46 -0
- package/src/bash/getInjectVarsScript.ts +12 -0
- package/src/bash/replaceAsync.ts +50 -0
- package/src/build/base/__tests__/createArtifactsConfig.test.ts +3 -3
- package/src/build/base/createAppBuildJob.ts +8 -4
- package/src/build/base/createArtifactsConfig.ts +2 -2
- package/src/build/base/index.ts +1 -1
- package/src/build/base/writeBuildInfo.ts +1 -1
- package/src/build/base/writeDotEnv.ts +6 -1
- package/src/build/custom/__tests__/testJob.test.ts +1 -1
- package/src/build/custom/buildJob.ts +4 -6
- package/src/build/custom/testJob.ts +6 -5
- package/src/build/docker.ts +21 -13
- package/src/build/index.ts +1 -1
- package/src/build/node/buildJob.ts +3 -5
- package/src/build/node/cache.ts +4 -4
- package/src/build/node/meteor.ts +1 -1
- package/src/build/node/testJob.ts +6 -5
- package/src/build/node/yarn.ts +14 -9
- package/src/build/rails/test.ts +2 -1
- package/src/build/types.ts +8 -1
- package/src/catladder-gitlab.ts +8 -55
- package/src/config/configruedEnvs.ts +6 -6
- package/src/config/readConfig.ts +4 -5
- package/src/constants.ts +5 -2
- package/src/context/__tests__/resolveReferences.test.ts +11 -6
- package/src/context/getBuildInfoVariables.ts +40 -0
- package/src/context/getEnvConfig.ts +1 -1
- package/src/context/getEnvType.ts +1 -1
- package/src/context/getEnvironment.ts +7 -30
- package/src/context/getEnvironmentContext.ts +25 -29
- package/src/context/getEnvironmentVariables.ts +72 -47
- package/src/context/getReviewSlug.ts +27 -0
- package/src/context/index.ts +26 -25
- package/src/context/resolveReferences.ts +40 -17
- package/src/context/transformJobOnlyVars.ts +6 -3
- package/src/context/utils/envVars.ts +5 -4
- package/src/deploy/base/deploy.ts +25 -23
- package/src/deploy/base/index.ts +1 -1
- package/src/deploy/base/rollback.ts +9 -11
- package/src/deploy/base/stop.ts +9 -10
- package/src/deploy/cloudRun/artifactsRegistry.ts +13 -8
- package/src/deploy/cloudRun/cleanup.ts +3 -3
- package/src/deploy/cloudRun/cloudRunRevisions.ts +3 -3
- package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +22 -17
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +7 -6
- package/src/deploy/cloudRun/createJobs/common.ts +1 -1
- package/src/deploy/cloudRun/createJobs/constants.ts +1 -0
- package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +25 -7
- package/src/deploy/cloudRun/createJobs/getCloudRunStopScripts.ts +1 -1
- package/src/deploy/cloudRun/createJobs/index.ts +18 -9
- package/src/deploy/cloudRun/createJobs/volumes.ts +2 -2
- package/src/deploy/cloudRun/index.ts +22 -10
- package/src/deploy/cloudRun/utils/createArgsString.ts +3 -2
- package/src/deploy/cloudRun/utils/database.ts +7 -7
- package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +1 -1
- package/src/deploy/cloudRun/utils/jobName.ts +7 -2
- package/src/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.ts +1 -1
- package/src/deploy/cloudSql/utils.ts +13 -10
- package/src/deploy/index.ts +5 -4
- package/src/deploy/kubernetes/cloudSql/index.ts +6 -5
- package/src/deploy/kubernetes/deployJob.ts +28 -14
- package/src/deploy/kubernetes/index.ts +15 -8
- package/src/deploy/kubernetes/kubeEnv.ts +9 -7
- package/src/deploy/kubernetes/kubeValues.ts +5 -6
- package/src/deploy/kubernetes/mongodb.ts +1 -1
- package/src/deploy/kubernetes/processSecretsAsFiles.ts +5 -4
- package/src/deploy/types/base.ts +6 -0
- package/src/deploy/types/googleCloudRun.ts +2 -0
- package/src/deploy/utils.ts +2 -2
- package/src/index.ts +2 -1
- package/src/packageInfos.ts +10 -0
- package/src/pipeline/createAllJobs.ts +28 -14
- package/src/pipeline/createChildPipeline.ts +20 -9
- package/src/pipeline/createJobsForComponent.ts +15 -23
- package/src/pipeline/createMainPipeline.ts +91 -0
- package/src/pipeline/generatePipelineFiles.ts +29 -0
- package/src/pipeline/getPipelineStages.ts +1 -1
- package/src/pipeline/gitlab/createGitlabJobs.ts +182 -59
- package/src/pipeline/gitlab/createGitlabPipeline.ts +16 -14
- package/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.ts +46 -0
- package/src/pipeline/gitlab/gitlabReleaseJobs.ts +20 -0
- package/src/pipeline/index.ts +2 -0
- package/src/pipeline/packageManager.ts +2 -2
- package/src/pipeline/yarn/yarnUtils.ts +7 -7
- package/src/rules/index.ts +15 -9
- package/src/types/config.ts +12 -3
- package/src/types/context.ts +39 -26
- package/src/types/environmentContext.ts +13 -7
- package/src/types/gitlab-ci-yml.ts +0 -1
- package/src/types/gitlab-types.ts +5 -4
- package/src/types/jobs.ts +29 -4
- package/src/types/pipeline.ts +4 -0
- package/src/types/utils.ts +4 -4
- package/src/utils/gitlab.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/writeFiles.ts +40 -0
- package/dist/deploy/cloudRun/createJobs/variables.d.ts +0 -5
- package/dist/deploy/cloudRun/createJobs/variables.js +0 -19
- package/dist/pipeline/commitInfo/getBuildId.d.ts +0 -6
- package/dist/pipeline/commitInfo/getCommitInfo.d.ts +0 -2
- package/src/deploy/cloudRun/createJobs/variables.ts +0 -21
- package/src/pipeline/commitInfo/getBuildId.ts +0 -17
- package/src/pipeline/commitInfo/getCommitInfo.ts +0 -15
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { getAllEnvsByTrigger } from "../config";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
CatladderJobWithContext,
|
|
4
|
+
Config,
|
|
5
|
+
PipelineTrigger,
|
|
6
|
+
PipelineType,
|
|
7
|
+
} from "../types";
|
|
4
8
|
import { createJobsForComponent } from "./createJobsForComponent";
|
|
5
9
|
|
|
6
10
|
export type AllCatladderJobs = {
|
|
7
11
|
[componentName: string]: {
|
|
8
|
-
[env: string]: Array<
|
|
12
|
+
[env: string]: Array<CatladderJobWithContext>;
|
|
9
13
|
};
|
|
10
14
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
export type AllJobsContext = {
|
|
17
|
+
config: Config;
|
|
18
|
+
trigger: PipelineTrigger;
|
|
19
|
+
pipelineType: PipelineType;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const createAllJobs = async ({
|
|
23
|
+
config,
|
|
24
|
+
trigger,
|
|
25
|
+
pipelineType,
|
|
26
|
+
}: AllJobsContext): Promise<AllCatladderJobs> => {
|
|
15
27
|
return Object.fromEntries(
|
|
16
28
|
await Promise.all(
|
|
17
29
|
Object.keys(config.components).map(async (componentName) => {
|
|
@@ -22,17 +34,19 @@ export const createAllJobs = async (
|
|
|
22
34
|
await Promise.all(
|
|
23
35
|
envs.map(async (env) => [
|
|
24
36
|
env,
|
|
25
|
-
|
|
37
|
+
|
|
38
|
+
await createJobsForComponent({
|
|
26
39
|
config,
|
|
27
40
|
componentName,
|
|
28
41
|
env,
|
|
29
|
-
trigger
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
trigger,
|
|
43
|
+
pipelineType,
|
|
44
|
+
}),
|
|
45
|
+
]),
|
|
46
|
+
),
|
|
33
47
|
),
|
|
34
48
|
];
|
|
35
|
-
})
|
|
36
|
-
)
|
|
49
|
+
}),
|
|
50
|
+
),
|
|
37
51
|
);
|
|
38
52
|
};
|
|
@@ -1,24 +1,35 @@
|
|
|
1
|
+
import { RULES_ALWAYS } from "../rules";
|
|
2
|
+
|
|
1
3
|
import type { Pipeline, PipelineType } from "../types";
|
|
2
4
|
import type { Config, PipelineTrigger } from "../types/config";
|
|
3
5
|
import { createAllJobs } from "./createAllJobs";
|
|
4
6
|
import { getPipelineStages } from "./getPipelineStages";
|
|
5
7
|
import { createGitlabJobs } from "./gitlab/createGitlabJobs";
|
|
6
|
-
import {
|
|
8
|
+
import { createGitlabPipelineWithDefaults } from "./gitlab/createGitlabPipeline";
|
|
7
9
|
|
|
8
10
|
export const createChildPipeline = async <T extends PipelineType>(
|
|
9
|
-
|
|
11
|
+
pipelineType: T,
|
|
10
12
|
trigger: PipelineTrigger,
|
|
11
|
-
config: Config
|
|
13
|
+
config: Config,
|
|
12
14
|
): Promise<Pipeline<T>> => {
|
|
13
|
-
const jobs = await createAllJobs(
|
|
15
|
+
const jobs = await createAllJobs({
|
|
16
|
+
config,
|
|
17
|
+
trigger,
|
|
18
|
+
pipelineType,
|
|
19
|
+
});
|
|
14
20
|
const stages = getPipelineStages(config);
|
|
15
21
|
|
|
16
|
-
if (
|
|
22
|
+
if (pipelineType === "gitlab") {
|
|
17
23
|
const gitlabJobs = await createGitlabJobs(jobs);
|
|
18
|
-
return
|
|
24
|
+
return createGitlabPipelineWithDefaults({
|
|
25
|
+
workflow: {
|
|
26
|
+
rules: RULES_ALWAYS,
|
|
27
|
+
},
|
|
19
28
|
stages,
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
jobs: Object.fromEntries(
|
|
30
|
+
gitlabJobs.map(({ gitlabJob, name }) => [name, gitlabJob]),
|
|
31
|
+
),
|
|
32
|
+
}) as Pipeline<T>;
|
|
22
33
|
}
|
|
23
|
-
throw new Error(`${
|
|
34
|
+
throw new Error(`${pipelineType} is not supported`);
|
|
24
35
|
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { isFunction } from "lodash";
|
|
2
2
|
import { BUILD_TYPES } from "../build";
|
|
3
|
+
import type { CreateContextContext } from "../context";
|
|
3
4
|
import { createContext } from "../context";
|
|
4
5
|
import { DEPLOY_TYPES } from "../deploy";
|
|
5
|
-
import type {
|
|
6
|
-
import type { CommitInfo, Context } from "../types/context";
|
|
6
|
+
import type { CatladderJobWithContext, Context } from "../types/context";
|
|
7
7
|
import type { CatladderJob } from "../types/jobs";
|
|
8
|
-
import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
|
|
9
8
|
import { getPackageManagerInfo } from "./packageManager";
|
|
10
9
|
|
|
11
10
|
const injectDefaultVarsInCustomJobs = (
|
|
12
11
|
context: Context,
|
|
13
|
-
jobs: CatladderJob[]
|
|
12
|
+
jobs: CatladderJob[],
|
|
14
13
|
) =>
|
|
15
14
|
jobs.map(({ variables, ...job }) => ({
|
|
16
15
|
variables: {
|
|
@@ -39,25 +38,18 @@ const createRawJobs = (context: Context): CatladderJob[] => {
|
|
|
39
38
|
const customJobs = getCustomJobs(context);
|
|
40
39
|
return [...buildJobs, ...deployJobs, ...customJobs];
|
|
41
40
|
};
|
|
42
|
-
export const createJobsForComponent = async (
|
|
43
|
-
config: Config,
|
|
44
|
-
componentName: string,
|
|
45
|
-
env: string,
|
|
46
|
-
trigger: PipelineTrigger
|
|
47
|
-
): Promise<Array<CatladderJob>> => {
|
|
48
|
-
const commitInfo: CommitInfo = {
|
|
49
|
-
...(await getBaseCommitInfo()),
|
|
50
|
-
trigger,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const packageManagerInfo = await getPackageManagerInfo(config, componentName);
|
|
54
41
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
export const createJobsForComponent = async (
|
|
43
|
+
contextContext: Omit<CreateContextContext, "packageManagerInfo">,
|
|
44
|
+
): Promise<Array<CatladderJobWithContext>> => {
|
|
45
|
+
const packageManagerInfo = await getPackageManagerInfo(
|
|
46
|
+
contextContext.config,
|
|
47
|
+
contextContext.componentName,
|
|
61
48
|
);
|
|
62
|
-
|
|
49
|
+
|
|
50
|
+
const context = await createContext({
|
|
51
|
+
...contextContext,
|
|
52
|
+
packageManagerInfo,
|
|
53
|
+
});
|
|
54
|
+
return createRawJobs(context).map((job) => ({ ...job, context }));
|
|
63
55
|
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RULE_IS_MAIN_BRANCH,
|
|
3
|
+
RULE_IS_MERGE_REQUEST,
|
|
4
|
+
RULE_IS_TAGGED_RELEASE,
|
|
5
|
+
RULE_NEVER_ON_RELEASE_COMMIT,
|
|
6
|
+
} from "../rules";
|
|
7
|
+
import type {
|
|
8
|
+
GitlabJobDef,
|
|
9
|
+
GitlabRule,
|
|
10
|
+
Pipeline,
|
|
11
|
+
PipelineTrigger,
|
|
12
|
+
PipelineType,
|
|
13
|
+
} from "../types";
|
|
14
|
+
import { ALL_PIPELINE_TRIGGERS, type Config } from "../types/config";
|
|
15
|
+
import { createAllJobs } from "./createAllJobs";
|
|
16
|
+
import { getPipelineStages } from "./getPipelineStages";
|
|
17
|
+
import { createGitlabJobs } from "./gitlab/createGitlabJobs";
|
|
18
|
+
import { createGitlabPipelineWithDefaults } from "./gitlab/createGitlabPipeline";
|
|
19
|
+
import { getGitlabReleaseJobs } from "./gitlab/gitlabReleaseJobs";
|
|
20
|
+
|
|
21
|
+
export const createMainPipeline = async <T extends PipelineType>(
|
|
22
|
+
pipelineType: T,
|
|
23
|
+
config: Config,
|
|
24
|
+
): Promise<Pipeline<T>> => {
|
|
25
|
+
const stages = getPipelineStages(config);
|
|
26
|
+
|
|
27
|
+
if (pipelineType === "gitlab") {
|
|
28
|
+
// for all triggers create jobs and add base rules
|
|
29
|
+
|
|
30
|
+
const allJobsPerTrigger = await Promise.all(
|
|
31
|
+
ALL_PIPELINE_TRIGGERS.map(
|
|
32
|
+
async (trigger) =>
|
|
33
|
+
await createGitlabJobs(
|
|
34
|
+
await createAllJobs({ config, trigger, pipelineType }),
|
|
35
|
+
getGitlabRulesForTrigger(trigger),
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const allJobs = allJobsPerTrigger
|
|
41
|
+
.flat()
|
|
42
|
+
// sort by componentName in the same order as they appear in the config
|
|
43
|
+
// this is purely for better readability in git diffs when you add new components
|
|
44
|
+
.sort((a, b) => {
|
|
45
|
+
const componentNames = Object.keys(config.components);
|
|
46
|
+
const aIndex = componentNames.findIndex((c) => c === a.componentName);
|
|
47
|
+
const bIndex = componentNames.findIndex((c) => c === b.componentName);
|
|
48
|
+
return aIndex - bIndex;
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
.reduce(
|
|
52
|
+
(acc, { gitlabJob, name }) => {
|
|
53
|
+
// merge jobs, if a job is already there, merge the rules
|
|
54
|
+
// this is currently needed because of envMode: "none", which creates the same job for all triggers, so it can appear multiple times
|
|
55
|
+
if (acc[name]) {
|
|
56
|
+
acc[name].rules = [
|
|
57
|
+
...(acc[name].rules ?? []),
|
|
58
|
+
...(gitlabJob.rules ?? []),
|
|
59
|
+
];
|
|
60
|
+
} else {
|
|
61
|
+
acc[name] = gitlabJob;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return acc;
|
|
65
|
+
},
|
|
66
|
+
{} as { [key: string]: GitlabJobDef },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return createGitlabPipelineWithDefaults({
|
|
70
|
+
stages: [...stages, "release"],
|
|
71
|
+
jobs: {
|
|
72
|
+
...allJobs,
|
|
73
|
+
...getGitlabReleaseJobs(),
|
|
74
|
+
},
|
|
75
|
+
}) as Pipeline<T>;
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`${pipelineType} is not supported`);
|
|
78
|
+
};
|
|
79
|
+
function getGitlabRulesForTrigger(trigger: PipelineTrigger): GitlabRule[] {
|
|
80
|
+
// mainBranch: on push to main branch
|
|
81
|
+
// mr: on merge request
|
|
82
|
+
// taggedRelease: on tag
|
|
83
|
+
switch (trigger) {
|
|
84
|
+
case "mainBranch":
|
|
85
|
+
return [RULE_NEVER_ON_RELEASE_COMMIT, RULE_IS_MAIN_BRANCH];
|
|
86
|
+
case "mr":
|
|
87
|
+
return [RULE_IS_MERGE_REQUEST];
|
|
88
|
+
case "taggedRelease":
|
|
89
|
+
return [RULE_IS_TAGGED_RELEASE];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Config, PipelineMode, PipelineType } from "../types";
|
|
2
|
+
import { writeYamlfile } from "../utils/writeFiles";
|
|
3
|
+
import { createChildPipeline } from "./createChildPipeline";
|
|
4
|
+
import { createMainPipeline } from "./createMainPipeline";
|
|
5
|
+
import { getPipelineTriggerForGitlabChildPipeline } from "./gitlab/getPipelineTriggerForGitlabChildPipeline";
|
|
6
|
+
export async function generatePipelineFiles<T extends PipelineType>(
|
|
7
|
+
config: Config,
|
|
8
|
+
pipelineType: T,
|
|
9
|
+
mode: PipelineMode<T>,
|
|
10
|
+
) {
|
|
11
|
+
if (mode === "childpipeline") {
|
|
12
|
+
const trigger = getPipelineTriggerForGitlabChildPipeline();
|
|
13
|
+
|
|
14
|
+
const { jobs, ...mainPipeline } = await createChildPipeline(
|
|
15
|
+
pipelineType,
|
|
16
|
+
trigger,
|
|
17
|
+
config,
|
|
18
|
+
);
|
|
19
|
+
// need to spread out the jobs, forgot why
|
|
20
|
+
await writeYamlfile(`__pipeline.yml`, { ...jobs, ...mainPipeline });
|
|
21
|
+
} else {
|
|
22
|
+
const { jobs, ...mainPipeline } = await createMainPipeline(
|
|
23
|
+
pipelineType,
|
|
24
|
+
config,
|
|
25
|
+
);
|
|
26
|
+
// need to spread out the jobs, forgot why
|
|
27
|
+
await writeYamlfile(`.gitlab-ci.yml`, { ...jobs, ...mainPipeline });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,20 +1,33 @@
|
|
|
1
|
-
import { isObject } from "lodash";
|
|
1
|
+
import { isObject, merge } from "lodash";
|
|
2
|
+
import { getInjectVarsScript } from "../../bash/getInjectVarsScript";
|
|
2
3
|
import { BASE_RETRY } from "../../defaults";
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
CatladderJobWithContext,
|
|
6
|
+
Context,
|
|
7
|
+
GitlabJobDef,
|
|
8
|
+
GitlabRule,
|
|
9
|
+
} from "../../types";
|
|
4
10
|
import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
|
|
5
|
-
import type { AllCatladderJobs } from "../createAllJobs";
|
|
6
11
|
import { notNil } from "../../utils";
|
|
12
|
+
import { collapseableSection } from "../../utils/gitlab";
|
|
13
|
+
import type { AllCatladderJobs } from "../createAllJobs";
|
|
7
14
|
|
|
8
|
-
export type AllGitlabJobs =
|
|
15
|
+
export type AllGitlabJobs = {
|
|
16
|
+
name: string;
|
|
17
|
+
gitlabJob: GitlabJobDef;
|
|
18
|
+
componentName: string;
|
|
19
|
+
env: string;
|
|
20
|
+
}[];
|
|
9
21
|
|
|
10
|
-
const
|
|
22
|
+
export const GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
|
|
23
|
+
const removeUndefined = (obj: GitlabJobDef): GitlabJobDef =>
|
|
11
24
|
Object.fromEntries(
|
|
12
|
-
Object.entries(obj).filter(([, value]) => value !== undefined)
|
|
13
|
-
) as
|
|
25
|
+
Object.entries(obj).filter(([, value]) => value !== undefined),
|
|
26
|
+
) as GitlabJobDef;
|
|
14
27
|
const getFullJobName = (
|
|
15
28
|
name: string,
|
|
16
29
|
componentName: string,
|
|
17
|
-
env?: string | null
|
|
30
|
+
env?: string | null,
|
|
18
31
|
) => {
|
|
19
32
|
if (env) {
|
|
20
33
|
return `${componentName} ${name} | ${env} `;
|
|
@@ -26,14 +39,14 @@ const getFullReferencedJobName = (
|
|
|
26
39
|
referencedJobName: string,
|
|
27
40
|
componentName: string,
|
|
28
41
|
env: string,
|
|
29
|
-
allJobs: AllCatladderJobs
|
|
42
|
+
allJobs: AllCatladderJobs,
|
|
30
43
|
) => {
|
|
31
44
|
const referencedJob = allJobs[componentName]?.[env]?.find(
|
|
32
|
-
(j) => j.name === referencedJobName
|
|
45
|
+
(j) => j.name === referencedJobName,
|
|
33
46
|
);
|
|
34
47
|
if (!referencedJob) {
|
|
35
48
|
throw new Error(
|
|
36
|
-
`unknown job referenced: '${referencedJobName}' from '${env}:${componentName}'
|
|
49
|
+
`unknown job referenced: '${referencedJobName}' from '${env}:${componentName}'`,
|
|
37
50
|
);
|
|
38
51
|
}
|
|
39
52
|
const envToSet = referencedJob.envMode !== "none" ? env : null;
|
|
@@ -47,6 +60,7 @@ export const makeGitlabJob = (
|
|
|
47
60
|
componentName: string,
|
|
48
61
|
env: string,
|
|
49
62
|
{
|
|
63
|
+
environment,
|
|
50
64
|
envMode,
|
|
51
65
|
needsStages,
|
|
52
66
|
needsOtherComponent,
|
|
@@ -54,9 +68,14 @@ export const makeGitlabJob = (
|
|
|
54
68
|
needs,
|
|
55
69
|
jobTags,
|
|
56
70
|
script,
|
|
71
|
+
context,
|
|
72
|
+
variables,
|
|
73
|
+
runnerVariables,
|
|
74
|
+
when,
|
|
57
75
|
...job
|
|
58
|
-
}:
|
|
59
|
-
allJobs: AllCatladderJobs
|
|
76
|
+
}: CatladderJobWithContext<string>,
|
|
77
|
+
allJobs: AllCatladderJobs,
|
|
78
|
+
baseRules?: GitlabRule[],
|
|
60
79
|
): [fullName: string, job: GitlabJobDef] => {
|
|
61
80
|
const stage = envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
|
|
62
81
|
|
|
@@ -88,11 +107,11 @@ export const makeGitlabJob = (
|
|
|
88
107
|
n.job,
|
|
89
108
|
n.componentName ?? componentName,
|
|
90
109
|
env,
|
|
91
|
-
allJobs
|
|
110
|
+
allJobs,
|
|
92
111
|
),
|
|
93
112
|
artifacts: n.artifacts,
|
|
94
113
|
}
|
|
95
|
-
: getFullReferencedJobName(n, componentName, env, allJobs)
|
|
114
|
+
: getFullReferencedJobName(n, componentName, env, allJobs),
|
|
96
115
|
) // sort in a predictable manner for snapshot tests
|
|
97
116
|
.sort((a, b) => getJobName(a).localeCompare(getJobName(b)));
|
|
98
117
|
|
|
@@ -103,60 +122,164 @@ export const makeGitlabJob = (
|
|
|
103
122
|
const fullJobName = getFullJobName(
|
|
104
123
|
name,
|
|
105
124
|
componentName,
|
|
106
|
-
envMode !== "none" ? env : undefined
|
|
125
|
+
envMode !== "none" ? env : undefined,
|
|
107
126
|
);
|
|
108
127
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
// backwards compatibility, some may still use KUBERNETES_CPU_REQUEST, KUBERNETES_MEMORY_REQUEST, etc. in variables.
|
|
129
|
+
// those should now be set in the runnerVariables as they don't work in the variables key of the catladder job, becuase those get injected
|
|
130
|
+
const PIPELINE_RUNNER_VARIABLES = [
|
|
131
|
+
"KUBERNETES_CPU_REQUEST",
|
|
132
|
+
"KUBERNETES_MEMORY_REQUEST",
|
|
133
|
+
"KUBERNETES_CPU_LIMIT",
|
|
134
|
+
"KUBERNETES_MEMORY_LIMIT",
|
|
135
|
+
];
|
|
136
|
+
// remove those from variables and add them to runnerVariables
|
|
137
|
+
|
|
138
|
+
const varsInjectScripts = collapseableSection(
|
|
139
|
+
"injectvars",
|
|
140
|
+
"Injecting variables",
|
|
141
|
+
)([
|
|
142
|
+
...getInjectVarsScript(
|
|
143
|
+
// remove legacy variables
|
|
144
|
+
Object.fromEntries(
|
|
145
|
+
Object.entries(variables ?? {}).filter(
|
|
146
|
+
([key]) => !PIPELINE_RUNNER_VARIABLES.includes(key),
|
|
147
|
+
),
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
const legacyRunnerVariables = Object.fromEntries(
|
|
153
|
+
Object.entries(variables ?? {}).filter(([key]) =>
|
|
154
|
+
PIPELINE_RUNNER_VARIABLES.includes(key),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
if (Object.keys(legacyRunnerVariables).length > 0) {
|
|
159
|
+
console.warn(
|
|
160
|
+
`Legacy variables detected in ${fullJobName}: ${Object.keys(
|
|
161
|
+
legacyRunnerVariables,
|
|
162
|
+
).join(", ")}. Please move them to the runnerVariables key.`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const rules = [
|
|
166
|
+
...(job.rules ?? []),
|
|
167
|
+
...(baseRules
|
|
168
|
+
? baseRules.map((rule) => ({
|
|
169
|
+
when: when,
|
|
170
|
+
...rule,
|
|
171
|
+
}))
|
|
172
|
+
: when
|
|
173
|
+
? [{ when }]
|
|
174
|
+
: []),
|
|
175
|
+
];
|
|
176
|
+
const modified = addGitlabEnvironment(
|
|
177
|
+
context,
|
|
178
|
+
environment,
|
|
179
|
+
{
|
|
180
|
+
...job,
|
|
181
|
+
rules: rules.length > 0 ? rules : undefined,
|
|
182
|
+
variables: {
|
|
183
|
+
...legacyRunnerVariables,
|
|
184
|
+
...runnerVariables,
|
|
185
|
+
},
|
|
186
|
+
script: [...varsInjectScripts, ...(script?.filter(notNil) ?? [])],
|
|
187
|
+
tags: jobTags,
|
|
188
|
+
stage,
|
|
189
|
+
|
|
190
|
+
// sort in a predictable manner for snapshot tests
|
|
191
|
+
needs: deduplicatedGitlabNeeds,
|
|
192
|
+
retry: BASE_RETRY,
|
|
193
|
+
interruptible: true,
|
|
194
|
+
},
|
|
195
|
+
componentName,
|
|
196
|
+
env,
|
|
197
|
+
allJobs,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const gitlabJob: GitlabJobDef = removeUndefined(modified);
|
|
130
201
|
|
|
131
202
|
return [fullJobName, gitlabJob];
|
|
132
203
|
};
|
|
133
204
|
|
|
205
|
+
const addGitlabEnvironment = (
|
|
206
|
+
context: Context,
|
|
207
|
+
environment: CatladderJob["environment"],
|
|
208
|
+
job: GitlabJobDef,
|
|
209
|
+
componentName: string,
|
|
210
|
+
env: string, // TODO: we could actually pull this from contxt
|
|
211
|
+
allJobs: AllCatladderJobs,
|
|
212
|
+
): GitlabJobDef => {
|
|
213
|
+
if (!environment) {
|
|
214
|
+
return job;
|
|
215
|
+
}
|
|
216
|
+
const { url, envType } = context.environment;
|
|
217
|
+
const { on_stop, ...restEnvironment } = environment;
|
|
218
|
+
// those can be dynamic, so we therefore have to do this: https://docs.gitlab.com/ee/ci/environments/#set-a-dynamic-environment-url
|
|
219
|
+
|
|
220
|
+
const dotEnvFile = "gitlab_environment.env";
|
|
221
|
+
|
|
222
|
+
const scriptToAdd = [
|
|
223
|
+
`echo "${GITLAB_ENVIRONMENT_URL_VARIABLE}=${url}" >> ${dotEnvFile}`,
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
// this is NOT a bashVariable since it NEEDS to be used as a string in gitlab
|
|
227
|
+
const gitlabEnvironmentName =
|
|
228
|
+
envType === "review"
|
|
229
|
+
? `${env}/$CI_COMMIT_REF_NAME/${componentName}` // FIXME: should be replaced with mr name as well
|
|
230
|
+
: `${env}/${componentName}`;
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
...job,
|
|
234
|
+
environment: {
|
|
235
|
+
name: gitlabEnvironmentName,
|
|
236
|
+
url: `$${GITLAB_ENVIRONMENT_URL_VARIABLE}`,
|
|
237
|
+
...(on_stop
|
|
238
|
+
? {
|
|
239
|
+
on_stop: getFullReferencedJobName(
|
|
240
|
+
on_stop,
|
|
241
|
+
componentName,
|
|
242
|
+
env,
|
|
243
|
+
allJobs,
|
|
244
|
+
),
|
|
245
|
+
}
|
|
246
|
+
: {}),
|
|
247
|
+
...restEnvironment,
|
|
248
|
+
},
|
|
249
|
+
artifacts: merge(job.artifacts ?? {}, {
|
|
250
|
+
reports: {
|
|
251
|
+
dotenv: `${dotEnvFile}`,
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
254
|
+
|
|
255
|
+
script: [...(job.script ?? []), ...scriptToAdd],
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
134
259
|
export const createGitlabJobs = async (
|
|
135
|
-
allJobs: AllCatladderJobs
|
|
260
|
+
allJobs: AllCatladderJobs,
|
|
261
|
+
baseRules?: GitlabRule[],
|
|
136
262
|
): Promise<AllGitlabJobs> => {
|
|
137
|
-
return Object.keys(allJobs).
|
|
263
|
+
return Object.keys(allJobs).flatMap((componentName) => {
|
|
138
264
|
const componentJobs = allJobs[componentName];
|
|
139
|
-
return {
|
|
140
|
-
|
|
141
|
-
...Object.keys(componentJobs).reduce((accForEnvs, env) => {
|
|
142
|
-
const jobs = componentJobs[env];
|
|
265
|
+
return Object.keys(componentJobs).flatMap((env) => {
|
|
266
|
+
const jobs = componentJobs[env];
|
|
143
267
|
|
|
268
|
+
return jobs.flatMap((job) => {
|
|
269
|
+
const [fullJobName, gitlabJob] = makeGitlabJob(
|
|
270
|
+
componentName,
|
|
271
|
+
env,
|
|
272
|
+
job,
|
|
273
|
+
allJobs,
|
|
274
|
+
baseRules,
|
|
275
|
+
);
|
|
144
276
|
return {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
env,
|
|
150
|
-
job,
|
|
151
|
-
allJobs
|
|
152
|
-
);
|
|
153
|
-
return {
|
|
154
|
-
...accForJobs,
|
|
155
|
-
[fullJobName]: gitlabJob,
|
|
156
|
-
};
|
|
157
|
-
}, {} as AllGitlabJobs),
|
|
277
|
+
name: fullJobName,
|
|
278
|
+
gitlabJob,
|
|
279
|
+
componentName,
|
|
280
|
+
env,
|
|
158
281
|
};
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
162
285
|
};
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { RULES_ALWAYS } from "../../rules";
|
|
2
1
|
import { getRunnerImage } from "../../runner";
|
|
3
2
|
import type { Pipeline } from "../../types";
|
|
4
|
-
import type { AllGitlabJobs } from "./createGitlabJobs";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
type PickRequired<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
|
|
5
|
+
|
|
6
|
+
export const createGitlabPipelineWithDefaults = ({
|
|
7
|
+
image,
|
|
8
|
+
variables,
|
|
9
|
+
...config
|
|
10
|
+
}: PickRequired<
|
|
11
|
+
Partial<Pipeline<"gitlab">>,
|
|
12
|
+
"stages" | "jobs"
|
|
13
|
+
>): Pipeline<"gitlab"> => {
|
|
10
14
|
return {
|
|
11
|
-
image: getRunnerImage("jobs-default"), // default image
|
|
15
|
+
image: image ?? getRunnerImage("jobs-default"), // default image
|
|
12
16
|
variables: {
|
|
13
17
|
FF_USE_FASTZIP: "true",
|
|
14
|
-
GIT_DEPTH: 1, // no need the full depth
|
|
15
|
-
|
|
16
|
-
workflow: {
|
|
17
|
-
rules: RULES_ALWAYS,
|
|
18
|
+
GIT_DEPTH: "1", // no need the full depth
|
|
19
|
+
...(variables ?? {}),
|
|
18
20
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
...config,
|
|
21
23
|
};
|
|
22
|
-
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PipelineTrigger } from "../..";
|
|
2
|
+
import { PIPELINE_IMAGE_TAG } from "../../constants";
|
|
3
|
+
|
|
4
|
+
export function getPipelineTriggerForGitlabChildPipeline() {
|
|
5
|
+
const {
|
|
6
|
+
CI_MERGE_REQUEST_ID,
|
|
7
|
+
CI_COMMIT_TAG,
|
|
8
|
+
CI_COMMIT_BRANCH,
|
|
9
|
+
CI_DEFAULT_BRANCH,
|
|
10
|
+
} = process.env;
|
|
11
|
+
|
|
12
|
+
const isDefaultBranch =
|
|
13
|
+
Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
|
|
14
|
+
const isHotfixBranch = CI_COMMIT_BRANCH
|
|
15
|
+
? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
|
|
16
|
+
: false;
|
|
17
|
+
const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
18
|
+
const isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
19
|
+
|
|
20
|
+
console.info(`catladder version ${PIPELINE_IMAGE_TAG}`);
|
|
21
|
+
|
|
22
|
+
const trigger: PipelineTrigger | null =
|
|
23
|
+
isMergeRequest || isHotfixBranch
|
|
24
|
+
? "mr"
|
|
25
|
+
: isDefaultBranch
|
|
26
|
+
? "mainBranch"
|
|
27
|
+
: isTaggedRelease
|
|
28
|
+
? "taggedRelease"
|
|
29
|
+
: null;
|
|
30
|
+
|
|
31
|
+
if (!trigger) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"no matching trigger: " +
|
|
34
|
+
JSON.stringify(
|
|
35
|
+
{
|
|
36
|
+
isMergeRequest,
|
|
37
|
+
isDefaultBranch,
|
|
38
|
+
isTaggedRelease,
|
|
39
|
+
},
|
|
40
|
+
null,
|
|
41
|
+
2,
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
return trigger;
|
|
46
|
+
}
|