@catladder/cli 0.0.0-main-7d749f5d → 0.0.0-main-3df5566d

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 (31) hide show
  1. package/dist/bundles/catenv/index.js +93 -139
  2. package/dist/bundles/cli/index.js +84 -130
  3. package/dist/cli/src/apps/catenv/catenv.js +1 -1
  4. package/dist/cli/src/apps/catenv/catenv.js.map +1 -1
  5. package/dist/pipeline/src/build/types.d.ts +3 -3
  6. package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
  7. package/dist/pipeline/src/deploy/types/index.d.ts +3 -3
  8. package/dist/pipeline/src/pipeline/createMainPipeline.js +13 -7
  9. package/dist/pipeline/src/pipeline/createMainPipeline.js.map +1 -1
  10. package/dist/pipeline/src/pipeline/generatePipelineFiles.d.ts +7 -40
  11. package/dist/pipeline/src/pipeline/generatePipelineFiles.js +69 -42
  12. package/dist/pipeline/src/pipeline/generatePipelineFiles.js.map +1 -1
  13. package/dist/pipeline/src/pipeline/gitlab/createGitlabJobs.d.ts +6 -4
  14. package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.d.ts +0 -2
  15. package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js +2 -4
  16. package/dist/pipeline/src/pipeline/gitlab/gitlabReleaseJobs.js.map +1 -1
  17. package/dist/pipeline/src/pipeline/index.d.ts +0 -1
  18. package/dist/pipeline/src/pipeline/index.js +0 -1
  19. package/dist/pipeline/src/pipeline/index.js.map +1 -1
  20. package/dist/pipeline/src/types/config.d.ts +3 -3
  21. package/dist/pipeline/src/types/gitlab-types.d.ts +2 -1
  22. package/dist/pipeline/src/types/pipeline.d.ts +0 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +1 -1
  25. package/src/apps/catenv/catenv.ts +1 -1
  26. package/dist/pipeline/src/pipeline/createChildPipeline.d.ts +0 -3
  27. package/dist/pipeline/src/pipeline/createChildPipeline.js +0 -30
  28. package/dist/pipeline/src/pipeline/createChildPipeline.js.map +0 -1
  29. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +0 -1
  30. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +0 -32
  31. package/dist/pipeline/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js.map +0 -1
@@ -19,7 +19,7 @@ exports["default"] = async (choice) => {
19
19
  return;
20
20
  }
21
21
  await Promise.all([
22
- (0, pipeline_1.generatePipelineFiles)(config, (_a = config.pipelineType) !== null && _a !== void 0 ? _a : "gitlab", "local"),
22
+ (0, pipeline_1.generatePipelineFiles)(config, (_a = config.pipelineType) !== null && _a !== void 0 ? _a : "gitlab"),
23
23
  (0, writeDotEnvFiles_1.writeDotEnvFiles)(config, choice),
24
24
  (0, writeEnvDTs_1.writeDTsFiles)(config, choice),
25
25
  (0, printVariables_1.printVariables)(config, choice),
@@ -4095,7 +4095,7 @@ exports.getCloudRunDeployScripts = getCloudRunDeployScripts;
4095
4095
 
4096
4096
  /***/ }),
4097
4097
 
4098
- /***/ 3747:
4098
+ /***/ 8123:
4099
4099
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
4100
4100
 
4101
4101
  "use strict";
@@ -4145,7 +4145,7 @@ const base_1 = __nccwpck_require__(2024);
4145
4145
  const types_1 = __nccwpck_require__(5781);
4146
4146
  const constants_1 = __nccwpck_require__(8865);
4147
4147
  const getCloudRunDeployScripts_1 = __nccwpck_require__(3695);
4148
- const getCloudRunStopScripts_1 = __nccwpck_require__(3747);
4148
+ const getCloudRunStopScripts_1 = __nccwpck_require__(8123);
4149
4149
  const createGoogleCloudRunDeployJobs = (context) => {
4150
4150
  var _a;
4151
4151
  const deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config;
@@ -5209,7 +5209,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5209
5209
  exports.isOfDeployType = void 0;
5210
5210
  __exportStar(__nccwpck_require__(461), exports);
5211
5211
  __exportStar(__nccwpck_require__(6938), exports);
5212
- __exportStar(__nccwpck_require__(835), exports);
5212
+ __exportStar(__nccwpck_require__(8189), exports);
5213
5213
  __exportStar(__nccwpck_require__(282), exports);
5214
5214
  const isOfDeployType = (t, ...types) => {
5215
5215
  return t && types.includes(t.type) ? true : false;
@@ -5219,7 +5219,7 @@ exports.isOfDeployType = isOfDeployType;
5219
5219
 
5220
5220
  /***/ }),
5221
5221
 
5222
- /***/ 835:
5222
+ /***/ 8189:
5223
5223
  /***/ ((__unused_webpack_module, exports) => {
5224
5224
 
5225
5225
  "use strict";
@@ -5392,43 +5392,6 @@ exports.createAllJobs = createAllJobs;
5392
5392
 
5393
5393
  /***/ }),
5394
5394
 
5395
- /***/ 5139:
5396
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
5397
-
5398
- "use strict";
5399
-
5400
- Object.defineProperty(exports, "__esModule", ({ value: true }));
5401
- exports.createChildPipeline = void 0;
5402
- const rules_1 = __nccwpck_require__(7551);
5403
- const createAllJobs_1 = __nccwpck_require__(3579);
5404
- const getPipelineStages_1 = __nccwpck_require__(7585);
5405
- const createGitlabJobs_1 = __nccwpck_require__(8862);
5406
- const createGitlabPipeline_1 = __nccwpck_require__(6551);
5407
- const createChildPipeline = async (pipelineType, trigger, config) => {
5408
- const jobs = await (0, createAllJobs_1.createAllJobs)({
5409
- config,
5410
- trigger,
5411
- pipelineType,
5412
- });
5413
- const stages = (0, getPipelineStages_1.getPipelineStages)(config);
5414
- if (pipelineType === "gitlab") {
5415
- const gitlabJobs = await (0, createGitlabJobs_1.createGitlabJobs)(jobs);
5416
- return (0, createGitlabPipeline_1.createGitlabPipelineWithDefaults)({
5417
- workflow: {
5418
- rules: rules_1.RULES_ALWAYS,
5419
- },
5420
- stages,
5421
- jobs: Object.fromEntries(gitlabJobs.map(({ gitlabJob, name }) => [name, gitlabJob])),
5422
- variables: config.runnerVariables,
5423
- });
5424
- }
5425
- throw new Error(`${pipelineType} is not supported`);
5426
- };
5427
- exports.createChildPipeline = createChildPipeline;
5428
- //# sourceMappingURL=createChildPipeline.js.map
5429
-
5430
- /***/ }),
5431
-
5432
5395
  /***/ 2321:
5433
5396
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
5434
5397
 
@@ -5505,7 +5468,7 @@ const createMainPipeline = async (pipelineType, config) => {
5505
5468
  // for all triggers create jobs and add base rules
5506
5469
  const allJobsPerTrigger = await Promise.all(config_1.ALL_PIPELINE_TRIGGERS.map(async (trigger) => await (0, createGitlabJobs_1.createGitlabJobs)(await (0, createAllJobs_1.createAllJobs)({ config, trigger, pipelineType }), getGitlabRulesForTrigger(trigger)))).then((j) => j.flat());
5507
5470
  const allWorkspaceJobs = allJobsPerTrigger
5508
- .filter((j) => j.context.type === "workspace") // sort by componentName in the same order as they appear in the config
5471
+ .filter((j) => { var _a; return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "workspace"; }) // sort by componentName in the same order as they appear in the config
5509
5472
  // this is purely for better readability in git diffs when you add new components
5510
5473
  .sort((a, b) => {
5511
5474
  var _a;
@@ -5515,7 +5478,7 @@ const createMainPipeline = async (pipelineType, config) => {
5515
5478
  return aIndex - bIndex;
5516
5479
  });
5517
5480
  const allComponentJobs = allJobsPerTrigger
5518
- .filter((j) => j.context.type === "component")
5481
+ .filter((j) => { var _a; return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "component"; })
5519
5482
  // sort by componentName in the same order as they appear in the config
5520
5483
  // this is purely for better readability in git diffs when you add new components
5521
5484
  .sort((a, b) => {
@@ -5524,18 +5487,18 @@ const createMainPipeline = async (pipelineType, config) => {
5524
5487
  const bIndex = componentNames.findIndex((c) => c === b.context.name);
5525
5488
  return aIndex - bIndex;
5526
5489
  });
5527
- const allJobs = [...allWorkspaceJobs, ...allComponentJobs].reduce((acc, { gitlabJob, name }) => {
5490
+ const allJobs = [...allWorkspaceJobs, ...allComponentJobs].reduce((acc, { gitlabJob, name, context }) => {
5528
5491
  var _a, _b;
5529
5492
  // merge jobs, if a job is already there, merge the rules
5530
5493
  // this is currently needed because of envMode: "none", which creates the same job for all triggers, so it can appear multiple times
5531
5494
  if (acc[name]) {
5532
- acc[name].rules = [
5533
- ...((_a = acc[name].rules) !== null && _a !== void 0 ? _a : []),
5495
+ acc[name].gitlabJob.rules = [
5496
+ ...((_a = acc[name].gitlabJob.rules) !== null && _a !== void 0 ? _a : []),
5534
5497
  ...((_b = gitlabJob.rules) !== null && _b !== void 0 ? _b : []),
5535
5498
  ];
5536
5499
  }
5537
5500
  else {
5538
- acc[name] = gitlabJob;
5501
+ acc[name] = { context, gitlabJob };
5539
5502
  }
5540
5503
  return acc;
5541
5504
  }, {});
@@ -5543,7 +5506,13 @@ const createMainPipeline = async (pipelineType, config) => {
5543
5506
  stages: [...stages, "release"],
5544
5507
  jobs: {
5545
5508
  ...allJobs,
5546
- ...(0, gitlabReleaseJobs_1.getGitlabReleaseJobs)(),
5509
+ ...Object.fromEntries(Object.entries((0, gitlabReleaseJobs_1.getGitlabReleaseJobs)()).map(([name, gitlabJob]) => [
5510
+ name,
5511
+ {
5512
+ gitlabJob,
5513
+ context: null,
5514
+ },
5515
+ ])),
5547
5516
  },
5548
5517
  variables: config.runnerVariables,
5549
5518
  });
@@ -5574,56 +5543,83 @@ function getGitlabRulesForTrigger(trigger) {
5574
5543
  "use strict";
5575
5544
 
5576
5545
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5577
- exports.generatePipelineFiles = exports.generateLocalPipelineContent = exports.generateChildPipelineContent = void 0;
5546
+ exports.getGitlabCompletePipeline = exports.generatePipelineFiles = void 0;
5547
+ const promises_1 = __nccwpck_require__(3292);
5548
+ const path_1 = __nccwpck_require__(1017);
5578
5549
  const writeFiles_1 = __nccwpck_require__(2228);
5579
- const createChildPipeline_1 = __nccwpck_require__(5139);
5580
5550
  const createMainPipeline_1 = __nccwpck_require__(9192);
5581
- const getPipelineTriggerForGitlabChildPipeline_1 = __nccwpck_require__(7426);
5582
5551
  const sortGitLabJobDefProps_1 = __nccwpck_require__(2361);
5583
- async function generateChildPipelineContent(config, pipelineType) {
5584
- const trigger = (0, getPipelineTriggerForGitlabChildPipeline_1.getPipelineTriggerForGitlabChildPipeline)();
5585
- const { jobs, image, stages, variables, workflow, ...pipelineRest } = await (0, createChildPipeline_1.createChildPipeline)(pipelineType, trigger, config);
5586
- const jobsWithSortedProps = Object.fromEntries(Object.entries(jobs).map(([jobName, job]) => [
5587
- jobName,
5588
- (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(job),
5589
- ]));
5590
- return {
5591
- image,
5592
- stages,
5593
- variables,
5594
- workflow,
5595
- ...pipelineRest,
5596
- // jobs need to be spread into main YAML, because GitLab pipeline YAML has no jobs key - jobs are top level with their key as their name
5597
- ...jobsWithSortedProps,
5552
+ const CATLADDER_GENERATED_FOLDER = ".catladder-generated";
5553
+ const GITLAB_GENERATED_FOLDER = CATLADDER_GENERATED_FOLDER + "/gitlab";
5554
+ async function generatePipelineFiles(config, pipelineType) {
5555
+ if (pipelineType !== "gitlab") {
5556
+ throw new Error("Pipeline type not supported");
5557
+ }
5558
+ const includes = await getGitlabPipelineIncludes(config);
5559
+ const mainFile = {
5560
+ path: ".gitlab-ci.yml",
5561
+ content: {
5562
+ include: includes.map((i) => i.path),
5563
+ },
5598
5564
  };
5565
+ const files = [mainFile, ...includes];
5566
+ // first clean up the folder
5567
+ await (0, promises_1.rm)(GITLAB_GENERATED_FOLDER, { recursive: true });
5568
+ // write files
5569
+ await Promise.all(files.map(async ({ path, content }) => {
5570
+ await (0, promises_1.mkdir)((0, path_1.dirname)(path), { recursive: true });
5571
+ await (0, writeFiles_1.writeYamlfile)(path, content);
5572
+ }));
5599
5573
  }
5600
- exports.generateChildPipelineContent = generateChildPipelineContent;
5601
- async function generateLocalPipelineContent(config, pipelineType) {
5602
- const { jobs, image, stages, variables, workflow, ...pipelineRest } = await (0, createMainPipeline_1.createMainPipeline)(pipelineType, config);
5603
- const jobsWithSortedProps = Object.fromEntries(Object.entries(jobs).map(([jobName, job]) => [
5604
- jobName,
5605
- (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(job),
5606
- ]));
5607
- return {
5608
- image,
5609
- stages,
5610
- variables,
5611
- workflow,
5612
- ...pipelineRest,
5613
- // jobs need to be spread into main YAML, because GitLab pipeline YAML has no jobs key - jobs are top level with their key as their name
5614
- ...jobsWithSortedProps,
5574
+ exports.generatePipelineFiles = generatePipelineFiles;
5575
+ async function getGitlabPipelineIncludes(config) {
5576
+ const { jobs, image, stages, variables, workflow, ...pipelineRest } = await (0, createMainPipeline_1.createMainPipeline)("gitlab", config);
5577
+ // we will create 1 include per component or workspace
5578
+ // this is for better readability in git diffs and to avoid problems with yaml files beeing too large
5579
+ // group by context
5580
+ const groups = Object.entries(jobs).reduce((acc, [jobName, { gitlabJob, context }]) => {
5581
+ const group = !context
5582
+ ? "global-jobs"
5583
+ : (context === null || context === void 0 ? void 0 : context.type) + "/" + context.name;
5584
+ if (!acc[group]) {
5585
+ acc[group] = {};
5586
+ }
5587
+ acc[group][jobName] = (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(gitlabJob); // also sort properties for more consistent diffing
5588
+ return acc;
5589
+ }, {});
5590
+ const componentIncludes = Object.entries(groups).map(([group, jobs]) => {
5591
+ return {
5592
+ path: GITLAB_GENERATED_FOLDER + "/" + group + ".yaml",
5593
+ content: jobs,
5594
+ };
5595
+ });
5596
+ const mainInclude = {
5597
+ path: GITLAB_GENERATED_FOLDER + "/main.yaml",
5598
+ content: {
5599
+ image,
5600
+ stages,
5601
+ variables,
5602
+ workflow,
5603
+ ...pipelineRest,
5604
+ },
5615
5605
  };
5606
+ const includes = [mainInclude, ...componentIncludes];
5607
+ return includes;
5616
5608
  }
5617
- exports.generateLocalPipelineContent = generateLocalPipelineContent;
5618
- async function generatePipelineFiles(config, pipelineType, mode) {
5619
- if (mode === "childpipeline") {
5620
- const pipelineContent = await generateChildPipelineContent(config, pipelineType);
5621
- return (0, writeFiles_1.writeYamlfile)(`__pipeline.yml`, pipelineContent);
5622
- }
5623
- const pipelineContent = await generateLocalPipelineContent(config, pipelineType);
5624
- return (0, writeFiles_1.writeYamlfile)(`.gitlab-ci.yml`, pipelineContent);
5609
+ /**
5610
+ *
5611
+ * for testing purposes
5612
+ */
5613
+ async function getGitlabCompletePipeline(config) {
5614
+ const includes = await getGitlabPipelineIncludes(config);
5615
+ return includes.reduce((acc, { content }) => {
5616
+ return {
5617
+ ...acc,
5618
+ ...content, // merge all includes into one object
5619
+ };
5620
+ }, {});
5625
5621
  }
5626
- exports.generatePipelineFiles = generatePipelineFiles;
5622
+ exports.getGitlabCompletePipeline = getGitlabCompletePipeline;
5627
5623
  //# sourceMappingURL=generatePipelineFiles.js.map
5628
5624
 
5629
5625
  /***/ }),
@@ -5957,45 +5953,6 @@ exports.createGitlabPipelineWithDefaults = createGitlabPipelineWithDefaults;
5957
5953
 
5958
5954
  /***/ }),
5959
5955
 
5960
- /***/ 7426:
5961
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
5962
-
5963
- "use strict";
5964
-
5965
- Object.defineProperty(exports, "__esModule", ({ value: true }));
5966
- exports.getPipelineTriggerForGitlabChildPipeline = void 0;
5967
- const constants_1 = __nccwpck_require__(2898);
5968
- function getPipelineTriggerForGitlabChildPipeline() {
5969
- const { CI_MERGE_REQUEST_ID, CI_COMMIT_TAG, CI_COMMIT_BRANCH, CI_DEFAULT_BRANCH, } = process.env;
5970
- const isDefaultBranch = Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
5971
- const isHotfixBranch = CI_COMMIT_BRANCH
5972
- ? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
5973
- : false;
5974
- const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
5975
- const isTaggedRelease = Boolean(CI_COMMIT_TAG);
5976
- console.info(`catladder version ${constants_1.PIPELINE_IMAGE_TAG}`);
5977
- const trigger = isMergeRequest || isHotfixBranch
5978
- ? "mr"
5979
- : isDefaultBranch
5980
- ? "mainBranch"
5981
- : isTaggedRelease
5982
- ? "taggedRelease"
5983
- : null;
5984
- if (!trigger) {
5985
- throw new Error("no matching trigger: " +
5986
- JSON.stringify({
5987
- isMergeRequest,
5988
- isDefaultBranch,
5989
- isTaggedRelease,
5990
- }, null, 2));
5991
- }
5992
- return trigger;
5993
- }
5994
- exports.getPipelineTriggerForGitlabChildPipeline = getPipelineTriggerForGitlabChildPipeline;
5995
- //# sourceMappingURL=getPipelineTriggerForGitlabChildPipeline.js.map
5996
-
5997
- /***/ }),
5998
-
5999
5956
  /***/ 6564:
6000
5957
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6001
5958
 
@@ -6011,15 +5968,13 @@ const getGitlabReleaseJobs = () => {
6011
5968
  ["create release"]: {
6012
5969
  stage: "release",
6013
5970
  image: (0, runner_1.getRunnerImage)("semantic-release"),
6014
- script: ["semanticRelease"],
6015
- after_script: [EXPIRED_TOKEN_HELP],
5971
+ script: ["semanticRelease", EXPIRED_TOKEN_HELP],
6016
5972
  rules: rules_1.RULES_RELEASE,
6017
5973
  },
6018
5974
  ["⚠️ force create release"]: {
6019
5975
  stage: "release",
6020
5976
  image: (0, runner_1.getRunnerImage)("semantic-release"),
6021
- script: ["semanticRelease"],
6022
- after_script: [EXPIRED_TOKEN_HELP],
5977
+ script: ["semanticRelease", EXPIRED_TOKEN_HELP],
6023
5978
  needs: [],
6024
5979
  rules: rules_1.RULES_MANUAL_RELEASE,
6025
5980
  },
@@ -6107,7 +6062,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
6107
6062
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
6108
6063
  };
6109
6064
  Object.defineProperty(exports, "__esModule", ({ value: true }));
6110
- __exportStar(__nccwpck_require__(5139), exports);
6111
6065
  __exportStar(__nccwpck_require__(2321), exports);
6112
6066
  __exportStar(__nccwpck_require__(6169), exports);
6113
6067
  __exportStar(__nccwpck_require__(6564), exports);
@@ -34247,7 +34201,7 @@ module.exports = function (resolvers) {
34247
34201
 
34248
34202
 
34249
34203
  var isValue = __nccwpck_require__(566)
34250
- , isPlainFunction = __nccwpck_require__(1874)
34204
+ , isPlainFunction = __nccwpck_require__(3747)
34251
34205
  , assign = __nccwpck_require__(6584)
34252
34206
  , normalizeOpts = __nccwpck_require__(3637)
34253
34207
  , contains = __nccwpck_require__(7346);
@@ -35147,12 +35101,12 @@ module.exports = function (value) {
35147
35101
  "use strict";
35148
35102
 
35149
35103
 
35150
- module.exports = __nccwpck_require__(9975)() ? String.prototype.contains : __nccwpck_require__(3457);
35104
+ module.exports = __nccwpck_require__(835)() ? String.prototype.contains : __nccwpck_require__(3457);
35151
35105
 
35152
35106
 
35153
35107
  /***/ }),
35154
35108
 
35155
- /***/ 9975:
35109
+ /***/ 835:
35156
35110
  /***/ ((module) => {
35157
35111
 
35158
35112
  "use strict";
@@ -38444,7 +38398,7 @@ module.exports = function (value) {
38444
38398
 
38445
38399
  /***/ }),
38446
38400
 
38447
- /***/ 1874:
38401
+ /***/ 3747:
38448
38402
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
38449
38403
 
38450
38404
  "use strict";
@@ -8329,43 +8329,6 @@ exports.createAllJobs = createAllJobs;
8329
8329
 
8330
8330
  /***/ }),
8331
8331
 
8332
- /***/ 55139:
8333
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
8334
-
8335
- "use strict";
8336
-
8337
- Object.defineProperty(exports, "__esModule", ({ value: true }));
8338
- exports.createChildPipeline = void 0;
8339
- const rules_1 = __nccwpck_require__(47551);
8340
- const createAllJobs_1 = __nccwpck_require__(73579);
8341
- const getPipelineStages_1 = __nccwpck_require__(77585);
8342
- const createGitlabJobs_1 = __nccwpck_require__(58862);
8343
- const createGitlabPipeline_1 = __nccwpck_require__(66551);
8344
- const createChildPipeline = async (pipelineType, trigger, config) => {
8345
- const jobs = await (0, createAllJobs_1.createAllJobs)({
8346
- config,
8347
- trigger,
8348
- pipelineType,
8349
- });
8350
- const stages = (0, getPipelineStages_1.getPipelineStages)(config);
8351
- if (pipelineType === "gitlab") {
8352
- const gitlabJobs = await (0, createGitlabJobs_1.createGitlabJobs)(jobs);
8353
- return (0, createGitlabPipeline_1.createGitlabPipelineWithDefaults)({
8354
- workflow: {
8355
- rules: rules_1.RULES_ALWAYS,
8356
- },
8357
- stages,
8358
- jobs: Object.fromEntries(gitlabJobs.map(({ gitlabJob, name }) => [name, gitlabJob])),
8359
- variables: config.runnerVariables,
8360
- });
8361
- }
8362
- throw new Error(`${pipelineType} is not supported`);
8363
- };
8364
- exports.createChildPipeline = createChildPipeline;
8365
- //# sourceMappingURL=createChildPipeline.js.map
8366
-
8367
- /***/ }),
8368
-
8369
8332
  /***/ 92321:
8370
8333
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
8371
8334
 
@@ -8442,7 +8405,7 @@ const createMainPipeline = async (pipelineType, config) => {
8442
8405
  // for all triggers create jobs and add base rules
8443
8406
  const allJobsPerTrigger = await Promise.all(config_1.ALL_PIPELINE_TRIGGERS.map(async (trigger) => await (0, createGitlabJobs_1.createGitlabJobs)(await (0, createAllJobs_1.createAllJobs)({ config, trigger, pipelineType }), getGitlabRulesForTrigger(trigger)))).then((j) => j.flat());
8444
8407
  const allWorkspaceJobs = allJobsPerTrigger
8445
- .filter((j) => j.context.type === "workspace") // sort by componentName in the same order as they appear in the config
8408
+ .filter((j) => { var _a; return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "workspace"; }) // sort by componentName in the same order as they appear in the config
8446
8409
  // this is purely for better readability in git diffs when you add new components
8447
8410
  .sort((a, b) => {
8448
8411
  var _a;
@@ -8452,7 +8415,7 @@ const createMainPipeline = async (pipelineType, config) => {
8452
8415
  return aIndex - bIndex;
8453
8416
  });
8454
8417
  const allComponentJobs = allJobsPerTrigger
8455
- .filter((j) => j.context.type === "component")
8418
+ .filter((j) => { var _a; return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "component"; })
8456
8419
  // sort by componentName in the same order as they appear in the config
8457
8420
  // this is purely for better readability in git diffs when you add new components
8458
8421
  .sort((a, b) => {
@@ -8461,18 +8424,18 @@ const createMainPipeline = async (pipelineType, config) => {
8461
8424
  const bIndex = componentNames.findIndex((c) => c === b.context.name);
8462
8425
  return aIndex - bIndex;
8463
8426
  });
8464
- const allJobs = [...allWorkspaceJobs, ...allComponentJobs].reduce((acc, { gitlabJob, name }) => {
8427
+ const allJobs = [...allWorkspaceJobs, ...allComponentJobs].reduce((acc, { gitlabJob, name, context }) => {
8465
8428
  var _a, _b;
8466
8429
  // merge jobs, if a job is already there, merge the rules
8467
8430
  // this is currently needed because of envMode: "none", which creates the same job for all triggers, so it can appear multiple times
8468
8431
  if (acc[name]) {
8469
- acc[name].rules = [
8470
- ...((_a = acc[name].rules) !== null && _a !== void 0 ? _a : []),
8432
+ acc[name].gitlabJob.rules = [
8433
+ ...((_a = acc[name].gitlabJob.rules) !== null && _a !== void 0 ? _a : []),
8471
8434
  ...((_b = gitlabJob.rules) !== null && _b !== void 0 ? _b : []),
8472
8435
  ];
8473
8436
  }
8474
8437
  else {
8475
- acc[name] = gitlabJob;
8438
+ acc[name] = { context, gitlabJob };
8476
8439
  }
8477
8440
  return acc;
8478
8441
  }, {});
@@ -8480,7 +8443,13 @@ const createMainPipeline = async (pipelineType, config) => {
8480
8443
  stages: [...stages, "release"],
8481
8444
  jobs: {
8482
8445
  ...allJobs,
8483
- ...(0, gitlabReleaseJobs_1.getGitlabReleaseJobs)(),
8446
+ ...Object.fromEntries(Object.entries((0, gitlabReleaseJobs_1.getGitlabReleaseJobs)()).map(([name, gitlabJob]) => [
8447
+ name,
8448
+ {
8449
+ gitlabJob,
8450
+ context: null,
8451
+ },
8452
+ ])),
8484
8453
  },
8485
8454
  variables: config.runnerVariables,
8486
8455
  });
@@ -8511,56 +8480,83 @@ function getGitlabRulesForTrigger(trigger) {
8511
8480
  "use strict";
8512
8481
 
8513
8482
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8514
- exports.generatePipelineFiles = exports.generateLocalPipelineContent = exports.generateChildPipelineContent = void 0;
8483
+ exports.getGitlabCompletePipeline = exports.generatePipelineFiles = void 0;
8484
+ const promises_1 = __nccwpck_require__(73292);
8485
+ const path_1 = __nccwpck_require__(71017);
8515
8486
  const writeFiles_1 = __nccwpck_require__(92228);
8516
- const createChildPipeline_1 = __nccwpck_require__(55139);
8517
8487
  const createMainPipeline_1 = __nccwpck_require__(39192);
8518
- const getPipelineTriggerForGitlabChildPipeline_1 = __nccwpck_require__(7426);
8519
8488
  const sortGitLabJobDefProps_1 = __nccwpck_require__(72361);
8520
- async function generateChildPipelineContent(config, pipelineType) {
8521
- const trigger = (0, getPipelineTriggerForGitlabChildPipeline_1.getPipelineTriggerForGitlabChildPipeline)();
8522
- const { jobs, image, stages, variables, workflow, ...pipelineRest } = await (0, createChildPipeline_1.createChildPipeline)(pipelineType, trigger, config);
8523
- const jobsWithSortedProps = Object.fromEntries(Object.entries(jobs).map(([jobName, job]) => [
8524
- jobName,
8525
- (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(job),
8526
- ]));
8527
- return {
8528
- image,
8529
- stages,
8530
- variables,
8531
- workflow,
8532
- ...pipelineRest,
8533
- // jobs need to be spread into main YAML, because GitLab pipeline YAML has no jobs key - jobs are top level with their key as their name
8534
- ...jobsWithSortedProps,
8489
+ const CATLADDER_GENERATED_FOLDER = ".catladder-generated";
8490
+ const GITLAB_GENERATED_FOLDER = CATLADDER_GENERATED_FOLDER + "/gitlab";
8491
+ async function generatePipelineFiles(config, pipelineType) {
8492
+ if (pipelineType !== "gitlab") {
8493
+ throw new Error("Pipeline type not supported");
8494
+ }
8495
+ const includes = await getGitlabPipelineIncludes(config);
8496
+ const mainFile = {
8497
+ path: ".gitlab-ci.yml",
8498
+ content: {
8499
+ include: includes.map((i) => i.path),
8500
+ },
8535
8501
  };
8502
+ const files = [mainFile, ...includes];
8503
+ // first clean up the folder
8504
+ await (0, promises_1.rm)(GITLAB_GENERATED_FOLDER, { recursive: true });
8505
+ // write files
8506
+ await Promise.all(files.map(async ({ path, content }) => {
8507
+ await (0, promises_1.mkdir)((0, path_1.dirname)(path), { recursive: true });
8508
+ await (0, writeFiles_1.writeYamlfile)(path, content);
8509
+ }));
8536
8510
  }
8537
- exports.generateChildPipelineContent = generateChildPipelineContent;
8538
- async function generateLocalPipelineContent(config, pipelineType) {
8539
- const { jobs, image, stages, variables, workflow, ...pipelineRest } = await (0, createMainPipeline_1.createMainPipeline)(pipelineType, config);
8540
- const jobsWithSortedProps = Object.fromEntries(Object.entries(jobs).map(([jobName, job]) => [
8541
- jobName,
8542
- (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(job),
8543
- ]));
8544
- return {
8545
- image,
8546
- stages,
8547
- variables,
8548
- workflow,
8549
- ...pipelineRest,
8550
- // jobs need to be spread into main YAML, because GitLab pipeline YAML has no jobs key - jobs are top level with their key as their name
8551
- ...jobsWithSortedProps,
8511
+ exports.generatePipelineFiles = generatePipelineFiles;
8512
+ async function getGitlabPipelineIncludes(config) {
8513
+ const { jobs, image, stages, variables, workflow, ...pipelineRest } = await (0, createMainPipeline_1.createMainPipeline)("gitlab", config);
8514
+ // we will create 1 include per component or workspace
8515
+ // this is for better readability in git diffs and to avoid problems with yaml files beeing too large
8516
+ // group by context
8517
+ const groups = Object.entries(jobs).reduce((acc, [jobName, { gitlabJob, context }]) => {
8518
+ const group = !context
8519
+ ? "global-jobs"
8520
+ : (context === null || context === void 0 ? void 0 : context.type) + "/" + context.name;
8521
+ if (!acc[group]) {
8522
+ acc[group] = {};
8523
+ }
8524
+ acc[group][jobName] = (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(gitlabJob); // also sort properties for more consistent diffing
8525
+ return acc;
8526
+ }, {});
8527
+ const componentIncludes = Object.entries(groups).map(([group, jobs]) => {
8528
+ return {
8529
+ path: GITLAB_GENERATED_FOLDER + "/" + group + ".yaml",
8530
+ content: jobs,
8531
+ };
8532
+ });
8533
+ const mainInclude = {
8534
+ path: GITLAB_GENERATED_FOLDER + "/main.yaml",
8535
+ content: {
8536
+ image,
8537
+ stages,
8538
+ variables,
8539
+ workflow,
8540
+ ...pipelineRest,
8541
+ },
8552
8542
  };
8543
+ const includes = [mainInclude, ...componentIncludes];
8544
+ return includes;
8553
8545
  }
8554
- exports.generateLocalPipelineContent = generateLocalPipelineContent;
8555
- async function generatePipelineFiles(config, pipelineType, mode) {
8556
- if (mode === "childpipeline") {
8557
- const pipelineContent = await generateChildPipelineContent(config, pipelineType);
8558
- return (0, writeFiles_1.writeYamlfile)(`__pipeline.yml`, pipelineContent);
8559
- }
8560
- const pipelineContent = await generateLocalPipelineContent(config, pipelineType);
8561
- return (0, writeFiles_1.writeYamlfile)(`.gitlab-ci.yml`, pipelineContent);
8546
+ /**
8547
+ *
8548
+ * for testing purposes
8549
+ */
8550
+ async function getGitlabCompletePipeline(config) {
8551
+ const includes = await getGitlabPipelineIncludes(config);
8552
+ return includes.reduce((acc, { content }) => {
8553
+ return {
8554
+ ...acc,
8555
+ ...content, // merge all includes into one object
8556
+ };
8557
+ }, {});
8562
8558
  }
8563
- exports.generatePipelineFiles = generatePipelineFiles;
8559
+ exports.getGitlabCompletePipeline = getGitlabCompletePipeline;
8564
8560
  //# sourceMappingURL=generatePipelineFiles.js.map
8565
8561
 
8566
8562
  /***/ }),
@@ -8894,45 +8890,6 @@ exports.createGitlabPipelineWithDefaults = createGitlabPipelineWithDefaults;
8894
8890
 
8895
8891
  /***/ }),
8896
8892
 
8897
- /***/ 7426:
8898
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
8899
-
8900
- "use strict";
8901
-
8902
- Object.defineProperty(exports, "__esModule", ({ value: true }));
8903
- exports.getPipelineTriggerForGitlabChildPipeline = void 0;
8904
- const constants_1 = __nccwpck_require__(62898);
8905
- function getPipelineTriggerForGitlabChildPipeline() {
8906
- const { CI_MERGE_REQUEST_ID, CI_COMMIT_TAG, CI_COMMIT_BRANCH, CI_DEFAULT_BRANCH, } = process.env;
8907
- const isDefaultBranch = Boolean(CI_DEFAULT_BRANCH) && CI_COMMIT_BRANCH === CI_DEFAULT_BRANCH;
8908
- const isHotfixBranch = CI_COMMIT_BRANCH
8909
- ? /^[0-9]+\.([0-9]+|x)\.x$/.test(CI_COMMIT_BRANCH)
8910
- : false;
8911
- const isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
8912
- const isTaggedRelease = Boolean(CI_COMMIT_TAG);
8913
- console.info(`catladder version ${constants_1.PIPELINE_IMAGE_TAG}`);
8914
- const trigger = isMergeRequest || isHotfixBranch
8915
- ? "mr"
8916
- : isDefaultBranch
8917
- ? "mainBranch"
8918
- : isTaggedRelease
8919
- ? "taggedRelease"
8920
- : null;
8921
- if (!trigger) {
8922
- throw new Error("no matching trigger: " +
8923
- JSON.stringify({
8924
- isMergeRequest,
8925
- isDefaultBranch,
8926
- isTaggedRelease,
8927
- }, null, 2));
8928
- }
8929
- return trigger;
8930
- }
8931
- exports.getPipelineTriggerForGitlabChildPipeline = getPipelineTriggerForGitlabChildPipeline;
8932
- //# sourceMappingURL=getPipelineTriggerForGitlabChildPipeline.js.map
8933
-
8934
- /***/ }),
8935
-
8936
8893
  /***/ 16564:
8937
8894
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
8938
8895
 
@@ -8948,15 +8905,13 @@ const getGitlabReleaseJobs = () => {
8948
8905
  ["create release"]: {
8949
8906
  stage: "release",
8950
8907
  image: (0, runner_1.getRunnerImage)("semantic-release"),
8951
- script: ["semanticRelease"],
8952
- after_script: [EXPIRED_TOKEN_HELP],
8908
+ script: ["semanticRelease", EXPIRED_TOKEN_HELP],
8953
8909
  rules: rules_1.RULES_RELEASE,
8954
8910
  },
8955
8911
  ["⚠️ force create release"]: {
8956
8912
  stage: "release",
8957
8913
  image: (0, runner_1.getRunnerImage)("semantic-release"),
8958
- script: ["semanticRelease"],
8959
- after_script: [EXPIRED_TOKEN_HELP],
8914
+ script: ["semanticRelease", EXPIRED_TOKEN_HELP],
8960
8915
  needs: [],
8961
8916
  rules: rules_1.RULES_MANUAL_RELEASE,
8962
8917
  },
@@ -9044,7 +8999,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
9044
8999
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
9045
9000
  };
9046
9001
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9047
- __exportStar(__nccwpck_require__(55139), exports);
9048
9002
  __exportStar(__nccwpck_require__(92321), exports);
9049
9003
  __exportStar(__nccwpck_require__(96169), exports);
9050
9004
  __exportStar(__nccwpck_require__(16564), exports);