@catladder/pipeline 1.153.0 → 1.154.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 (153) hide show
  1. package/dist/build/artifacts/createBuildJobArtifact.d.ts +3 -0
  2. package/dist/build/artifacts/createBuildJobArtifact.js +97 -0
  3. package/dist/build/base/createAppBuildJob.d.ts +3 -3
  4. package/dist/build/base/createAppBuildJob.js +9 -15
  5. package/dist/build/base/index.d.ts +6 -2
  6. package/dist/build/base/index.js +14 -5
  7. package/dist/build/base/writeDotEnv.js +2 -1
  8. package/dist/build/custom/__tests__/testJob.test.js +1 -1
  9. package/dist/build/custom/buildJob.js +3 -10
  10. package/dist/build/docker.js +3 -3
  11. package/dist/build/index.d.ts +13 -6
  12. package/dist/build/index.js +29 -7
  13. package/dist/build/node/buildJob.d.ts +7 -2
  14. package/dist/build/node/buildJob.js +40 -33
  15. package/dist/build/node/cache.d.ts +2 -2
  16. package/dist/build/node/cache.js +8 -4
  17. package/dist/build/node/index.d.ts +2 -2
  18. package/dist/build/node/meteor.js +3 -6
  19. package/dist/build/node/testJob.d.ts +3 -2
  20. package/dist/build/node/testJob.js +9 -4
  21. package/dist/build/node/yarn.js +1 -1
  22. package/dist/build/rails/build.d.ts +1 -1
  23. package/dist/build/rails/build.js +7 -2
  24. package/dist/build/rails/test.d.ts +1 -1
  25. package/dist/build/rails/test.js +5 -0
  26. package/dist/build/sbom.js +3 -2
  27. package/dist/build/types.d.ts +48 -4
  28. package/dist/build/types.js +7 -1
  29. package/dist/bundles/catladder-gitlab/index.js +2 -2
  30. package/dist/constants.js +1 -1
  31. package/dist/context/createAllComponentsContext.d.ts +12 -0
  32. package/dist/context/createAllComponentsContext.js +159 -0
  33. package/dist/context/createComponentContext.d.ts +1 -5
  34. package/dist/context/createComponentContext.js +82 -20
  35. package/dist/context/createWorkspaceContext.d.ts +16 -0
  36. package/dist/context/createWorkspaceContext.js +173 -0
  37. package/dist/context/getBuildInfoVariables.d.ts +1 -1
  38. package/dist/context/getEnvironmentContext.d.ts +1 -1
  39. package/dist/context/getEnvironmentVariables.d.ts +2 -2
  40. package/dist/context/getEnvironmentVariables.js +5 -4
  41. package/dist/context/getLabels.js +5 -5
  42. package/dist/deploy/base/deploy.d.ts +1 -1
  43. package/dist/deploy/base/deploy.js +18 -5
  44. package/dist/deploy/cloudRun/artifactsRegistry.js +2 -2
  45. package/dist/deploy/cloudRun/createJobs/common.d.ts +4 -4
  46. package/dist/deploy/cloudRun/index.d.ts +2 -2
  47. package/dist/deploy/custom/index.d.ts +2 -2
  48. package/dist/deploy/dockerTag/index.d.ts +2 -2
  49. package/dist/deploy/index.d.ts +7 -7
  50. package/dist/deploy/kubernetes/additionalSecretKeys.d.ts +3 -1
  51. package/dist/deploy/kubernetes/cloudSql/index.js +1 -1
  52. package/dist/deploy/kubernetes/deployJob.js +2 -2
  53. package/dist/deploy/kubernetes/index.d.ts +2 -2
  54. package/dist/deploy/sbom.d.ts +1 -1
  55. package/dist/deploy/sbom.js +4 -3
  56. package/dist/deploy/types/index.d.ts +3 -3
  57. package/dist/pipeline/createAllJobs.d.ts +12 -10
  58. package/dist/pipeline/createAllJobs.js +94 -51
  59. package/dist/pipeline/createJobsForComponent.js +2 -3
  60. package/dist/pipeline/createJobsForWorkspace.d.ts +3 -0
  61. package/dist/pipeline/createJobsForWorkspace.js +12 -0
  62. package/dist/pipeline/createMainPipeline.js +26 -6
  63. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +3 -16
  64. package/dist/pipeline/gitlab/createGitlabJobs.js +191 -73
  65. package/dist/pipeline/packageManager.d.ts +3 -2
  66. package/dist/pipeline/packageManager.js +43 -15
  67. package/dist/tsconfig.tsbuildinfo +1 -1
  68. package/dist/types/config.d.ts +5 -4
  69. package/dist/types/context.d.ts +80 -12
  70. package/dist/types/context.js +10 -1
  71. package/dist/types/environmentContext.d.ts +5 -6
  72. package/dist/types/jobs.d.ts +5 -0
  73. package/examples/__snapshots__/cloud-run-memory-limit.ts.snap +8 -8
  74. package/examples/__snapshots__/cloud-run-meteor-with-worker.ts.snap +8 -0
  75. package/examples/__snapshots__/cloud-run-no-cpu-throttling.ts.snap +8 -8
  76. package/examples/__snapshots__/cloud-run-no-service.ts.snap +8 -8
  77. package/examples/__snapshots__/cloud-run-non-public.ts.snap +8 -8
  78. package/examples/__snapshots__/cloud-run-post-stop-job.ts.snap +8 -8
  79. package/examples/__snapshots__/cloud-run-service-gen2.ts.snap +8 -8
  80. package/examples/__snapshots__/cloud-run-service-increase-timout.ts.snap +8 -8
  81. package/examples/__snapshots__/cloud-run-service-with-volumes.ts.snap +8 -8
  82. package/examples/__snapshots__/cloud-run-storybook.ts.snap +4 -8
  83. package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +4 -8
  84. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.ts.snap +16 -16
  85. package/examples/__snapshots__/cloud-run-with-sql.ts.snap +589 -1097
  86. package/examples/__snapshots__/cloud-run-with-worker.ts.snap +8 -8
  87. package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +4 -0
  88. package/examples/__snapshots__/custom-build-job.ts.snap +4 -0
  89. package/examples/__snapshots__/custom-deploy.ts.snap +8 -8
  90. package/examples/__snapshots__/custom-envs.ts.snap +18 -12
  91. package/examples/__snapshots__/custom-sbom-java.ts.snap +4 -0
  92. package/examples/__snapshots__/kubernetes-application-customization.ts.snap +8 -8
  93. package/examples/__snapshots__/kubernetes-with-cloud-sql-legacy.ts.snap +8 -8
  94. package/examples/__snapshots__/kubernetes-with-cloud-sql.ts.snap +8 -8
  95. package/examples/__snapshots__/kubernetes-with-jobs.ts.snap +16 -16
  96. package/examples/__snapshots__/kubernetes-with-mongodb.ts.snap +8 -8
  97. package/examples/__snapshots__/local-dot-env.ts.snap +8 -8
  98. package/examples/__snapshots__/meteor-kubernetes.ts.snap +8 -0
  99. package/examples/__snapshots__/multiline-var.ts.snap +16 -16
  100. package/examples/__snapshots__/native-app.ts.snap +24 -16
  101. package/examples/__snapshots__/node-build-with-custom-image.ts.snap +8 -8
  102. package/examples/__snapshots__/node-build-with-docker-additions.ts.snap +8 -8
  103. package/examples/__snapshots__/wait-for-other-deploy.ts.snap +16 -16
  104. package/examples/cloud-run-with-sql.ts +9 -2
  105. package/package.json +1 -1
  106. package/src/build/artifacts/createBuildJobArtifact.ts +61 -0
  107. package/src/build/base/createAppBuildJob.ts +26 -22
  108. package/src/build/base/index.ts +31 -4
  109. package/src/build/base/writeDotEnv.ts +6 -2
  110. package/src/build/custom/__tests__/testJob.test.ts +4 -4
  111. package/src/build/custom/buildJob.ts +2 -13
  112. package/src/build/docker.ts +6 -8
  113. package/src/build/index.ts +39 -7
  114. package/src/build/node/buildJob.ts +68 -56
  115. package/src/build/node/cache.ts +17 -8
  116. package/src/build/node/index.ts +4 -2
  117. package/src/build/node/meteor.ts +3 -9
  118. package/src/build/node/testJob.ts +21 -7
  119. package/src/build/node/yarn.ts +2 -2
  120. package/src/build/rails/build.ts +14 -4
  121. package/src/build/rails/test.ts +9 -1
  122. package/src/build/sbom.ts +7 -2
  123. package/src/build/types.ts +68 -4
  124. package/src/context/createAllComponentsContext.ts +31 -0
  125. package/src/context/createComponentContext.ts +59 -20
  126. package/src/context/createWorkspaceContext.ts +56 -0
  127. package/src/context/getBuildInfoVariables.ts +2 -1
  128. package/src/context/getEnvironmentContext.ts +2 -2
  129. package/src/context/getEnvironmentVariables.ts +12 -7
  130. package/src/context/getLabels.ts +3 -3
  131. package/src/deploy/base/deploy.ts +33 -7
  132. package/src/deploy/cloudRun/artifactsRegistry.ts +3 -4
  133. package/src/deploy/cloudRun/createJobs/common.ts +4 -4
  134. package/src/deploy/cloudRun/index.ts +68 -67
  135. package/src/deploy/custom/index.ts +2 -2
  136. package/src/deploy/dockerTag/index.ts +8 -7
  137. package/src/deploy/index.ts +11 -9
  138. package/src/deploy/kubernetes/additionalSecretKeys.ts +3 -1
  139. package/src/deploy/kubernetes/cloudSql/index.ts +1 -1
  140. package/src/deploy/kubernetes/deployJob.ts +2 -2
  141. package/src/deploy/kubernetes/index.ts +42 -41
  142. package/src/deploy/sbom.ts +9 -4
  143. package/src/pipeline/createAllJobs.ts +56 -55
  144. package/src/pipeline/createChildPipeline.ts +1 -0
  145. package/src/pipeline/createJobsForComponent.ts +5 -4
  146. package/src/pipeline/createJobsForWorkspace.ts +12 -0
  147. package/src/pipeline/createMainPipeline.ts +38 -23
  148. package/src/pipeline/gitlab/createGitlabJobs.ts +283 -119
  149. package/src/pipeline/packageManager.ts +25 -9
  150. package/src/types/config.ts +4 -1
  151. package/src/types/context.ts +108 -12
  152. package/src/types/environmentContext.ts +6 -7
  153. package/src/types/jobs.ts +3 -1
@@ -175,16 +175,24 @@ var utils_1 = require("../../utils");
175
175
  var gitlab_1 = require("../../utils/gitlab");
176
176
  var removeUndefined_1 = require("../../utils/removeUndefined");
177
177
  exports.GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
178
- var getFullJobName = function (name, componentName, env) {
178
+ var getFullJobName = function (_a) {
179
+ var type = _a.type,
180
+ name = _a.name,
181
+ baseName = _a.baseName,
182
+ allJobs = _a.allJobs,
183
+ env = _a.env;
184
+ var shouldAddIcon = allJobs.workspaces.length > 0;
185
+ var icon = type === "component" ? "🔹" : "🔸";
186
+ var prefix = shouldAddIcon ? icon + " " : "";
179
187
  if (env) {
180
- return "".concat(componentName, " ").concat(name, " | ").concat(env, " ");
188
+ return "".concat(prefix).concat(baseName, " ").concat(name, " | ").concat(env, " ");
181
189
  }
182
- return "".concat(componentName, " ").concat(name);
190
+ return "".concat(prefix).concat(baseName, " ").concat(name);
183
191
  };
184
- var getFullReferencedJobName = function (referencedJobName, componentName, env, allJobs) {
192
+ var getFullReferencedJobNameFromComponent = function (referencedJobName, componentName, env, allJobs) {
185
193
  var _a, _b;
186
- var referencedJob = (_b = (_a = allJobs.find(function (j) {
187
- return j.context.componentName === componentName && j.context.env === env;
194
+ var referencedJob = (_b = (_a = allJobs.components.find(function (j) {
195
+ return j.context.name === componentName && j.context.env === env;
188
196
  })) === null || _a === void 0 ? void 0 : _a.jobs) === null || _b === void 0 ? void 0 : _b.find(function (j) {
189
197
  return j.name === referencedJobName;
190
198
  });
@@ -192,61 +200,59 @@ var getFullReferencedJobName = function (referencedJobName, componentName, env,
192
200
  throw new Error("unknown job referenced: '".concat(referencedJobName, "' from '").concat(env, ":").concat(componentName, "'"));
193
201
  }
194
202
  var envToSet = referencedJob.envMode !== "none" ? env : null;
195
- return getFullJobName(referencedJobName, componentName, envToSet);
203
+ return getFullJobName({
204
+ type: "component",
205
+ name: referencedJobName,
206
+ baseName: componentName,
207
+ env: envToSet,
208
+ allJobs: allJobs
209
+ });
210
+ };
211
+ var getFullReferencedJobNameFromWorkspace = function (referencedJobName, workspaceName, env, allJobs) {
212
+ var _a, _b;
213
+ var referencedJob = (_b = (_a = allJobs.workspaces.find(function (w) {
214
+ return w.context.name === workspaceName;
215
+ })) === null || _a === void 0 ? void 0 : _a.jobs) === null || _b === void 0 ? void 0 : _b.find(function (j) {
216
+ return j.name === referencedJobName;
217
+ });
218
+ if (!referencedJob) {
219
+ throw new Error("unknown job referenced: '".concat(referencedJobName, "' from workspace ").concat(env, ":").concat(workspaceName, "'"));
220
+ }
221
+ var envToSet = referencedJob.envMode !== "none" ? env : null;
222
+ return getFullJobName({
223
+ type: "workspace",
224
+ name: referencedJobName,
225
+ baseName: workspaceName,
226
+ env: envToSet,
227
+ allJobs: allJobs
228
+ });
196
229
  };
197
230
  var getJobName = function (need) {
198
231
  return (0, lodash_1.isObject)(need) ? need.job : need;
199
232
  };
200
- var makeGitlabJob = function (context, _a, allJobs, baseRules) {
201
- var _b, _c;
202
- var environment = _a.environment,
203
- envMode = _a.envMode,
204
- needsStages = _a.needsStages,
205
- needsOtherComponent = _a.needsOtherComponent,
206
- name = _a.name,
207
- needs = _a.needs,
208
- jobTags = _a.jobTags,
209
- script = _a.script,
210
- variables = _a.variables,
211
- runnerVariables = _a.runnerVariables,
212
- when = _a.when,
213
- job = __rest(_a, ["environment", "envMode", "needsStages", "needsOtherComponent", "name", "needs", "jobTags", "script", "variables", "runnerVariables", "when"]);
233
+ var makeGitlabJob = function (context, job, allJobs, baseRules) {
234
+ var _a, _b;
235
+ var environment = job.environment,
236
+ envMode = job.envMode,
237
+ needsStages = job.needsStages,
238
+ needsOtherComponent = job.needsOtherComponent,
239
+ name = job.name,
240
+ needs = job.needs,
241
+ jobTags = job.jobTags,
242
+ script = job.script,
243
+ variables = job.variables,
244
+ runnerVariables = job.runnerVariables,
245
+ when = job.when,
246
+ rest = __rest(job, ["environment", "envMode", "needsStages", "needsOtherComponent", "name", "needs", "jobTags", "script", "variables", "runnerVariables", "when"]);
214
247
  var stage = envMode === "stagePerEnv" ? "".concat(job.stage, " ").concat(context.env) : job.stage;
215
- var needsFromStages = needsStages === null || needsStages === void 0 ? void 0 : needsStages.flatMap(function (n) {
216
- var _a, _b, _c;
217
- var referencedComponentName = context.componentName;
218
- var allJobNamesFromThatStage = (_c = (_b = (_a = allJobs.filter(function (j) {
219
- return j.context.componentName === referencedComponentName && j.context.env === context.env;
220
- }).flatMap(function (j) {
221
- return j.jobs;
222
- })) === null || _a === void 0 ? void 0 : _a.filter(function (j) {
223
- return j.stage === n.stage;
224
- })) === null || _b === void 0 ? void 0 : _b.map(function (j) {
225
- return j.name;
226
- })) !== null && _c !== void 0 ? _c : [];
227
- return allJobNamesFromThatStage.map(function (job) {
228
- var _a;
229
- return {
230
- job: job,
231
- artifacts: (_a = n.artifacts) !== null && _a !== void 0 ? _a : false,
232
- componentName: referencedComponentName
233
- };
234
- });
248
+ var deduplicatedGitlabNeeds = getGitlabNeeds(context, job, allJobs);
249
+ var fullJobName = getFullJobName({
250
+ type: context.type,
251
+ name: name,
252
+ baseName: context.name,
253
+ env: envMode !== "none" ? context.env : undefined,
254
+ allJobs: allJobs
235
255
  });
236
- var cleanedNeeds = __spreadArray(__spreadArray(__spreadArray([], __read(needsFromStages !== null && needsFromStages !== void 0 ? needsFromStages : []), false), __read(needs !== null && needs !== void 0 ? needs : []), false), __read(needsOtherComponent !== null && needsOtherComponent !== void 0 ? needsOtherComponent : []), false);
237
- var gitlabNeeds = cleanedNeeds === null || cleanedNeeds === void 0 ? void 0 : cleanedNeeds.map(function (n) {
238
- var _a;
239
- return (0, lodash_1.isObject)(n) ? {
240
- job: getFullReferencedJobName(n.job, (_a = n.componentName) !== null && _a !== void 0 ? _a : context.componentName, context.env, allJobs),
241
- artifacts: n.artifacts
242
- } : getFullReferencedJobName(n, context.componentName, context.env, allJobs);
243
- }).sort(function (a, b) {
244
- return getJobName(a).localeCompare(getJobName(b));
245
- });
246
- var deduplicatedGitlabNeeds = __spreadArray([], __read(new Map(gitlabNeeds.map(function (n) {
247
- return [(0, lodash_1.isObject)(n) ? n.job : n, n];
248
- })).values()), false);
249
- var fullJobName = getFullJobName(name, context.componentName, envMode !== "none" ? context.env : undefined);
250
256
  // backwards compatibility, some may still use KUBERNETES_CPU_REQUEST, KUBERNETES_MEMORY_REQUEST, etc. in variables.
251
257
  // 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
252
258
  var PIPELINE_RUNNER_VARIABLES = ["KUBERNETES_CPU_REQUEST", "KUBERNETES_MEMORY_REQUEST", "KUBERNETES_CPU_LIMIT", "KUBERNETES_MEMORY_LIMIT"];
@@ -266,51 +272,56 @@ var makeGitlabJob = function (context, _a, allJobs, baseRules) {
266
272
  if (Object.keys(legacyRunnerVariables).length > 0) {
267
273
  console.warn("Legacy variables detected in ".concat(fullJobName, ": ").concat(Object.keys(legacyRunnerVariables).join(", "), ". Please move them to the runnerVariables key."));
268
274
  }
269
- var rules = __spreadArray(__spreadArray([], __read((_b = job.rules) !== null && _b !== void 0 ? _b : []), false), __read(baseRules ? baseRules.map(function (rule) {
275
+ var rules = __spreadArray(__spreadArray([], __read((_a = job.rules) !== null && _a !== void 0 ? _a : []), false), __read(baseRules ? baseRules.map(function (rule) {
270
276
  return __assign({
271
277
  when: when
272
278
  }, rule);
273
279
  }) : when ? [{
274
280
  when: when
275
281
  }] : []), false);
276
- var modified = addGitlabEnvironment(context, environment, __assign(__assign({}, job), {
282
+ var gitlabJob = __assign(__assign({}, rest), {
277
283
  rules: rules.length > 0 ? rules : undefined,
278
284
  variables: __assign(__assign({}, legacyRunnerVariables), runnerVariables),
279
- script: __spreadArray(__spreadArray([], __read(varsInjectScripts), false), __read((_c = script === null || script === void 0 ? void 0 : script.filter(utils_1.notNil)) !== null && _c !== void 0 ? _c : []), false),
285
+ script: __spreadArray(__spreadArray([], __read(varsInjectScripts), false), __read((_b = script === null || script === void 0 ? void 0 : script.filter(utils_1.notNil)) !== null && _b !== void 0 ? _b : []), false),
280
286
  tags: jobTags,
281
287
  stage: stage,
282
288
  // sort in a predictable manner for snapshot tests
283
289
  needs: deduplicatedGitlabNeeds,
284
290
  retry: defaults_1.BASE_RETRY,
285
291
  interruptible: true
286
- }), context.componentName, context.env, allJobs);
292
+ });
293
+ var modified = addGitlabEnvironment(context, environment, gitlabJob, allJobs);
287
294
  return [fullJobName, (0, removeUndefined_1.removeUndefined)(modified)];
288
295
  };
289
296
  exports.makeGitlabJob = makeGitlabJob;
290
- var addGitlabEnvironment = function (context, environment, job, componentName, env,
291
- // TODO: we could actually pull this from contxt
292
- allJobs) {
297
+ var addGitlabEnvironment = function (context, catladderJobEnvironment, job, allJobs) {
293
298
  var _a, _b;
294
- if (!environment) {
299
+ if (!catladderJobEnvironment) {
300
+ return job;
301
+ }
302
+ if (context.type !== "component") {
303
+ // don't add enviornment for workspace jobs atm.
295
304
  return job;
296
305
  }
297
- var _c = context.environment,
298
- url = _c.url,
299
- envType = _c.envType;
300
- var on_stop = environment.on_stop,
301
- restEnvironment = __rest(environment, ["on_stop"]);
306
+ var env = context.env,
307
+ name = context.name,
308
+ environment = context.environment;
309
+ var url = environment.url,
310
+ envType = environment.envType;
311
+ var on_stop = catladderJobEnvironment.on_stop,
312
+ restEnvironment = __rest(catladderJobEnvironment, ["on_stop"]);
302
313
  // those can be dynamic, so we therefore have to do this: https://docs.gitlab.com/ee/ci/environments/#set-a-dynamic-environment-url
303
314
  var dotEnvFile = "gitlab_environment.env";
304
315
  var scriptToAdd = ["echo \"".concat(exports.GITLAB_ENVIRONMENT_URL_VARIABLE, "=").concat(url, "\" >> ").concat(dotEnvFile)];
305
316
  // this is NOT a bashVariable since it NEEDS to be used as a string in gitlab
306
- var gitlabEnvironmentName = envType === "review" ? "".concat(env, "/$CI_COMMIT_REF_NAME/").concat(componentName) // FIXME: should be replaced with mr name as well
307
- : "".concat(env, "/").concat(componentName);
317
+ var gitlabEnvironmentName = envType === "review" ? "".concat(env, "/$CI_COMMIT_REF_NAME/").concat(name) // FIXME: should be replaced with mr name as well
318
+ : "".concat(env, "/").concat(name);
308
319
  return __assign(__assign({}, job), {
309
320
  environment: __assign(__assign({
310
321
  name: gitlabEnvironmentName,
311
322
  url: "$".concat(exports.GITLAB_ENVIRONMENT_URL_VARIABLE)
312
323
  }, on_stop ? {
313
- on_stop: getFullReferencedJobName(on_stop, componentName, env, allJobs)
324
+ on_stop: getFullReferencedJobNameFromComponent(on_stop, name, env, allJobs)
314
325
  } : {}), restEnvironment),
315
326
  artifacts: (0, lodash_1.merge)((_a = job.artifacts) !== null && _a !== void 0 ? _a : {}, {
316
327
  reports: {
@@ -323,7 +334,8 @@ allJobs) {
323
334
  var createGitlabJobs = function (allJobs, baseRules) {
324
335
  return __awaiter(void 0, void 0, void 0, function () {
325
336
  return __generator(this, function (_a) {
326
- return [2 /*return*/, allJobs.flatMap(function (_a) {
337
+ // TODO: add workspace jobs
338
+ return [2 /*return*/, __spreadArray(__spreadArray([], __read(allJobs.workspaces), false), __read(allJobs.components), false).flatMap(function (_a) {
327
339
  var context = _a.context,
328
340
  jobs = _a.jobs;
329
341
  return jobs.map(function (job) {
@@ -340,4 +352,110 @@ var createGitlabJobs = function (allJobs, baseRules) {
340
352
  });
341
353
  });
342
354
  };
343
- exports.createGitlabJobs = createGitlabJobs;
355
+ exports.createGitlabJobs = createGitlabJobs;
356
+ function getGitlabNeeds(context, job, allJobs) {
357
+ var needs = context.type === "workspace" ? getGitlabNeedsForWorkspaceJob(context, job, allJobs) : getGitlabNeedsForComponentJob(context, job, allJobs);
358
+ return deduplicateNeeds(needs);
359
+ }
360
+ function deduplicateNeeds(needs) {
361
+ return needs ? __spreadArray([], __read(new Map(needs.map(function (n) {
362
+ return [(0, lodash_1.isObject)(n) ? n.job : n, n];
363
+ })).values()), false) : undefined;
364
+ }
365
+ function getGitlabNeedsForComponentJob(context, _a, allJobs) {
366
+ var needsStages = _a.needsStages,
367
+ needs = _a.needs,
368
+ needsOtherComponent = _a.needsOtherComponent;
369
+ var needsFromStages = needsStages === null || needsStages === void 0 ? void 0 : needsStages.flatMap(function (n) {
370
+ var _a, _b, _c, _d, _e, _f, _g, _h;
371
+ var componentName = context.name;
372
+ if (!n.workspaceName) {
373
+ var allJobNamesFromThatStage = (_c = (_b = (_a = allJobs.components.filter(function (j) {
374
+ return j.context.name === componentName && j.context.env === context.env;
375
+ }).flatMap(function (j) {
376
+ return j.jobs;
377
+ })) === null || _a === void 0 ? void 0 : _a.filter(function (j) {
378
+ return j.stage === n.stage;
379
+ })) === null || _b === void 0 ? void 0 : _b.map(function (j) {
380
+ return j.name;
381
+ })) !== null && _c !== void 0 ? _c : [];
382
+ return allJobNamesFromThatStage.map(function (job) {
383
+ var _a;
384
+ return {
385
+ job: job,
386
+ artifacts: (_a = n.artifacts) !== null && _a !== void 0 ? _a : false,
387
+ componentName: componentName
388
+ };
389
+ });
390
+ } else {
391
+ var allJobNamesFromThatStage = (_h = (_g = (_f = (_e = (_d = allJobs.workspaces.find(function (w) {
392
+ return w.context.name === n.workspaceName && w.context.env === context.env;
393
+ })) === null || _d === void 0 ? void 0 : _d.jobs) === null || _e === void 0 ? void 0 : _e.flatMap(function (j) {
394
+ return j;
395
+ })) === null || _f === void 0 ? void 0 : _f.filter(function (j) {
396
+ return j.stage === n.stage;
397
+ })) === null || _g === void 0 ? void 0 : _g.map(function (j) {
398
+ return j.name;
399
+ })) !== null && _h !== void 0 ? _h : [];
400
+ return allJobNamesFromThatStage.map(function (job) {
401
+ var _a;
402
+ return {
403
+ job: job,
404
+ artifacts: (_a = n.artifacts) !== null && _a !== void 0 ? _a : false,
405
+ workspaceName: n.workspaceName
406
+ };
407
+ });
408
+ }
409
+ });
410
+ var cleanedNeeds = __spreadArray(__spreadArray(__spreadArray([], __read(needsFromStages !== null && needsFromStages !== void 0 ? needsFromStages : []), false), __read(needs !== null && needs !== void 0 ? needs : []), false), __read(needsOtherComponent !== null && needsOtherComponent !== void 0 ? needsOtherComponent : []), false);
411
+ return cleanedNeeds === null || cleanedNeeds === void 0 ? void 0 : cleanedNeeds.map(function (n) {
412
+ var _a;
413
+ return (0, lodash_1.isObject)(n) ? "workspaceName" in n ? {
414
+ job: getFullReferencedJobNameFromWorkspace(n.job, n.workspaceName, context.env, allJobs),
415
+ artifacts: n.artifacts
416
+ } : {
417
+ job: getFullReferencedJobNameFromComponent(n.job, (_a = n.componentName) !== null && _a !== void 0 ? _a : context.name, context.env, allJobs),
418
+ artifacts: n.artifacts
419
+ } : getFullReferencedJobNameFromComponent(n, context.name, context.env, allJobs);
420
+ }).sort(function (a, b) {
421
+ return getJobName(a).localeCompare(getJobName(b));
422
+ });
423
+ }
424
+ /**
425
+ *
426
+ *unclear whether we actually need this. So far jobs in a workspace don't have needs to other jobs from the same workspace
427
+ */
428
+ function getGitlabNeedsForWorkspaceJob(context, _a, allJobs) {
429
+ var needsStages = _a.needsStages,
430
+ needs = _a.needs;
431
+ var needsFromStages = needsStages === null || needsStages === void 0 ? void 0 : needsStages.flatMap(function (n) {
432
+ var _a, _b, _c, _d;
433
+ var workspaceName = (_a = n.workspaceName) !== null && _a !== void 0 ? _a : context.name;
434
+ var allJobNamesFromThatStage = (_d = (_c = (_b = allJobs.workspaces.filter(function (j) {
435
+ return j.context.name === workspaceName && j.context.env === context.env;
436
+ }).flatMap(function (j) {
437
+ return j.jobs;
438
+ })) === null || _b === void 0 ? void 0 : _b.filter(function (j) {
439
+ return j.stage === n.stage;
440
+ })) === null || _c === void 0 ? void 0 : _c.map(function (j) {
441
+ return j.name;
442
+ })) !== null && _d !== void 0 ? _d : [];
443
+ return allJobNamesFromThatStage.map(function (job) {
444
+ var _a;
445
+ return {
446
+ job: job,
447
+ artifacts: (_a = n.artifacts) !== null && _a !== void 0 ? _a : false,
448
+ workspaceName: workspaceName
449
+ };
450
+ });
451
+ });
452
+ var cleanedNeeds = __spreadArray(__spreadArray([], __read(needsFromStages !== null && needsFromStages !== void 0 ? needsFromStages : []), false), __read(needs !== null && needs !== void 0 ? needs : []), false);
453
+ return cleanedNeeds === null || cleanedNeeds === void 0 ? void 0 : cleanedNeeds.map(function (n) {
454
+ return (0, lodash_1.isObject)(n) ? {
455
+ job: getFullReferencedJobNameFromWorkspace(n.job, "workspaceName" in n && n.workspaceName ? n.workspaceName : context.name, context.env, allJobs),
456
+ artifacts: n.artifacts
457
+ } : getFullReferencedJobNameFromWorkspace(n, context.name, context.env, allJobs);
458
+ }).sort(function (a, b) {
459
+ return getJobName(a).localeCompare(getJobName(b));
460
+ });
461
+ }
@@ -1,2 +1,3 @@
1
- import type { Config, PackageManagerInfoComponent } from "../types";
2
- export declare const getPackageManagerInfoForComponent: (config: Config, componentName: string) => Promise<PackageManagerInfoComponent>;
1
+ import type { Config, PackageManagerInfoBase, PackageManagerInfoComponent } from "../types";
2
+ export declare const getPackageManagerInfoForComponent: (config: Config, componentName: string) => Promise<PackageManagerInfoComponent>;
3
+ export declare const getPackageManagerInfoBase: () => Promise<PackageManagerInfoBase>;
@@ -1,5 +1,15 @@
1
1
  "use strict";
2
2
 
3
+ var __assign = this && this.__assign || function () {
4
+ __assign = Object.assign || function (t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
3
13
  var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
4
14
  function adopt(value) {
5
15
  return value instanceof P ? value : new P(function (resolve) {
@@ -149,26 +159,22 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
149
159
  Object.defineProperty(exports, "__esModule", {
150
160
  value: true
151
161
  });
152
- exports.getPackageManagerInfoForComponent = void 0;
162
+ exports.getPackageManagerInfoBase = exports.getPackageManagerInfoForComponent = void 0;
153
163
  var fs_1 = require("fs");
154
164
  var path_1 = require("path");
155
165
  var path_equal_1 = require("path-equal");
156
166
  var yarnUtils_1 = require("./yarn/yarnUtils");
157
167
  var getPackageManagerInfoForComponent = function (config, componentName) {
158
168
  return __awaiter(void 0, void 0, void 0, function () {
159
- var version, isClassic, component, workspaces, currentWorkspace, componentIsInWorkspace, workspaceRoot, packageJson, workspacePackageJson, lockFile, configFiles, configFilePaths, currentWorkspaceDependencies, pathsToCopyInDocker;
169
+ var baseInfo, workspaces, component, currentWorkspace, componentIsInWorkspace, workspaceRoot, packageJson, workspacePackageJson, lockFile, configFiles, configFilePaths, currentWorkspaceDependencies, pathsToCopyInDocker;
160
170
  return __generator(this, function (_a) {
161
171
  switch (_a.label) {
162
172
  case 0:
163
- return [4 /*yield*/, (0, yarnUtils_1.getYarnVersion)()];
173
+ return [4 /*yield*/, (0, exports.getPackageManagerInfoBase)()];
164
174
  case 1:
165
- version = _a.sent();
166
- if (!version) throw new Error("could not get yarn version");
167
- isClassic = version.startsWith("1");
175
+ baseInfo = _a.sent();
176
+ workspaces = baseInfo.workspaces;
168
177
  component = config.components[componentName];
169
- return [4 /*yield*/, (0, yarnUtils_1.getWorkspaces)(isClassic)];
170
- case 2:
171
- workspaces = _a.sent();
172
178
  currentWorkspace = workspaces.find(function (w) {
173
179
  return (0, path_equal_1.pathEqual)(component.dir, w.location);
174
180
  });
@@ -185,18 +191,40 @@ var getPackageManagerInfoForComponent = function (config, componentName) {
185
191
  });
186
192
  currentWorkspaceDependencies = currentWorkspace ? (0, yarnUtils_1.getWorkspaceDependencies)(currentWorkspace, workspaces) : [];
187
193
  pathsToCopyInDocker = __spreadArray(__spreadArray(__spreadArray(__spreadArray([packageJson], __read(workspacePackageJson ? [workspacePackageJson] : []), false), [lockFile], false), __read(configFilePaths), false), __read(currentWorkspaceDependencies), false);
188
- return [2 /*return*/, {
189
- type: "yarn",
190
- workspaces: workspaces,
191
- version: version,
192
- isClassic: isClassic,
194
+ return [2 /*return*/, __assign(__assign({}, baseInfo), {
193
195
  currentWorkspace: currentWorkspace,
194
196
  currentWorkspaceDependencies: currentWorkspaceDependencies,
195
197
  componentIsInWorkspace: componentIsInWorkspace,
196
198
  pathsToCopyInDocker: pathsToCopyInDocker
199
+ })];
200
+ }
201
+ });
202
+ });
203
+ };
204
+ exports.getPackageManagerInfoForComponent = getPackageManagerInfoForComponent;
205
+ // TODO: memoizee
206
+ var getPackageManagerInfoBase = function () {
207
+ return __awaiter(void 0, void 0, void 0, function () {
208
+ var version, isClassic, workspaces;
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0:
212
+ return [4 /*yield*/, (0, yarnUtils_1.getYarnVersion)()];
213
+ case 1:
214
+ version = _a.sent();
215
+ if (!version) throw new Error("could not get yarn version");
216
+ isClassic = version.startsWith("1");
217
+ return [4 /*yield*/, (0, yarnUtils_1.getWorkspaces)(isClassic)];
218
+ case 2:
219
+ workspaces = _a.sent();
220
+ return [2 /*return*/, {
221
+ type: "yarn",
222
+ workspaces: workspaces,
223
+ version: version,
224
+ isClassic: isClassic
197
225
  }];
198
226
  }
199
227
  });
200
228
  });
201
229
  };
202
- exports.getPackageManagerInfoForComponent = getPackageManagerInfoForComponent;
230
+ exports.getPackageManagerInfoBase = getPackageManagerInfoBase;