@catladder/pipeline 0.0.0-node16-ddfae617 → 0.0.0-prettier-cbceeed9

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 (275) hide show
  1. package/bin/catladder-gitlab-dev.js +3 -0
  2. package/bin/catladder-gitlab.js +1 -1
  3. package/dist/build/base/createBuildJob.d.ts +2 -2
  4. package/dist/build/base/createBuildJob.js +15 -30
  5. package/dist/build/base/writeBuildInfo.d.ts +2 -0
  6. package/dist/build/base/{getBuildInfo.js → writeBuildInfo.js} +3 -6
  7. package/dist/build/custom/buildJob.d.ts +3 -0
  8. package/dist/build/custom/buildJob.js +83 -0
  9. package/dist/build/custom/index.d.ts +3 -0
  10. package/dist/build/custom/index.js +40 -0
  11. package/dist/build/docker.d.ts +33 -9
  12. package/dist/build/docker.js +51 -54
  13. package/dist/build/index.d.ts +6 -5
  14. package/dist/build/index.js +20 -6
  15. package/dist/build/node/buildJob.d.ts +2 -2
  16. package/dist/build/node/buildJob.js +3 -25
  17. package/dist/build/node/cache.d.ts +2 -2
  18. package/dist/build/node/cache.js +19 -22
  19. package/dist/build/node/index.d.ts +1 -1
  20. package/dist/build/node/index.js +3 -16
  21. package/dist/build/node/meteor.d.ts +1 -1
  22. package/dist/build/node/meteor.js +9 -20
  23. package/dist/build/node/testJob.d.ts +2 -2
  24. package/dist/build/node/testJob.js +7 -21
  25. package/dist/build/node/yarn.d.ts +1 -1
  26. package/dist/build/node/yarn.js +14 -15
  27. package/dist/build/rails/build.d.ts +3 -0
  28. package/dist/build/rails/build.js +51 -0
  29. package/dist/build/rails/index.d.ts +3 -0
  30. package/dist/build/rails/index.js +41 -0
  31. package/dist/build/rails/test.d.ts +3 -0
  32. package/dist/build/rails/test.js +94 -0
  33. package/dist/build/types.d.ts +84 -9
  34. package/dist/build/types.js +0 -4
  35. package/dist/bundles/catladder-gitlab/index.js +32979 -0
  36. package/dist/catladder-gitlab.js +7 -26
  37. package/dist/config/{configruedEnvs.test.d.ts → __tests__/configruedEnvs.test.d.ts} +0 -0
  38. package/dist/config/{configruedEnvs.test.js → __tests__/configruedEnvs.test.js} +10 -12
  39. package/dist/config/configruedEnvs.d.ts +1 -1
  40. package/dist/config/configruedEnvs.js +7 -22
  41. package/dist/config/index.js +0 -4
  42. package/dist/config/readConfig.d.ts +1 -1
  43. package/dist/config/readConfig.js +2 -13
  44. package/dist/constants.js +1 -1
  45. package/dist/context/{resolveReferences.test.d.ts → __tests__/resolveReferences.test.d.ts} +0 -0
  46. package/dist/context/__tests__/resolveReferences.test.js +336 -0
  47. package/dist/context/getEnvConfig.d.ts +2 -0
  48. package/dist/context/getEnvConfig.js +18 -0
  49. package/dist/context/getEnvType.d.ts +4 -0
  50. package/dist/context/getEnvType.js +13 -0
  51. package/dist/context/getEnvironment.d.ts +3 -0
  52. package/dist/{pipeline/createChildPipeline.test.js → context/getEnvironment.js} +42 -84
  53. package/dist/context/getEnvironmentContext.d.ts +4 -0
  54. package/dist/context/getEnvironmentContext.js +33 -0
  55. package/dist/context/getEnvironmentVariables.d.ts +10 -0
  56. package/dist/context/getEnvironmentVariables.js +260 -0
  57. package/dist/context/getLabels.d.ts +8 -0
  58. package/dist/context/getLabels.js +38 -0
  59. package/dist/context/index.d.ts +5 -6
  60. package/dist/context/index.js +158 -208
  61. package/dist/context/resolveReferences.d.ts +1 -3
  62. package/dist/context/resolveReferences.js +213 -52
  63. package/dist/defaults/index.d.ts +1 -1
  64. package/dist/deploy/base.d.ts +4 -2
  65. package/dist/deploy/base.js +38 -33
  66. package/dist/deploy/cloudRun/deployJob.d.ts +3 -0
  67. package/dist/deploy/cloudRun/deployJob.js +238 -0
  68. package/dist/deploy/cloudRun/index.d.ts +4 -0
  69. package/dist/deploy/cloudRun/index.js +112 -0
  70. package/dist/deploy/cloudRun/utils/createArgsString.d.ts +11 -0
  71. package/dist/deploy/cloudRun/utils/createArgsString.js +55 -0
  72. package/dist/deploy/cloudRun/utils/database.d.ts +4 -0
  73. package/dist/deploy/cloudRun/utils/database.js +64 -0
  74. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.d.ts +2 -0
  75. package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +10 -0
  76. package/dist/deploy/cloudRun/utils/jobName.d.ts +1 -0
  77. package/dist/deploy/cloudRun/utils/jobName.js +8 -0
  78. package/dist/deploy/custom/deployJob.d.ts +2 -2
  79. package/dist/deploy/custom/deployJob.js +10 -16
  80. package/dist/deploy/custom/index.d.ts +2 -1
  81. package/dist/deploy/custom/index.js +14 -19
  82. package/dist/deploy/dockerTag/deployJob.d.ts +3 -0
  83. package/dist/deploy/dockerTag/deployJob.js +24 -0
  84. package/dist/deploy/dockerTag/index.d.ts +2 -0
  85. package/dist/deploy/dockerTag/index.js +17 -0
  86. package/dist/deploy/index.d.ts +12 -8
  87. package/dist/deploy/index.js +7 -20
  88. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +4 -0
  89. package/dist/deploy/kubernetes/additionalSecretKeys.js +24 -0
  90. package/dist/deploy/kubernetes/cloudSql/index.d.ts +13 -0
  91. package/dist/deploy/kubernetes/cloudSql/index.js +30 -0
  92. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  93. package/dist/deploy/kubernetes/deployJob.js +17 -91
  94. package/dist/deploy/kubernetes/index.d.ts +3 -1
  95. package/dist/deploy/kubernetes/index.js +42 -4
  96. package/dist/deploy/kubernetes/kubeEnv.d.ts +9 -0
  97. package/dist/deploy/kubernetes/kubeEnv.js +72 -0
  98. package/dist/deploy/kubernetes/kubeValues.d.ts +97 -0
  99. package/dist/deploy/kubernetes/kubeValues.js +124 -0
  100. package/dist/deploy/kubernetes/mongodb.d.ts +18 -5
  101. package/dist/deploy/kubernetes/mongodb.js +96 -10
  102. package/dist/deploy/kubernetes/processSecretsAsFiles.d.ts +25 -21
  103. package/dist/deploy/kubernetes/processSecretsAsFiles.js +2 -10
  104. package/dist/deploy/types/base.d.ts +14 -0
  105. package/dist/deploy/types/base.js +3 -0
  106. package/dist/deploy/types/custom.d.ts +33 -0
  107. package/dist/deploy/types/custom.js +3 -0
  108. package/dist/deploy/types/dockerTag.d.ts +10 -0
  109. package/dist/deploy/types/dockerTag.js +3 -0
  110. package/dist/deploy/types/googleCloudRun.d.ts +121 -0
  111. package/dist/deploy/types/googleCloudRun.js +3 -0
  112. package/dist/deploy/types/index.d.ts +22 -0
  113. package/dist/deploy/types/index.js +31 -0
  114. package/dist/deploy/types/kubernetes.d.ts +276 -0
  115. package/dist/deploy/types/kubernetes.js +3 -0
  116. package/dist/deploy/utils.d.ts +2 -2
  117. package/dist/deploy/utils.js +3 -10
  118. package/dist/index.js +0 -10
  119. package/dist/pipeline/commitInfo/getBuildId.d.ts +1 -0
  120. package/dist/pipeline/commitInfo/getBuildId.js +135 -0
  121. package/dist/pipeline/commitInfo/getCommitInfo.d.ts +2 -0
  122. package/dist/pipeline/commitInfo/getCommitInfo.js +140 -0
  123. package/dist/pipeline/createAllJobs.d.ts +8 -0
  124. package/dist/{build/tests/storybook.test.js → pipeline/createAllJobs.js} +54 -104
  125. package/dist/pipeline/createChildPipeline.d.ts +2 -2
  126. package/dist/pipeline/createChildPipeline.js +40 -121
  127. package/dist/pipeline/createJobsForComponent.d.ts +3 -0
  128. package/dist/pipeline/{createJobs.js → createJobsForComponent.js} +33 -192
  129. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +14 -0
  130. package/dist/pipeline/gitlab/createGitlabJobs.js +260 -0
  131. package/dist/pipeline/index.d.ts +1 -1
  132. package/dist/pipeline/index.js +1 -5
  133. package/dist/pipeline/packageManager.d.ts +1 -1
  134. package/dist/pipeline/packageManager.js +20 -173
  135. package/dist/pipeline/yarn/yarnUtils.d.ts +4 -0
  136. package/dist/pipeline/yarn/yarnUtils.js +193 -0
  137. package/dist/rules/index.d.ts +3 -1
  138. package/dist/rules/index.js +7 -6
  139. package/dist/runner/index.d.ts +2 -3
  140. package/dist/runner/index.js +0 -3
  141. package/dist/tsconfig.tsbuildinfo +1 -1
  142. package/dist/types/config.d.ts +19 -25
  143. package/dist/types/config.js +6 -16
  144. package/dist/types/context.d.ts +16 -3
  145. package/dist/types/environmentContext.d.ts +28 -0
  146. package/dist/types/environmentContext.js +3 -0
  147. package/dist/types/gitlab-types.d.ts +39 -7
  148. package/dist/types/index.js +0 -6
  149. package/dist/types/jobs.d.ts +25 -17
  150. package/dist/types/jobs.js +1 -1
  151. package/dist/types/pipeline.d.ts +1 -1
  152. package/dist/types/utils.d.ts +1 -0
  153. package/dist/types/utils.js +3 -0
  154. package/dist/utils/gitlab.d.ts +5 -0
  155. package/dist/utils/gitlab.js +48 -0
  156. package/dist/utils/index.js +5 -15
  157. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +1560 -0
  158. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +1560 -0
  159. package/examples/__snapshots__/cloud-run-non-public.ts.snap +1560 -0
  160. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +3092 -0
  161. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +3103 -0
  162. package/examples/__snapshots__/custom-build-job.ts.snap +1162 -0
  163. package/examples/__snapshots__/custom-envs.ts.snap +261 -0
  164. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +2280 -0
  165. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +4077 -0
  166. package/examples/__snapshots__/rails-k8s-with-worker.ts.snap +1911 -0
  167. package/examples/__snapshots__/wait-for-other-deploy.ts.snap +1626 -0
  168. package/examples/__utils__/helpers.ts +14 -0
  169. package/examples/cloud-run-memory-limit.ts +28 -0
  170. package/examples/cloud-run-no-cpu-throttling.ts +33 -0
  171. package/examples/cloud-run-non-public.ts +27 -0
  172. package/examples/cloud-run-with-sql-reuse-db.ts +54 -0
  173. package/examples/cloud-run-with-sql.ts +61 -0
  174. package/examples/custom-build-job.ts +28 -0
  175. package/examples/custom-envs.ts +31 -0
  176. package/examples/kubernetes-application-customization.ts +57 -0
  177. package/examples/kubernetes-with-jobs.ts +68 -0
  178. package/examples/rails-k8s-with-worker.ts +95 -0
  179. package/examples/wait-for-other-deploy.ts +36 -0
  180. package/package.json +16 -13
  181. package/scripts/bundle +2 -0
  182. package/src/build/base/createBuildJob.ts +12 -5
  183. package/src/build/base/{getBuildInfo.ts → writeBuildInfo.ts} +2 -2
  184. package/src/build/custom/buildJob.ts +64 -0
  185. package/src/build/custom/index.ts +7 -0
  186. package/src/build/docker.ts +58 -33
  187. package/src/build/index.ts +24 -5
  188. package/src/build/node/buildJob.ts +2 -2
  189. package/src/build/node/cache.ts +19 -8
  190. package/src/build/node/index.ts +1 -1
  191. package/src/build/node/meteor.ts +8 -2
  192. package/src/build/node/testJob.ts +4 -2
  193. package/src/build/node/yarn.ts +21 -10
  194. package/src/build/rails/build.ts +38 -0
  195. package/src/build/rails/index.ts +8 -0
  196. package/src/build/rails/test.ts +86 -0
  197. package/src/build/types.ts +97 -2
  198. package/src/catladder-gitlab.ts +4 -2
  199. package/src/config/{configruedEnvs.test.ts → __tests__/configruedEnvs.test.ts} +3 -3
  200. package/src/config/configruedEnvs.ts +2 -7
  201. package/src/config/readConfig.ts +1 -1
  202. package/src/context/{resolveReferences.test.ts → __tests__/resolveReferences.test.ts} +23 -38
  203. package/src/context/getEnvConfig.ts +21 -0
  204. package/src/context/getEnvType.ts +17 -0
  205. package/src/context/getEnvironment.ts +40 -0
  206. package/src/context/getEnvironmentContext.ts +57 -0
  207. package/src/context/getEnvironmentVariables.ts +155 -0
  208. package/src/context/getLabels.ts +20 -0
  209. package/src/context/index.ts +28 -193
  210. package/src/context/resolveReferences.ts +35 -31
  211. package/src/defaults/index.ts +1 -1
  212. package/src/deploy/base.ts +43 -19
  213. package/src/deploy/cloudRun/deployJob.ts +276 -0
  214. package/src/deploy/cloudRun/index.ts +95 -0
  215. package/src/deploy/cloudRun/utils/createArgsString.ts +26 -0
  216. package/src/deploy/cloudRun/utils/database.ts +55 -0
  217. package/src/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.ts +14 -0
  218. package/src/deploy/cloudRun/utils/jobName.ts +2 -0
  219. package/src/deploy/custom/deployJob.ts +13 -3
  220. package/src/deploy/custom/index.ts +9 -1
  221. package/src/deploy/dockerTag/deployJob.ts +31 -0
  222. package/src/deploy/dockerTag/index.ts +9 -0
  223. package/src/deploy/index.ts +26 -17
  224. package/src/deploy/kubernetes/additionalSecretKeys.ts +23 -0
  225. package/src/deploy/kubernetes/cloudSql/index.ts +28 -0
  226. package/src/deploy/kubernetes/deployJob.ts +21 -78
  227. package/src/deploy/kubernetes/index.ts +42 -1
  228. package/src/deploy/kubernetes/kubeEnv.ts +48 -0
  229. package/src/deploy/kubernetes/kubeValues.ts +96 -0
  230. package/src/deploy/kubernetes/mongodb.ts +104 -7
  231. package/src/deploy/kubernetes/processSecretsAsFiles.ts +1 -1
  232. package/src/deploy/types/base.ts +17 -0
  233. package/src/deploy/types/custom.ts +36 -0
  234. package/src/deploy/types/dockerTag.ts +12 -0
  235. package/src/deploy/types/googleCloudRun.ts +179 -0
  236. package/src/deploy/types/index.ts +28 -0
  237. package/src/deploy/types/kubernetes.ts +301 -0
  238. package/src/deploy/utils.ts +6 -2
  239. package/src/pipeline/commitInfo/getBuildId.ts +6 -0
  240. package/src/pipeline/commitInfo/getCommitInfo.ts +12 -0
  241. package/src/pipeline/createAllJobs.ts +38 -0
  242. package/src/pipeline/createChildPipeline.ts +9 -20
  243. package/src/pipeline/createJobsForComponent.ts +64 -0
  244. package/src/pipeline/gitlab/createGitlabJobs.ts +149 -0
  245. package/src/pipeline/index.ts +1 -1
  246. package/src/pipeline/packageManager.ts +4 -38
  247. package/src/pipeline/yarn/yarnUtils.ts +37 -0
  248. package/src/rules/index.ts +9 -6
  249. package/src/runner/index.ts +2 -1
  250. package/src/types/config.ts +26 -13
  251. package/src/types/context.ts +23 -2
  252. package/src/types/environmentContext.ts +33 -0
  253. package/src/types/gitlab-types.ts +36 -6
  254. package/src/types/jobs.ts +30 -6
  255. package/src/types/pipeline.ts +1 -1
  256. package/src/types/utils.ts +7 -0
  257. package/src/utils/gitlab.ts +23 -0
  258. package/tsconfig.json +3 -1
  259. package/dist/build/base/getBuildInfo.d.ts +0 -2
  260. package/dist/build/tests/storybook.test.d.ts +0 -1
  261. package/dist/context/resolveReferences.test.js +0 -141
  262. package/dist/deploy/kubernetes/cloudsql.d.ts +0 -6
  263. package/dist/deploy/kubernetes/cloudsql.js +0 -16
  264. package/dist/deploy/types.d.ts +0 -196
  265. package/dist/deploy/types.js +0 -16
  266. package/dist/pipeline/createChildPipeline.test.d.ts +0 -1
  267. package/dist/pipeline/createJobs.d.ts +0 -3
  268. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +0 -8
  269. package/dist/pipeline/gitlab/makeGitlabJob.js +0 -45
  270. package/src/build/tests/storybook.test.ts +0 -54
  271. package/src/deploy/kubernetes/cloudsql.ts +0 -12
  272. package/src/deploy/types.ts +0 -189
  273. package/src/pipeline/createChildPipeline.test.ts +0 -49
  274. package/src/pipeline/createJobs.ts +0 -195
  275. package/src/pipeline/gitlab/makeGitlabJob.ts +0 -16
@@ -0,0 +1,149 @@
1
+ import { isObject } from "lodash";
2
+ import { BASE_RETRY } from "../../defaults";
3
+ import type { GitlabJobDef } from "../../types";
4
+ import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
5
+ import type { AllCatladderJobs } from "../createAllJobs";
6
+
7
+ type AllGitlabJobs = Record<string, GitlabJobDef>;
8
+
9
+ const getFullJobName = (
10
+ name: string,
11
+ componentName: string,
12
+ env?: string | null
13
+ ) => {
14
+ if (env) {
15
+ return `${componentName} ${name} | ${env} `;
16
+ }
17
+ return `${componentName} ${name}`;
18
+ };
19
+
20
+ const getFullReferencedJobName = (
21
+ referencedJobName: string,
22
+ componentName: string,
23
+ env: string,
24
+ allJobs: AllCatladderJobs
25
+ ) => {
26
+ const referencedJob = allJobs[componentName]?.[env]?.find(
27
+ (j) => j.name === referencedJobName
28
+ );
29
+ if (!referencedJob) {
30
+ throw new Error(
31
+ `unknown job referenced: '${referencedJobName}' from '${env}:${componentName}'`
32
+ );
33
+ }
34
+ const envToSet = referencedJob.envMode !== "none" ? env : null;
35
+ return getFullJobName(referencedJobName, componentName, envToSet);
36
+ };
37
+
38
+ const getJobName = (need: CatladderJobNeed) =>
39
+ isObject(need) ? need.job : need;
40
+
41
+ export const makeGitlabJob = (
42
+ componentName: string,
43
+ env: string,
44
+ {
45
+ envMode,
46
+ needsStages,
47
+ needsOtherComponent,
48
+ name,
49
+ needs,
50
+ ...job
51
+ }: CatladderJob<string>,
52
+ allJobs: AllCatladderJobs
53
+ ): [fullName: string, job: GitlabJobDef] => {
54
+ const stage = envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
55
+
56
+ const needsFromStages: CatladderJob["needs"] = needsStages?.flatMap((n) => {
57
+ const referencedComponentName = componentName;
58
+ const allJobNamesFromThatStage =
59
+ allJobs[referencedComponentName]?.[env]
60
+ ?.filter((j) => j.stage === n.stage)
61
+ ?.map((j) => j.name) ?? [];
62
+
63
+ return allJobNamesFromThatStage.map((job) => ({
64
+ job,
65
+ artifacts: n.artifacts ?? false,
66
+ componentName: referencedComponentName,
67
+ }));
68
+ });
69
+ const cleanedNeeds: CatladderJob["needs"] = [
70
+ ...(needs ?? []),
71
+ // pull in legacy needs from other component, which is now identical to needs
72
+ ...(needsOtherComponent ?? []),
73
+ ...(needsFromStages ?? []),
74
+ ];
75
+
76
+ const gitlabNeeds: GitlabJobDef["needs"] = cleanedNeeds
77
+ ?.map((n) =>
78
+ isObject(n)
79
+ ? {
80
+ job: getFullReferencedJobName(
81
+ n.job,
82
+ n.componentName ?? componentName,
83
+ env,
84
+ allJobs
85
+ ),
86
+ artifacts: n.artifacts,
87
+ }
88
+ : getFullReferencedJobName(n, componentName, env, allJobs)
89
+ ) // sort in a predictable manner for snapshot tests
90
+ .sort((a, b) => getJobName(a).localeCompare(getJobName(b)));
91
+
92
+ const fullJobName = getFullJobName(
93
+ name,
94
+ componentName,
95
+ envMode !== "none" ? env : undefined
96
+ );
97
+
98
+ const gitlabJob = {
99
+ ...job,
100
+ stage,
101
+ environment: job.environment?.on_stop
102
+ ? {
103
+ ...job.environment,
104
+ on_stop: getFullReferencedJobName(
105
+ job.environment.on_stop,
106
+ componentName,
107
+ env,
108
+ allJobs
109
+ ),
110
+ }
111
+ : job.environment,
112
+ // sort in a predictable manner for snapshot tests
113
+ needs: gitlabNeeds,
114
+ retry: BASE_RETRY,
115
+ interruptible: true,
116
+ };
117
+
118
+ return [fullJobName, gitlabJob];
119
+ };
120
+
121
+ export const createGitlabJobs = async (
122
+ allJobs: AllCatladderJobs
123
+ ): Promise<AllGitlabJobs> => {
124
+ return Object.keys(allJobs).reduce((accForComponents, componentName) => {
125
+ const componentJobs = allJobs[componentName];
126
+ return {
127
+ ...accForComponents,
128
+ ...Object.keys(componentJobs).reduce((accForEnvs, env) => {
129
+ const jobs = componentJobs[env];
130
+
131
+ return {
132
+ ...accForEnvs,
133
+ ...jobs.reduce((accForJobs, job) => {
134
+ const [fullJobName, gitlabJob] = makeGitlabJob(
135
+ componentName,
136
+ env,
137
+ job,
138
+ allJobs
139
+ );
140
+ return {
141
+ ...accForJobs,
142
+ [fullJobName]: gitlabJob,
143
+ };
144
+ }, {} as AllGitlabJobs),
145
+ };
146
+ }, {} as AllGitlabJobs),
147
+ };
148
+ }, {} as AllGitlabJobs);
149
+ };
@@ -1,2 +1,2 @@
1
1
  export * from "./createChildPipeline";
2
- export * from "./createJobs";
2
+ export * from "./createJobsForComponent";
@@ -1,43 +1,9 @@
1
- import { exec } from "child-process-promise";
2
- import { Config, PackageManagerInfo } from "../types";
3
- import { pathEqual } from "path-equal";
4
- import memoizee from "memoizee";
5
- import { join } from "path";
6
1
  import { existsSync } from "fs";
2
+ import { join } from "path";
3
+ import { pathEqual } from "path-equal";
4
+ import type { Config, PackageManagerInfo } from "../types";
5
+ import { getWorkspaces, getYarnVersion } from "./yarn/yarnUtils";
7
6
 
8
- const execOrFail = async (cmd: string, onFail: string): Promise<string> => {
9
- try {
10
- return await exec(cmd).then((r) => r.stdout);
11
- } catch (e) {
12
- return onFail ?? null;
13
- }
14
- };
15
-
16
- const getYarnVersion = memoizee(
17
- async () => {
18
- return await execOrFail("yarn --version", "");
19
- },
20
- { promise: true }
21
- );
22
-
23
- const getWorkspaces = memoizee(
24
- async (isClassic: boolean): Promise<PackageManagerInfo["workspaces"]> => {
25
- return isClassic
26
- ? Object.values(
27
- JSON.parse(
28
- JSON.parse(await execOrFail("yarn workspaces --json info", "{}"))
29
- ?.data ?? "{}"
30
- )
31
- )
32
- : JSON.parse(
33
- `[${(await execOrFail("yarn workspaces list --json --verbose", ""))
34
- .trim()
35
- .split("\n")
36
- .join(",")}]`
37
- );
38
- },
39
- { promise: true }
40
- );
41
7
  export const getPackageManagerInfo = async (
42
8
  config: Config,
43
9
  componentName: string
@@ -0,0 +1,37 @@
1
+ import { exec } from "child-process-promise";
2
+ import memoizee from "memoizee";
3
+ import type { PackageManagerInfo } from "../../types";
4
+
5
+ const execOrFail = async (cmd: string, onFail: string): Promise<string> => {
6
+ try {
7
+ return await exec(cmd).then((r) => r.stdout);
8
+ } catch (e) {
9
+ return onFail ?? null;
10
+ }
11
+ };
12
+ // export for mocking
13
+ export const getYarnVersion = memoizee(
14
+ async () => {
15
+ return await execOrFail("yarn --version", "");
16
+ },
17
+ { promise: true }
18
+ );
19
+ // export for mocking
20
+ export const getWorkspaces = memoizee(
21
+ async (isClassic: boolean): Promise<PackageManagerInfo["workspaces"]> => {
22
+ return isClassic
23
+ ? Object.values(
24
+ JSON.parse(
25
+ JSON.parse(await execOrFail("yarn workspaces --json info", "{}"))
26
+ ?.data ?? "{}"
27
+ )
28
+ )
29
+ : JSON.parse(
30
+ `[${(await execOrFail("yarn workspaces list --json --verbose", ""))
31
+ .trim()
32
+ .split("\n")
33
+ .join(",")}]`
34
+ );
35
+ },
36
+ { promise: true }
37
+ );
@@ -1,6 +1,6 @@
1
- import { GitlabRule } from "../types";
1
+ import type { GitlabRule } from "../types";
2
2
 
3
- const NEVER_ON_RELEASE_COMMIT: GitlabRule = {
3
+ export const RULE_NEVER_ON_RELEASE_COMMIT: GitlabRule = {
4
4
  if: "$CI_COMMIT_MESSAGE =~ /^chore\\(release\\).*/",
5
5
  when: "never",
6
6
  };
@@ -8,7 +8,7 @@ export const RULES_ALWAYS: GitlabRule[] = [
8
8
  {
9
9
  if: "$CI_COMMIT_TAG",
10
10
  },
11
- NEVER_ON_RELEASE_COMMIT,
11
+ RULE_NEVER_ON_RELEASE_COMMIT,
12
12
  {
13
13
  if: "$CI_COMMIT_BRANCH =~ /^[0-9]+.([0-9]+|x).x$/",
14
14
  },
@@ -20,14 +20,17 @@ export const RULES_ALWAYS: GitlabRule[] = [
20
20
  },
21
21
  ];
22
22
 
23
+ export const RULE_CONDITION_MAIN_BRANCH =
24
+ "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH";
25
+
23
26
  export const RULES_RELEASE: GitlabRule[] = [
24
- NEVER_ON_RELEASE_COMMIT,
27
+ RULE_NEVER_ON_RELEASE_COMMIT,
25
28
  {
26
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $AUTO_RELEASE == "true"',
29
+ if: RULE_CONDITION_MAIN_BRANCH + ' && $AUTO_RELEASE == "true"',
27
30
  when: "on_success",
28
31
  },
29
32
  {
30
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH",
33
+ if: RULE_CONDITION_MAIN_BRANCH,
31
34
  when: "manual",
32
35
  },
33
36
  {
@@ -1,12 +1,13 @@
1
1
  import { PIPELINE_IMAGE_TAG, DOCKER_REGISTRY } from "../constants";
2
2
 
3
- type RunnerImageName =
3
+ export type RunnerImageName =
4
4
  | "jobs-default"
5
5
  | "jobs-meteor"
6
6
  | "jobs-testing-chrome"
7
7
  | "kubernetes"
8
8
  | "base-pipeline"
9
9
  | "docker-build"
10
+ | "gcloud"
10
11
  | "semantic-release";
11
12
  export const getRunnerImage = (imageName: RunnerImageName) =>
12
13
  DOCKER_REGISTRY + "/" + imageName + ":" + PIPELINE_IMAGE_TAG;
@@ -1,8 +1,9 @@
1
- import { BuildConfig } from "../build/types";
2
- import { DeployConfig } from "../deploy/types";
3
- import { PartialDeep } from "type-fest";
4
- import { CatladderJob } from "./jobs";
5
- import { Context } from "./context";
1
+ import type { BuildConfig } from "../build/types";
2
+ import type { DeployConfig } from "../deploy/types";
3
+
4
+ import type { CatladderJob } from "./jobs";
5
+ import type { Context } from "./context";
6
+ import type { PartialDeep } from "./utils";
6
7
  export type PipelineTrigger = "mainBranch" | "mr" | "taggedRelease";
7
8
 
8
9
  /**
@@ -11,7 +12,7 @@ export type PipelineTrigger = "mainBranch" | "mr" | "taggedRelease";
11
12
  */
12
13
  export const ENV_TYPES = {
13
14
  dev: {
14
- triggers: ["mainBranch", "taggedRelease"], // we also trigger dev on tagged release, so that the versions match
15
+ triggers: ["mainBranch"],
15
16
  },
16
17
  review: {
17
18
  triggers: ["mr"],
@@ -104,7 +105,12 @@ export type EnvConfig<E extends EnvType = EnvType> = {
104
105
  host?: string;
105
106
  } & PartialDeep<DefaultEnvConfig>;
106
107
 
107
- export type Env = {
108
+ export type EnvConfigWithComponent = EnvConfig<EnvType> & ComponentConfig;
109
+
110
+ export type CustomEnv = EnvConfig & {
111
+ type: EnvType;
112
+ };
113
+ export type Env<C extends ConfigProps = never> = {
108
114
  /**
109
115
  * local is a special env that is only used in local development
110
116
  */
@@ -114,13 +120,16 @@ export type Env = {
114
120
  stage?: EnvConfig<"stage"> | false;
115
121
  review?: EnvConfig<"review"> | false;
116
122
  prod?: EnvConfig<"prod"> | false;
117
- } & Record<string, EnvConfig | false>;
118
-
119
- export type ComponentConfig = {
123
+ // unfortunatly, typescript does not properly support objects with a mix of known and unknown properties.
124
+ // for backwards compatiblity we allow unknown props, but we cannot type it (typescript problem)
125
+ // however, we now support providing custom envs through a generic parameter of `Config`
126
+ } & Record<C["CustomEnvs"], CustomEnv> &
127
+ Record<string, any>;
128
+ export type ComponentConfig<C extends ConfigProps = never> = {
120
129
  /**
121
130
  * specify environment configurations
122
131
  */
123
- env?: Env;
132
+ env?: Env<C>;
124
133
  /**
125
134
  * the directory of the component (e.g. where the package.json or similar is located). You can set "." if you only have one app.
126
135
  */
@@ -137,7 +146,11 @@ export type ComponentConfig = {
137
146
  customJobs?: CatladderJob[] | ((context: Context) => CatladderJob[]);
138
147
  } & DefaultEnvConfig;
139
148
 
140
- export type Config = {
149
+ export type ConfigProps = {
150
+ CustomEnvs: string;
151
+ };
152
+
153
+ export type Config<C extends ConfigProps = never> = {
141
154
  /**
142
155
  * name of the customer or group
143
156
  */
@@ -155,7 +168,7 @@ export type Config = {
155
168
  /**
156
169
  * components (sub apps)
157
170
  */
158
- components: Record<string, ComponentConfig>;
171
+ components: Record<string, ComponentConfig<C>>;
159
172
 
160
173
  /**
161
174
  * additional meta data (only for organisational purposes)
@@ -1,11 +1,25 @@
1
- import { PipelineTrigger, ComponentConfig, Config, EnvType } from "./config";
1
+ import type {
2
+ PipelineTrigger,
3
+ ComponentConfig,
4
+ Config,
5
+ EnvType,
6
+ } from "./config";
2
7
 
3
8
  export type Environment = {
4
9
  host: string;
10
+ url: string;
11
+ /**
12
+ * the full name of the app. We use this as RELEASE_NAME in kubernetes and the service name in google cloud run
13
+ */
5
14
  fullName: string;
15
+
16
+ gitlabEnvironment: {
17
+ name: string;
18
+ url: string;
19
+ };
6
20
  shortName: string;
21
+ slugPrefix: string;
7
22
  slug: string;
8
- url: string;
9
23
  /**
10
24
  * env vars contain all build-time env vars. secrets have to be resolved (they are stored in gitlab)
11
25
  */
@@ -39,6 +53,13 @@ export type YarnPackageManagerInfo = {
39
53
  };
40
54
 
41
55
  export type PackageManagerInfo = YarnPackageManagerInfo;
56
+
57
+ export type ContextBeforeConfig = {
58
+ componentName: string;
59
+ fullConfig: Config;
60
+ commitInfo?: CommitInfo;
61
+ packageManagerInfo?: PackageManagerInfo;
62
+ };
42
63
  export type Context = {
43
64
  componentName: string;
44
65
  componentConfig: ComponentConfig;
@@ -0,0 +1,33 @@
1
+ import type { BuildConfigGeneric, BuildConfigType } from "../build";
2
+ import type { DeployConfigGeneric } from "../deploy";
3
+ import type { DeployConfigType } from "../deploy";
4
+ import type { Config, EnvConfigWithComponent, EnvType } from "./config";
5
+ import type { CommitInfo } from "./context";
6
+
7
+ export type EnvironmentContext<
8
+ B extends BuildConfigType,
9
+ D extends DeployConfigType
10
+ > = {
11
+ envConfigRaw: EnvConfigWithComponent;
12
+ buildConfigRaw: false | BuildConfigGeneric<B>;
13
+ deployConfigRaw: false | DeployConfigGeneric<D>;
14
+ commitInfo?: CommitInfo;
15
+ env: string;
16
+ envType: EnvType;
17
+ componentName: string;
18
+ fullName: string;
19
+ /**
20
+ * the environment slug without component name.
21
+ */
22
+ environmentSlugPrefix: string;
23
+ /**
24
+ * the full environment slug, including the componentName
25
+ */
26
+ environmentSlug: string;
27
+ gitlabEnvironmentName: string;
28
+
29
+ /**
30
+ * the full catladder config
31
+ */
32
+ fullConfig: Config;
33
+ };
@@ -1,11 +1,31 @@
1
1
  export type Artifacts = {
2
2
  paths: string[];
3
+ expire_in?: string;
4
+ when?: "always" | "on_success" | "on_failure";
5
+ reports?: ArtifactReports;
3
6
  };
7
+ // Reports won't show up on MRs until https://gitlab.com/groups/gitlab-org/-/epics/8205
8
+ export type ArtifactReports =
9
+ | { accessibility: string | string[] }
10
+ | { coverage_report: string | string[] }
11
+ | { codequality: string | string[] }
12
+ | { cyclonedx: string | string[] }
13
+ | { dotenv: string | string[] }
14
+ | { junit: string | string[] }
15
+ | { sast: string | string[] }
16
+ | { secret_detection: string | string[] }
17
+ | { terraform: string | string[] };
4
18
  export type GitlabJobCache = {
5
- key: string;
19
+ key: GitlabJobCacheKey;
6
20
  policy?: string;
7
21
  paths: string[];
8
22
  };
23
+ export type GitlabJobCacheKey =
24
+ | string
25
+ | {
26
+ files: string[];
27
+ prefix?: string;
28
+ };
9
29
  export type GitlabRule = {
10
30
  if?: string;
11
31
  when?: "always" | "on_success" | "manual" | "never"; // todo
@@ -16,18 +36,27 @@ export type Retry = {
16
36
  when: string[];
17
37
  };
18
38
 
19
- export type Service = {
39
+ export type GitlabJobService = {
20
40
  name: string;
21
- command: string[];
41
+ command?: string[];
42
+ entrypoint?: string[];
43
+ alias?: string;
22
44
  };
23
45
 
46
+ export type GitlabJobImage =
47
+ | string
48
+ | {
49
+ name: string;
50
+ entrypoint?: string[];
51
+ };
52
+
24
53
  export type GitlabEnvironment = {
25
54
  url: string;
26
55
  name: string;
27
56
  kubernetes?: {
28
57
  namespace?: string;
29
58
  };
30
- action?: "stop" | "start" | "prepare"; // defaults to start
59
+ action?: "stop" | "start" | "prepare" | "access"; // defaults to start
31
60
  on_stop?: string; // other job to run on stop
32
61
  auto_stop_in?: string;
33
62
  };
@@ -41,12 +70,13 @@ export type GitlabJobDef = {
41
70
  cache?: GitlabJobCache | GitlabJobCache[];
42
71
  artifacts?: Artifacts;
43
72
  retry?: Retry;
44
- services?: Service[];
45
- image?: string;
73
+ services?: GitlabJobService[];
74
+ image?: GitlabJobImage;
46
75
  variables?: GitlabVariables;
47
76
  dependencies?: string[];
48
77
  environment?: GitlabEnvironment;
49
78
  allow_failure?: boolean;
79
+ parallel?: number;
50
80
  trigger?: {
51
81
  strategy: "depend";
52
82
  include: Array<{
package/src/types/jobs.ts CHANGED
@@ -1,10 +1,11 @@
1
- import {
1
+ import type {
2
2
  Artifacts,
3
3
  GitlabEnvironment,
4
4
  GitlabJobCache,
5
5
  GitlabRule,
6
6
  GitlabVariables,
7
- Service,
7
+ GitlabJobService,
8
+ GitlabJobImage,
8
9
  } from "./gitlab-types";
9
10
 
10
11
  export const BASE_STAGES = [
@@ -13,10 +14,14 @@ export const BASE_STAGES = [
13
14
  "build",
14
15
  "deploy",
15
16
  "verify",
17
+ "rollback",
16
18
  "stop",
17
19
  ] as const;
18
20
  export type BaseStage = typeof BASE_STAGES[number];
19
21
 
22
+ export type CatladderJobNeed =
23
+ | string
24
+ | { job: string; artifacts: boolean; componentName?: string };
20
25
  export type CatladderJob<S = BaseStage> = {
21
26
  /**
22
27
  * the name of the job (without any env or app prefix and suffix)
@@ -49,9 +54,21 @@ export type CatladderJob<S = BaseStage> = {
49
54
  }[];
50
55
 
51
56
  /**
52
- * does this require another job?
57
+ * does this require another job (from the same component)?
58
+ *
59
+ * You can also require a job from another component if you set `componentName`
60
+ *
53
61
  */
54
- needs?: Array<string | { job: string; artifacts: boolean }>;
62
+ needs?: Array<CatladderJobNeed>;
63
+
64
+ /**
65
+ * @deprecated set `componentName` to `needs` if you want to wait for a job from another component
66
+ */
67
+ needsOtherComponent?: Array<{
68
+ componentName: string;
69
+ job: string;
70
+ artifacts: boolean;
71
+ }>;
55
72
  /**
56
73
  * cache config, we use here the same shape as gitlab itself
57
74
  */
@@ -65,12 +82,12 @@ export type CatladderJob<S = BaseStage> = {
65
82
  /**
66
83
  * additional services, mainly used for docker
67
84
  */
68
- services?: Service[];
85
+ services?: GitlabJobService[];
69
86
 
70
87
  /**
71
88
  * image to use
72
89
  */
73
- image?: string;
90
+ image?: GitlabJobImage;
74
91
 
75
92
  /**
76
93
  * variables to pass
@@ -85,4 +102,11 @@ export type CatladderJob<S = BaseStage> = {
85
102
  environment?: GitlabEnvironment;
86
103
 
87
104
  rules?: GitlabRule[];
105
+
106
+ /**
107
+ * How many instances of a job should be run in parallel.
108
+ * Useful for big test suites that can be split into multiple pipeline jobs.
109
+ * We use the same shape as GitLab itself.
110
+ */
111
+ parallel?: number;
88
112
  };
@@ -1,4 +1,4 @@
1
- import { GitlabJobDef, GitlabPipeline } from "./gitlab-types";
1
+ import type { GitlabJobDef, GitlabPipeline } from "./gitlab-types";
2
2
 
3
3
  export type PipelineType = "gitlab";
4
4
 
@@ -0,0 +1,7 @@
1
+ export type PartialDeep<T> = T extends any[]
2
+ ? T
3
+ : T extends Record<string, any>
4
+ ? {
5
+ [P in keyof T]?: PartialDeep<T[P]>;
6
+ }
7
+ : T;
@@ -0,0 +1,23 @@
1
+ export const allowFailureInScripts = (script: string[]): string[] => [
2
+ "set +e", // disable fail job on error
3
+ ...script,
4
+ "set -e", // reenable
5
+ ];
6
+
7
+ export const sanitizeForBashVariable = (name: string) =>
8
+ name.replace(/-/g, "_");
9
+
10
+ export const repeatOnFailure = (
11
+ command: string,
12
+ options: {
13
+ pauseInSeconds: number;
14
+ }
15
+ ): string => {
16
+ return `
17
+ until ${command} &> /dev/null
18
+ do
19
+ echo "Trying again."
20
+ sleep ${options.pauseInSeconds}
21
+ done
22
+ `;
23
+ };
package/tsconfig.json CHANGED
@@ -2,11 +2,13 @@
2
2
  "compilerOptions": {
3
3
  "lib": ["es2020", "DOM"],
4
4
  "strict": true,
5
+ "module": "CommonJS",
5
6
  "downlevelIteration": true,
6
7
  "declaration": true,
7
8
  "outDir": "dist",
9
+ "moduleResolution": "node",
8
10
  "esModuleInterop": true,
9
11
  "incremental": true
10
12
  },
11
- "include": ["./src"]
13
+ "include": ["./src", "tests"]
12
14
  }
@@ -1,2 +0,0 @@
1
- import { Context } from "../../types";
2
- export declare const getBuildInfo: (context: Context) => string[];
@@ -1 +0,0 @@
1
- export {};