@catladder/pipeline 1.144.0 → 1.145.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.
Files changed (307) hide show
  1. package/dist/bash/BashExpression.d.ts +40 -0
  2. package/dist/bash/BashExpression.js +124 -0
  3. package/dist/bash/bashExpressionPerPipelineType.d.ts +6 -0
  4. package/dist/bash/bashExpressionPerPipelineType.js +11 -0
  5. package/dist/bash/bashYaml.d.ts +10 -0
  6. package/dist/bash/bashYaml.js +46 -0
  7. package/dist/bash/getInjectVarsScript.d.ts +2 -0
  8. package/dist/bash/getInjectVarsScript.js +45 -0
  9. package/dist/bash/replaceAsync.d.ts +2 -0
  10. package/dist/{pipeline/commitInfo/getCommitInfo.js → bash/replaceAsync.js} +49 -21
  11. package/dist/build/base/__tests__/createArtifactsConfig.test.js +3 -1
  12. package/dist/build/base/constants.js +3 -1
  13. package/dist/build/base/createAppBuildJob.d.ts +2 -1
  14. package/dist/build/base/createAppBuildJob.js +10 -6
  15. package/dist/build/base/createArtifactsConfig.d.ts +1 -1
  16. package/dist/build/base/createArtifactsConfig.js +3 -1
  17. package/dist/build/base/index.js +3 -1
  18. package/dist/build/base/writeBuildInfo.js +4 -3
  19. package/dist/build/base/writeDotEnv.js +12 -3
  20. package/dist/build/custom/__tests__/testJob.test.js +3 -1
  21. package/dist/build/custom/buildJob.js +4 -12
  22. package/dist/build/custom/index.js +3 -1
  23. package/dist/build/custom/testJob.d.ts +1 -1
  24. package/dist/build/custom/testJob.js +18 -14
  25. package/dist/build/docker.d.ts +5 -31
  26. package/dist/build/docker.js +16 -9
  27. package/dist/build/index.d.ts +1 -1
  28. package/dist/build/index.js +13 -7
  29. package/dist/build/node/buildJob.js +4 -12
  30. package/dist/build/node/cache.js +6 -3
  31. package/dist/build/node/constants.js +3 -1
  32. package/dist/build/node/index.js +3 -1
  33. package/dist/build/node/meteor.js +5 -2
  34. package/dist/build/node/testJob.js +18 -14
  35. package/dist/build/node/yarn.d.ts +3 -2
  36. package/dist/build/node/yarn.js +6 -3
  37. package/dist/build/rails/build.js +3 -1
  38. package/dist/build/rails/index.js +3 -1
  39. package/dist/build/rails/test.js +15 -11
  40. package/dist/build/sbom.js +3 -1
  41. package/dist/build/types.d.ts +24 -18
  42. package/dist/build/types.js +3 -1
  43. package/dist/bundles/catladder-gitlab/index.js +3 -3
  44. package/dist/catladder-gitlab.js +10 -54
  45. package/dist/config/__tests__/configruedEnvs.test.js +3 -1
  46. package/dist/config/configruedEnvs.js +3 -1
  47. package/dist/config/index.js +13 -7
  48. package/dist/config/readConfig.js +6 -5
  49. package/dist/constants.js +5 -3
  50. package/dist/context/__tests__/resolveReferences.test.js +40 -8
  51. package/dist/context/getBuildInfoVariables.d.ts +7 -0
  52. package/dist/context/getBuildInfoVariables.js +29 -0
  53. package/dist/context/getEnvConfig.js +3 -1
  54. package/dist/context/getEnvType.js +3 -1
  55. package/dist/context/getEnvironment.d.ts +3 -3
  56. package/dist/context/getEnvironment.js +10 -14
  57. package/dist/context/getEnvironmentContext.d.ts +7 -3
  58. package/dist/context/getEnvironmentContext.js +21 -11
  59. package/dist/context/getEnvironmentVariables.d.ts +26 -5
  60. package/dist/context/getEnvironmentVariables.js +41 -25
  61. package/dist/context/getLabels.js +4 -2
  62. package/dist/context/getReviewSlug.d.ts +4 -0
  63. package/dist/context/getReviewSlug.js +22 -0
  64. package/dist/context/index.d.ts +12 -3
  65. package/dist/context/index.js +21 -15
  66. package/dist/context/resolveReferences.d.ts +3 -1
  67. package/dist/context/resolveReferences.js +53 -21
  68. package/dist/context/transformJobOnlyVars.d.ts +5 -2
  69. package/dist/context/transformJobOnlyVars.js +4 -2
  70. package/dist/context/utils/envVars.d.ts +1 -1
  71. package/dist/context/utils/envVars.js +5 -2
  72. package/dist/defaults/index.js +3 -1
  73. package/dist/deploy/base/deploy.d.ts +1 -1
  74. package/dist/deploy/base/deploy.js +12 -11
  75. package/dist/deploy/base/index.js +3 -1
  76. package/dist/deploy/base/rollback.d.ts +1 -1
  77. package/dist/deploy/base/rollback.js +13 -9
  78. package/dist/deploy/base/stop.d.ts +1 -1
  79. package/dist/deploy/base/stop.js +16 -11
  80. package/dist/deploy/base/types.d.ts +1 -1
  81. package/dist/deploy/base/types.js +3 -1
  82. package/dist/deploy/base/variables.js +3 -1
  83. package/dist/deploy/cloudRun/artifactsRegistry.d.ts +2 -1
  84. package/dist/deploy/cloudRun/artifactsRegistry.js +6 -4
  85. package/dist/deploy/cloudRun/cleanup.js +3 -1
  86. package/dist/deploy/cloudRun/cloudRunRevisions.js +3 -1
  87. package/dist/deploy/cloudRun/createJobs/cloudRunJobs.js +8 -5
  88. package/dist/deploy/cloudRun/createJobs/cloudRunServices.d.ts +2 -2
  89. package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +6 -3
  90. package/dist/deploy/cloudRun/createJobs/common.d.ts +3 -3
  91. package/dist/deploy/cloudRun/createJobs/common.js +3 -1
  92. package/dist/deploy/cloudRun/createJobs/constants.d.ts +1 -0
  93. package/dist/deploy/cloudRun/createJobs/constants.js +7 -0
  94. package/dist/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +9 -2
  95. package/dist/deploy/cloudRun/createJobs/getCloudRunStopScripts.js +3 -1
  96. package/dist/deploy/cloudRun/createJobs/index.js +25 -8
  97. package/dist/deploy/cloudRun/createJobs/volumes.js +3 -1
  98. package/dist/deploy/cloudRun/index.js +5 -3
  99. package/dist/deploy/cloudRun/utils/createArgsString.d.ts +2 -1
  100. package/dist/deploy/cloudRun/utils/createArgsString.js +3 -1
  101. package/dist/deploy/cloudRun/utils/database.js +13 -13
  102. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +3 -1
  103. package/dist/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
  104. package/dist/deploy/cloudRun/utils/getServiceName.js +3 -1
  105. package/dist/deploy/cloudRun/utils/jobName.d.ts +2 -1
  106. package/dist/deploy/cloudRun/utils/jobName.js +4 -2
  107. package/dist/deploy/cloudRun/utils/removeFirstLinesFromCommandOutput.js +3 -1
  108. package/dist/deploy/cloudSql/utils.d.ts +2 -1
  109. package/dist/deploy/cloudSql/utils.js +7 -2
  110. package/dist/deploy/custom/deployJob.js +3 -1
  111. package/dist/deploy/custom/index.js +3 -1
  112. package/dist/deploy/dockerTag/deployJob.js +3 -1
  113. package/dist/deploy/dockerTag/index.js +3 -1
  114. package/dist/deploy/index.d.ts +4 -3
  115. package/dist/deploy/index.js +13 -7
  116. package/dist/deploy/kubernetes/additionalSecretKeys.js +3 -1
  117. package/dist/deploy/kubernetes/cloudSql/index.d.ts +3 -2
  118. package/dist/deploy/kubernetes/cloudSql/index.js +6 -4
  119. package/dist/deploy/kubernetes/deployJob.js +22 -15
  120. package/dist/deploy/kubernetes/index.js +51 -14
  121. package/dist/deploy/kubernetes/kubeEnv.d.ts +3 -2
  122. package/dist/deploy/kubernetes/kubeEnv.js +7 -4
  123. package/dist/deploy/kubernetes/kubeValues.d.ts +2 -2
  124. package/dist/deploy/kubernetes/kubeValues.js +3 -2
  125. package/dist/deploy/kubernetes/mongodb.js +3 -1
  126. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +2 -1
  127. package/dist/deploy/kubernetes/processSecretsAsFiles.js +3 -1
  128. package/dist/deploy/sbom.js +3 -1
  129. package/dist/deploy/types/base.d.ts +8 -2
  130. package/dist/deploy/types/base.js +3 -1
  131. package/dist/deploy/types/custom.d.ts +1 -1
  132. package/dist/deploy/types/custom.js +3 -1
  133. package/dist/deploy/types/dockerTag.d.ts +1 -1
  134. package/dist/deploy/types/dockerTag.js +3 -1
  135. package/dist/deploy/types/googleCloudRun.d.ts +19 -18
  136. package/dist/deploy/types/googleCloudRun.js +3 -1
  137. package/dist/deploy/types/index.d.ts +6 -6
  138. package/dist/deploy/types/index.js +13 -7
  139. package/dist/deploy/types/kubernetes.d.ts +22 -22
  140. package/dist/deploy/types/kubernetes.js +3 -1
  141. package/dist/deploy/utils.js +3 -1
  142. package/dist/index.d.ts +3 -2
  143. package/dist/index.js +16 -9
  144. package/dist/packageInfos.d.ts +2 -0
  145. package/dist/packageInfos.js +14 -0
  146. package/dist/pipeline/createAllJobs.d.ts +13 -5
  147. package/dist/pipeline/createAllJobs.js +21 -10
  148. package/dist/pipeline/createChildPipeline.d.ts +1 -1
  149. package/dist/pipeline/createChildPipeline.js +24 -7
  150. package/dist/pipeline/createJobsForComponent.d.ts +3 -3
  151. package/dist/pipeline/createJobsForComponent.js +19 -18
  152. package/dist/pipeline/createMainPipeline.d.ts +3 -0
  153. package/dist/pipeline/createMainPipeline.js +248 -0
  154. package/dist/pipeline/generatePipelineFiles.d.ts +2 -0
  155. package/dist/pipeline/generatePipelineFiles.js +178 -0
  156. package/dist/pipeline/getPipelineStages.js +3 -1
  157. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +15 -5
  158. package/dist/pipeline/gitlab/createGitlabJobs.js +98 -25
  159. package/dist/pipeline/gitlab/createGitlabPipeline.d.ts +7 -2
  160. package/dist/pipeline/gitlab/createGitlabPipeline.js +34 -17
  161. package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +1 -0
  162. package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +29 -0
  163. package/dist/pipeline/gitlab/gitlabReleaseJobs.d.ts +33 -0
  164. package/dist/pipeline/gitlab/gitlabReleaseJobs.js +24 -0
  165. package/dist/pipeline/index.d.ts +3 -1
  166. package/dist/pipeline/index.js +16 -8
  167. package/dist/pipeline/packageManager.js +4 -2
  168. package/dist/pipeline/yarn/yarnUtils.js +6 -4
  169. package/dist/rules/index.d.ts +4 -1
  170. package/dist/rules/index.js +25 -18
  171. package/dist/runner/index.d.ts +1 -1
  172. package/dist/runner/index.js +3 -1
  173. package/dist/tsconfig.tsbuildinfo +1 -1
  174. package/dist/types/config.d.ts +18 -15
  175. package/dist/types/config.js +5 -2
  176. package/dist/types/context.d.ts +37 -32
  177. package/dist/types/context.js +3 -1
  178. package/dist/types/environmentContext.d.ts +11 -7
  179. package/dist/types/environmentContext.js +3 -1
  180. package/dist/types/gitlab-ci-yml.d.ts +30 -30
  181. package/dist/types/gitlab-ci-yml.js +3 -2
  182. package/dist/types/gitlab-types.d.ts +4 -6
  183. package/dist/types/gitlab-types.js +3 -1
  184. package/dist/types/index.js +13 -7
  185. package/dist/types/jobs.d.ts +23 -6
  186. package/dist/types/jobs.js +3 -1
  187. package/dist/types/pipeline.d.ts +4 -3
  188. package/dist/types/pipeline.js +3 -1
  189. package/dist/types/utils.d.ts +1 -1
  190. package/dist/types/utils.js +3 -1
  191. package/dist/utils/gitlab.js +3 -1
  192. package/dist/utils/index.d.ts +1 -1
  193. package/dist/utils/index.js +3 -1
  194. package/dist/utils/writeFiles.d.ts +7 -0
  195. package/dist/{pipeline/commitInfo/getBuildId.js → utils/writeFiles.js} +39 -22
  196. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +480 -384
  197. package/examples/__snapshots__/cloud-run-meteor-with-worker.ts.snap +462 -366
  198. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +480 -384
  199. package/examples/__snapshots__/cloud-run-no-service.ts.snap +501 -393
  200. package/examples/__snapshots__/cloud-run-non-public.ts.snap +480 -384
  201. package/examples/__snapshots__/cloud-run-post-stop-job.ts.snap +489 -392
  202. package/examples/__snapshots__/cloud-run-service-gen2.ts.snap +480 -384
  203. package/examples/__snapshots__/cloud-run-service-with-volumes.ts.snap +501 -401
  204. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +1155 -915
  205. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +1116 -888
  206. package/examples/__snapshots__/cloud-run-with-worker.ts.snap +482 -386
  207. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +452 -356
  208. package/examples/__snapshots__/custom-build-job.ts.snap +434 -350
  209. package/examples/__snapshots__/custom-deploy.ts.snap +319 -223
  210. package/examples/__snapshots__/custom-envs.ts.snap +123 -81
  211. package/examples/__snapshots__/custom-sbom-java.ts.snap +434 -350
  212. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +846 -969
  213. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +886 -957
  214. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +894 -969
  215. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +1626 -1728
  216. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +974 -1137
  217. package/examples/__snapshots__/local-dot-env.ts.snap +480 -384
  218. package/examples/__snapshots__/meteor-kubernetes.ts.snap +906 -1069
  219. package/examples/__snapshots__/multiline-var.ts.snap +4500 -0
  220. package/examples/__snapshots__/native-app.ts.snap +706 -578
  221. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +480 -384
  222. package/examples/__snapshots__/node-build-with-docker-additions.ts.snap +488 -384
  223. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1656 -1942
  224. package/examples/__snapshots__/wait-for-other-deploy.ts.snap +287 -231
  225. package/examples/custom-deploy.ts +7 -7
  226. package/examples/multiline-var.ts +64 -0
  227. package/package.json +5 -8
  228. package/src/bash/BashExpression.ts +81 -0
  229. package/src/bash/bashExpressionPerPipelineType.ts +16 -0
  230. package/src/bash/bashYaml.ts +46 -0
  231. package/src/bash/getInjectVarsScript.ts +12 -0
  232. package/src/bash/replaceAsync.ts +50 -0
  233. package/src/build/base/createAppBuildJob.ts +6 -2
  234. package/src/build/base/writeBuildInfo.ts +1 -1
  235. package/src/build/base/writeDotEnv.ts +6 -1
  236. package/src/build/custom/buildJob.ts +2 -4
  237. package/src/build/custom/testJob.ts +3 -2
  238. package/src/build/docker.ts +15 -7
  239. package/src/build/node/buildJob.ts +1 -3
  240. package/src/build/node/testJob.ts +3 -2
  241. package/src/build/node/yarn.ts +9 -4
  242. package/src/build/rails/test.ts +2 -1
  243. package/src/build/types.ts +8 -1
  244. package/src/catladder-gitlab.ts +8 -55
  245. package/src/config/readConfig.ts +2 -3
  246. package/src/constants.ts +5 -2
  247. package/src/context/__tests__/resolveReferences.test.ts +11 -6
  248. package/src/context/getBuildInfoVariables.ts +40 -0
  249. package/src/context/getEnvironment.ts +7 -30
  250. package/src/context/getEnvironmentContext.ts +25 -29
  251. package/src/context/getEnvironmentVariables.ts +61 -36
  252. package/src/context/getReviewSlug.ts +27 -0
  253. package/src/context/index.ts +24 -23
  254. package/src/context/resolveReferences.ts +28 -8
  255. package/src/context/transformJobOnlyVars.ts +5 -2
  256. package/src/context/utils/envVars.ts +2 -1
  257. package/src/deploy/base/deploy.ts +20 -18
  258. package/src/deploy/base/rollback.ts +8 -10
  259. package/src/deploy/base/stop.ts +8 -9
  260. package/src/deploy/cloudRun/artifactsRegistry.ts +9 -4
  261. package/src/deploy/cloudRun/createJobs/cloudRunJobs.ts +12 -7
  262. package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +3 -2
  263. package/src/deploy/cloudRun/createJobs/constants.ts +1 -0
  264. package/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.ts +20 -2
  265. package/src/deploy/cloudRun/createJobs/index.ts +17 -8
  266. package/src/deploy/cloudRun/index.ts +14 -6
  267. package/src/deploy/cloudRun/utils/createArgsString.ts +2 -1
  268. package/src/deploy/cloudRun/utils/database.ts +2 -2
  269. package/src/deploy/cloudRun/utils/jobName.ts +7 -2
  270. package/src/deploy/cloudSql/utils.ts +12 -9
  271. package/src/deploy/index.ts +2 -1
  272. package/src/deploy/kubernetes/cloudSql/index.ts +3 -2
  273. package/src/deploy/kubernetes/deployJob.ts +24 -10
  274. package/src/deploy/kubernetes/index.ts +15 -8
  275. package/src/deploy/kubernetes/kubeEnv.ts +8 -6
  276. package/src/deploy/kubernetes/kubeValues.ts +0 -1
  277. package/src/deploy/kubernetes/processSecretsAsFiles.ts +2 -1
  278. package/src/deploy/types/base.ts +6 -0
  279. package/src/deploy/types/googleCloudRun.ts +2 -0
  280. package/src/index.ts +2 -1
  281. package/src/packageInfos.ts +10 -0
  282. package/src/pipeline/createAllJobs.ts +24 -10
  283. package/src/pipeline/createChildPipeline.ts +19 -8
  284. package/src/pipeline/createJobsForComponent.ts +14 -22
  285. package/src/pipeline/createMainPipeline.ts +88 -0
  286. package/src/pipeline/generatePipelineFiles.ts +29 -0
  287. package/src/pipeline/gitlab/createGitlabJobs.ts +174 -51
  288. package/src/pipeline/gitlab/createGitlabPipeline.ts +16 -14
  289. package/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.ts +46 -0
  290. package/src/pipeline/gitlab/gitlabReleaseJobs.ts +20 -0
  291. package/src/pipeline/index.ts +2 -0
  292. package/src/rules/index.ts +15 -9
  293. package/src/types/config.ts +11 -2
  294. package/src/types/context.ts +39 -26
  295. package/src/types/environmentContext.ts +12 -6
  296. package/src/types/gitlab-ci-yml.ts +0 -1
  297. package/src/types/gitlab-types.ts +5 -4
  298. package/src/types/jobs.ts +28 -3
  299. package/src/types/pipeline.ts +4 -0
  300. package/src/utils/writeFiles.ts +40 -0
  301. package/dist/deploy/cloudRun/createJobs/variables.d.ts +0 -5
  302. package/dist/deploy/cloudRun/createJobs/variables.js +0 -19
  303. package/dist/pipeline/commitInfo/getBuildId.d.ts +0 -6
  304. package/dist/pipeline/commitInfo/getCommitInfo.d.ts +0 -2
  305. package/src/deploy/cloudRun/createJobs/variables.ts +0 -21
  306. package/src/pipeline/commitInfo/getBuildId.ts +0 -17
  307. package/src/pipeline/commitInfo/getCommitInfo.ts +0 -15
@@ -70,7 +70,6 @@ export const createKubeValues = (context: Context) => {
70
70
 
71
71
  // we remove the application config because it can be just the value `false` which is a convenience feature, but not supported in the helm chart
72
72
  // we only merge the rest of the values in
73
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
73
  const { application, jobs, cronjobs, ...rest } = values ?? {};
75
74
 
76
75
  const env = createKubeEnv(context);
@@ -1,10 +1,11 @@
1
1
  import { omit } from "lodash";
2
2
  import type { DeployConfigKubernetesValues } from "../types";
3
+ import type { StringOrBashExpression } from "../../bash/BashExpression";
3
4
 
4
5
  export const processSecretsAsFiles = <
5
6
  T extends {
6
7
  env: {
7
- secret: Record<string, string>;
8
+ secret: Record<string, StringOrBashExpression>;
8
9
  };
9
10
  } & DeployConfigKubernetesValues
10
11
  >(
@@ -31,6 +31,12 @@ export type DeployConfigBase = {
31
31
  * @deprecated use deploy.jobVars for deploy job specific variables
32
32
  */
33
33
  extraVars?: Record<string, string>;
34
+ /**
35
+ * additional vars only for the runner.
36
+ * Also if you use services: that require env vars, you need to set them here.
37
+ *
38
+ */
39
+ runnerVariables?: Record<string, string>;
34
40
  };
35
41
 
36
42
  export type AllowUnknownProps<T extends Record<string, unknown>> = T &
@@ -256,6 +256,8 @@ export type DeployConfigCloudRun = {
256
256
  * add cloudSql
257
257
  */
258
258
  cloudSql?: DeployConfigCloudRunCloudSql | false;
259
+
260
+ debug?: boolean;
259
261
  } & DeployConfigBase;
260
262
 
261
263
  export type DeployConfigCloudRunVolumes = Record<
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./pipeline/";
1
+ export * from "./pipeline";
2
2
  export * from "./types";
3
3
  export * from "./rules";
4
4
  export * from "./runner";
@@ -6,3 +6,4 @@ export * from "./config";
6
6
  export * from "./context";
7
7
  export * from "./build";
8
8
  export * from "./deploy";
9
+ export * from "./utils/writeFiles";
@@ -0,0 +1,10 @@
1
+ // we can't import the package.json directly, because the bundling process will inline it
2
+ // but the version is only set during deployement, when its already bundled
3
+ // instead we need to use require.main.path to get the path of the main module, which is actually the file in the bin
4
+ // this will point to the root package.json
5
+
6
+ const path = require.main?.path + "/../package.json";
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ const ownPkg = require(path);
9
+
10
+ export default ownPkg;
@@ -1,17 +1,29 @@
1
1
  import { getAllEnvsByTrigger } from "../config";
2
- import type { Config, PipelineTrigger } from "../types";
3
- import type { CatladderJob } from "../types/jobs";
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<CatladderJob>;
12
+ [env: string]: Array<CatladderJobWithContext>;
9
13
  };
10
14
  };
11
- export const createAllJobs = async (
12
- config: Config,
13
- trigger: PipelineTrigger
14
- ): Promise<AllCatladderJobs> => {
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,12 +34,14 @@ export const createAllJobs = async (
22
34
  await Promise.all(
23
35
  envs.map(async (env) => [
24
36
  env,
25
- await createJobsForComponent(
37
+
38
+ await createJobsForComponent({
26
39
  config,
27
40
  componentName,
28
41
  env,
29
- trigger
30
- ),
42
+ trigger,
43
+ pipelineType,
44
+ }),
31
45
  ])
32
46
  )
33
47
  ),
@@ -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 { createGitlabPipelineFromStagesAndJobs } from "./gitlab/createGitlabPipeline";
8
+ import { createGitlabPipelineWithDefaults } from "./gitlab/createGitlabPipeline";
7
9
 
8
10
  export const createChildPipeline = async <T extends PipelineType>(
9
- type: T,
11
+ pipelineType: T,
10
12
  trigger: PipelineTrigger,
11
13
  config: Config
12
14
  ): Promise<Pipeline<T>> => {
13
- const jobs = await createAllJobs(config, trigger);
15
+ const jobs = await createAllJobs({
16
+ config,
17
+ trigger,
18
+ pipelineType,
19
+ });
14
20
  const stages = getPipelineStages(config);
15
21
 
16
- if (type === "gitlab") {
22
+ if (pipelineType === "gitlab") {
17
23
  const gitlabJobs = await createGitlabJobs(jobs);
18
- return createGitlabPipelineFromStagesAndJobs(
24
+ return createGitlabPipelineWithDefaults({
25
+ workflow: {
26
+ rules: RULES_ALWAYS,
27
+ },
19
28
  stages,
20
- gitlabJobs
21
- ) as Pipeline<T>;
29
+ jobs: Object.fromEntries(
30
+ gitlabJobs.map(({ gitlabJob, name }) => [name, gitlabJob])
31
+ ),
32
+ }) as Pipeline<T>;
22
33
  }
23
- throw new Error(`${type} is not supported`);
34
+ throw new Error(`${pipelineType} is not supported`);
24
35
  };
@@ -1,11 +1,10 @@
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 { Config, PipelineTrigger } from "../types/config";
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 = (
@@ -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
- const context = await createContext(
56
- config,
57
- componentName,
58
- env,
59
- commitInfo,
60
- packageManagerInfo
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
- return createRawJobs(context);
49
+
50
+ const context = await createContext({
51
+ ...contextContext,
52
+ packageManagerInfo,
53
+ });
54
+ return createRawJobs(context).map((job) => ({ ...job, context }));
63
55
  };
@@ -0,0 +1,88 @@
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((acc, { gitlabJob, name }) => {
52
+ // merge jobs, if a job is already there, merge the rules
53
+ // this is currently needed because of envMode: "none", which creates the same job for all triggers, so it can appear multiple times
54
+ if (acc[name]) {
55
+ acc[name].rules = [
56
+ ...(acc[name].rules ?? []),
57
+ ...(gitlabJob.rules ?? []),
58
+ ];
59
+ } else {
60
+ acc[name] = gitlabJob;
61
+ }
62
+
63
+ return acc;
64
+ }, {} as { [key: string]: GitlabJobDef });
65
+
66
+ return createGitlabPipelineWithDefaults({
67
+ stages: [...stages, "release"],
68
+ jobs: {
69
+ ...allJobs,
70
+ ...getGitlabReleaseJobs(),
71
+ },
72
+ }) as Pipeline<T>;
73
+ }
74
+ throw new Error(`${pipelineType} is not supported`);
75
+ };
76
+ function getGitlabRulesForTrigger(trigger: PipelineTrigger): GitlabRule[] {
77
+ // mainBranch: on push to main branch
78
+ // mr: on merge request
79
+ // taggedRelease: on tag
80
+ switch (trigger) {
81
+ case "mainBranch":
82
+ return [RULE_NEVER_ON_RELEASE_COMMIT, RULE_IS_MAIN_BRANCH];
83
+ case "mr":
84
+ return [RULE_IS_MERGE_REQUEST];
85
+ case "taggedRelease":
86
+ return [RULE_IS_TAGGED_RELEASE];
87
+ }
88
+ }
@@ -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,16 +1,29 @@
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 { GitlabJobDef } from "../../types";
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 = Record<string, GitlabJobDef>;
15
+ export type AllGitlabJobs = {
16
+ name: string;
17
+ gitlabJob: GitlabJobDef;
18
+ componentName: string;
19
+ env: string;
20
+ }[];
9
21
 
10
- const removeUndefined = <T extends Record<string, unknown>>(obj: T): T =>
22
+ export const GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
23
+ const removeUndefined = (obj: GitlabJobDef): GitlabJobDef =>
11
24
  Object.fromEntries(
12
25
  Object.entries(obj).filter(([, value]) => value !== undefined)
13
- ) as T;
26
+ ) as GitlabJobDef;
14
27
  const getFullJobName = (
15
28
  name: string,
16
29
  componentName: string,
@@ -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
- }: CatladderJob<string>,
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
 
@@ -106,57 +125,161 @@ export const makeGitlabJob = (
106
125
  envMode !== "none" ? env : undefined
107
126
  );
108
127
 
109
- const gitlabJob: GitlabJobDef = removeUndefined({
110
- ...job,
111
- script: script?.filter(notNil),
112
- tags: jobTags,
113
- stage,
114
- environment: job.environment?.on_stop
115
- ? {
116
- ...job.environment,
117
- on_stop: getFullReferencedJobName(
118
- job.environment.on_stop,
119
- componentName,
120
- env,
121
- allJobs
122
- ),
123
- }
124
- : job.environment,
125
- // sort in a predictable manner for snapshot tests
126
- needs: deduplicatedGitlabNeeds,
127
- retry: BASE_RETRY,
128
- interruptible: true,
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
 
134
- export const createGitlabJobs = async (
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
135
211
  allJobs: AllCatladderJobs
136
- ): Promise<AllGitlabJobs> => {
137
- return Object.keys(allJobs).reduce((accForComponents, componentName) => {
138
- const componentJobs = allJobs[componentName];
139
- return {
140
- ...accForComponents,
141
- ...Object.keys(componentJobs).reduce((accForEnvs, env) => {
142
- const jobs = componentJobs[env];
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
143
219
 
144
- return {
145
- ...accForEnvs,
146
- ...jobs.reduce((accForJobs, job) => {
147
- const [fullJobName, gitlabJob] = makeGitlabJob(
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,
148
241
  componentName,
149
242
  env,
150
- job,
151
243
  allJobs
152
- );
153
- return {
154
- ...accForJobs,
155
- [fullJobName]: gitlabJob,
156
- };
157
- }, {} as AllGitlabJobs),
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
+
259
+ export const createGitlabJobs = async (
260
+ allJobs: AllCatladderJobs,
261
+ baseRules?: GitlabRule[]
262
+ ): Promise<AllGitlabJobs> => {
263
+ return Object.keys(allJobs).flatMap((componentName) => {
264
+ const componentJobs = allJobs[componentName];
265
+ return Object.keys(componentJobs).flatMap((env) => {
266
+ const jobs = componentJobs[env];
267
+
268
+ return jobs.flatMap((job) => {
269
+ const [fullJobName, gitlabJob] = makeGitlabJob(
270
+ componentName,
271
+ env,
272
+ job,
273
+ allJobs,
274
+ baseRules
275
+ );
276
+ return {
277
+ name: fullJobName,
278
+ gitlabJob,
279
+ componentName,
280
+ env,
158
281
  };
159
- }, {} as AllGitlabJobs),
160
- };
161
- }, {} as AllGitlabJobs);
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
- export function createGitlabPipelineFromStagesAndJobs(
7
- stages: string[],
8
- gitlabJobs: AllGitlabJobs
9
- ): Pipeline<"gitlab"> {
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
- stages,
20
- jobs: gitlabJobs,
21
+
22
+ ...config,
21
23
  };
22
- }
24
+ };