@catladder/pipeline 2.0.5 → 2.2.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 (93) hide show
  1. package/dist/build/base/writeDotEnv.js +0 -1
  2. package/dist/build/docker.js +0 -1
  3. package/dist/build/node/meteor.js +0 -1
  4. package/dist/build/rails/test.js +0 -1
  5. package/dist/build/types.d.ts +1 -1
  6. package/dist/catladder-gitlab.js +2 -3
  7. package/dist/config/readConfig.js +0 -1
  8. package/dist/constants.js +1 -1
  9. package/dist/context/getEnvironmentVariables.d.ts +1 -1
  10. package/dist/context/getEnvironmentVariables.js +0 -1
  11. package/dist/context/getReviewSlug.js +0 -1
  12. package/dist/deploy/cloudRun/createJobs/index.js +0 -1
  13. package/dist/deploy/kubernetes/deployJob.js +0 -1
  14. package/dist/deploy/types/index.d.ts +3 -3
  15. package/dist/pipeline/createMainPipeline.js +20 -6
  16. package/dist/pipeline/generatePipelineFiles.d.ts +7 -40
  17. package/dist/pipeline/generatePipelineFiles.js +113 -49
  18. package/dist/pipeline/gitlab/createGitlabJobs.d.ts +6 -4
  19. package/dist/pipeline/gitlab/gitlabReleaseJobs.d.ts +0 -2
  20. package/dist/pipeline/gitlab/gitlabReleaseJobs.js +2 -4
  21. package/dist/pipeline/index.d.ts +0 -1
  22. package/dist/pipeline/index.js +0 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/dist/types/config.d.ts +3 -3
  25. package/dist/types/gitlab-types.d.ts +2 -1
  26. package/dist/types/pipeline.d.ts +0 -1
  27. package/dist/utils/writeFiles.js +0 -2
  28. package/dist/variables/__tests__/resolveAllReferences.test.js +0 -1
  29. package/dist/variables/__tests__/resolveReferencesOnce.test.js +0 -3
  30. package/examples/__snapshots__/cloud-run-http2.test.ts.snap +0 -2
  31. package/examples/__snapshots__/cloud-run-memory-limit.test.ts.snap +0 -2
  32. package/examples/__snapshots__/cloud-run-meteor-with-worker.test.ts.snap +0 -2
  33. package/examples/__snapshots__/cloud-run-nextjs.test.ts.snap +0 -2
  34. package/examples/__snapshots__/cloud-run-no-cpu-throttling.test.ts.snap +0 -2
  35. package/examples/__snapshots__/cloud-run-no-service.test.ts.snap +0 -2
  36. package/examples/__snapshots__/cloud-run-non-public.test.ts.snap +0 -2
  37. package/examples/__snapshots__/cloud-run-post-stop-job.test.ts.snap +0 -2
  38. package/examples/__snapshots__/cloud-run-service-custom-vpc-connector.test.ts.snap +0 -2
  39. package/examples/__snapshots__/cloud-run-service-custom-vpc.test.ts.snap +0 -2
  40. package/examples/__snapshots__/cloud-run-service-gen2.test.ts.snap +0 -2
  41. package/examples/__snapshots__/cloud-run-service-increase-timout.test.ts.snap +0 -2
  42. package/examples/__snapshots__/cloud-run-service-with-volumes.test.ts.snap +0 -2
  43. package/examples/__snapshots__/cloud-run-storybook.test.ts.snap +0 -2
  44. package/examples/__snapshots__/cloud-run-with-ngnix.test.ts.snap +0 -2
  45. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +0 -2
  46. package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +0 -2
  47. package/examples/__snapshots__/cloud-run-with-worker.test.ts.snap +0 -2
  48. package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +0 -2
  49. package/examples/__snapshots__/custom-build-job.test.ts.snap +0 -2
  50. package/examples/__snapshots__/custom-deploy.test.ts.snap +0 -2
  51. package/examples/__snapshots__/custom-envs.test.ts.snap +0 -2
  52. package/examples/__snapshots__/custom-sbom-java.test.ts.snap +0 -2
  53. package/examples/__snapshots__/git-submodule.test.ts.snap +0 -2
  54. package/examples/__snapshots__/kubernetes-application-customization.test.ts.snap +0 -2
  55. package/examples/__snapshots__/kubernetes-with-cloud-sql.test.ts.snap +0 -2
  56. package/examples/__snapshots__/kubernetes-with-jobs.test.ts.snap +0 -2
  57. package/examples/__snapshots__/kubernetes-with-mongodb.test.ts.snap +0 -2
  58. package/examples/__snapshots__/local-dot-env.test.ts.snap +0 -2
  59. package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +0 -2
  60. package/examples/__snapshots__/multiline-var.test.ts.snap +0 -2
  61. package/examples/__snapshots__/native-app.test.ts.snap +0 -2
  62. package/examples/__snapshots__/node-build-with-custom-image.test.ts.snap +0 -2
  63. package/examples/__snapshots__/node-build-with-docker-additions.test.ts.snap +0 -2
  64. package/examples/__snapshots__/rails-k8s-with-worker-dockerfile.test.ts.snap +0 -2
  65. package/examples/__snapshots__/rails-k8s-with-worker.test.ts.snap +0 -2
  66. package/examples/__snapshots__/referencing-other-vars.test.ts.snap +0 -2
  67. package/examples/__snapshots__/wait-for-other-deploy.test.ts.snap +0 -2
  68. package/examples/__snapshots__/workspace-api-www-turbo-cache.test.ts.snap +0 -2
  69. package/examples/__snapshots__/workspace-api-www.test.ts.snap +0 -2
  70. package/examples/__utils__/helpers.ts +2 -18
  71. package/examples/rails-k8s-with-worker-dockerfile.test.ts +11 -4
  72. package/package.json +16 -17
  73. package/src/build/cache/createJobCache.ts +2 -2
  74. package/src/build/sbom.ts +2 -2
  75. package/src/catladder-gitlab.ts +2 -9
  76. package/src/config/readConfig.ts +0 -1
  77. package/src/context/createComponentContext.ts +1 -1
  78. package/src/context/getEnvironmentVariables.ts +1 -1
  79. package/src/deploy/base/deploy.ts +3 -3
  80. package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +1 -1
  81. package/src/pipeline/createMainPipeline.ts +17 -9
  82. package/src/pipeline/generatePipelineFiles.ts +82 -58
  83. package/src/pipeline/gitlab/createGitlabJobs.ts +4 -4
  84. package/src/pipeline/gitlab/gitlabReleaseJobs.ts +2 -4
  85. package/src/pipeline/index.ts +0 -1
  86. package/src/types/gitlab-types.ts +2 -1
  87. package/src/types/pipeline.ts +0 -4
  88. package/dist/pipeline/createChildPipeline.d.ts +0 -3
  89. package/dist/pipeline/createChildPipeline.js +0 -163
  90. package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.d.ts +0 -1
  91. package/dist/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.js +0 -29
  92. package/src/pipeline/createChildPipeline.ts +0 -37
  93. package/src/pipeline/gitlab/getPipelineTriggerForGitlabChildPipeline.ts +0 -46
@@ -64,5 +64,4 @@ var componentContextNeedsBuildTimeDotEnv = function (context) {
64
64
  var _a;
65
65
  return ((_a = context.componentConfig.dotEnv) !== null && _a !== void 0 ? _a : true) === true; // don't build when set to `local`
66
66
  };
67
-
68
67
  exports.componentContextNeedsBuildTimeDotEnv = componentContextNeedsBuildTimeDotEnv;
@@ -110,7 +110,6 @@ var getDockerBuildRunnerVariables = function () {
110
110
  DOCKER_BUILDKIT: "1" // see https://docs.docker.com/develop/develop-images/build_enhancements/
111
111
  };
112
112
  };
113
-
114
113
  var getDockerAdditions = function (build) {
115
114
  var _a, _b;
116
115
  if (!("docker" in build)) return {};
@@ -61,7 +61,6 @@ var createMeteorBuildJobs = function (context) {
61
61
  variables: {
62
62
  METEOR_DISABLE_OPTIMISTIC_CACHING: "1" // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
63
63
  },
64
-
65
64
  script: __spreadArray(__spreadArray([], __read(yarnInstall), false), ['echo "add healthcheck package"', "meteor add panter:healthroute --allow-superuser", "meteor add qualia:prod-shell --allow-superuser", 'TOOL_NODE_FLAGS="--max_old_space_size=3584 --min_semi_space_size=8 --max_semi_space_size=256 --optimize_for_size" meteor build ./dist --architecture os.linux.x86_64 --allow-superuser --server-only --directory', "cp ./__build_info.json ./dist/bundle/programs/server"], false)
66
65
  } : undefined,
67
66
  dockerBuild: {
@@ -73,7 +73,6 @@ var createRailsTestJobs = function (context) {
73
73
  files: ["Gemfile.lock"],
74
74
  prefix: "$CI_JOB_IMAGE" // a changed image might have different OS libraries which no longer work with the cached gems
75
75
  },
76
-
77
76
  paths: [bundlerCacheDir]
78
77
  };
79
78
  var auditJob = buildConfig.audit !== false ? __assign(__assign({
@@ -277,7 +277,7 @@ export type BuildConfigGeneric<T extends BuildConfigStandaloneType> = Extract<Bu
277
277
  type: T;
278
278
  }>;
279
279
  export declare const isStandaloneBuildConfig: (t: BuildConfig | false) => t is BuildConfigStandalone;
280
- export declare const isOfBuildType: <T extends ("custom" | "rails" | "node" | "meteor" | "node-static" | "storybook")[]>(t: BuildConfig, ...types: T) => t is Extract<BuildConfigNode, {
280
+ export declare const isOfBuildType: <T extends ("node" | "custom" | "rails" | "meteor" | "node-static" | "storybook")[]>(t: BuildConfig, ...types: T) => t is Extract<BuildConfigNode, {
281
281
  type: T[number];
282
282
  }> | Extract<BuildConfigNodeStatic, {
283
283
  type: T[number];
@@ -120,8 +120,7 @@ Object.defineProperty(exports, "__esModule", {
120
120
  });
121
121
  var config_1 = require("./config");
122
122
  var generatePipelineFiles_1 = require("./pipeline/generatePipelineFiles");
123
- var mode = process.argv[2] || "local";
124
- var config = (0, config_1.readConfig)().then(function (result) {
123
+ (0, config_1.readConfig)().then(function (result) {
125
124
  return __awaiter(void 0, void 0, void 0, function () {
126
125
  return __generator(this, function (_a) {
127
126
  switch (_a.label) {
@@ -129,7 +128,7 @@ var config = (0, config_1.readConfig)().then(function (result) {
129
128
  if (!(result === null || result === void 0 ? void 0 : result.config)) {
130
129
  throw new Error("no catladder config found");
131
130
  }
132
- return [4 /*yield*/, (0, generatePipelineFiles_1.generatePipelineFiles)(result.config, "gitlab", mode)];
131
+ return [4 /*yield*/, (0, generatePipelineFiles_1.generatePipelineFiles)(result.config, "gitlab")];
133
132
  case 1:
134
133
  _a.sent();
135
134
  return [2 /*return*/];
@@ -151,7 +151,6 @@ Object.defineProperty(exports, "__esModule", {
151
151
  });
152
152
  exports.readConfig = void 0;
153
153
  var fs_1 = require("fs");
154
- // eslint-disable-next-line @typescript-eslint/no-var-requires
155
154
  var tsx = require("tsx/cjs/api");
156
155
  var yaml_1 = require("yaml");
157
156
  // allows us to load ts files
package/dist/constants.js CHANGED
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
7
- exports.PIPELINE_IMAGE_TAG = "v2-0-5-d03973d6" || "latest";
7
+ exports.PIPELINE_IMAGE_TAG = "v2-2-0-123818a3" || "latest";
8
8
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "git.panter.ch:5001/catladder/catladder";
@@ -9,7 +9,7 @@ export type SecretEnvVar = {
9
9
  declare const getBasePredefinedVariables: (ctx: EnvironmentContext) => {
10
10
  ENV_SHORT: string;
11
11
  APP_DIR: string;
12
- ENV_TYPE: "stage" | "dev" | "review" | "prod" | "local";
12
+ ENV_TYPE: "dev" | "review" | "stage" | "prod" | "local";
13
13
  };
14
14
  type BasePredefinedVariables = ReturnType<typeof getBasePredefinedVariables>;
15
15
  export type PredefinedVariables = BasePredefinedVariables & {
@@ -246,7 +246,6 @@ var getEnvironmentVariables = function (ctx_1) {
246
246
  }), {
247
247
  shouldResolveReferences: false // we already do this here with replaceAllReferences recursivly until re replaced all
248
248
  })];
249
-
250
249
  case 1:
251
250
  otherEnvVars = _a.sent().envVars;
252
251
  return [2 /*return*/, otherEnvVars];
@@ -18,5 +18,4 @@ var getReviewSlug = function (envConfig, env, pipelineType) {
18
18
  }
19
19
  return null; // not a review app;
20
20
  };
21
-
22
21
  exports.getReviewSlug = getReviewSlug;
@@ -39,7 +39,6 @@ var createGoogleCloudRunDeployJobs = function (context) {
39
39
  artifacts: {
40
40
  paths: [constants_1.ENV_VARS_FILENAME // debug
41
41
  ],
42
-
43
42
  when: "always"
44
43
  }
45
44
  } : {}), {
@@ -67,7 +67,6 @@ var createKubernetesDeployJobs = function (context) {
67
67
  artifacts: {
68
68
  paths: [ALL_VALUES_FILE // debug
69
69
  ],
70
-
71
70
  when: "always"
72
71
  }
73
72
  } : {}), {
@@ -11,12 +11,12 @@ export type DeployConfigType = DeployConfig["type"];
11
11
  export type DeployConfigGeneric<T extends DeployConfigType> = Extract<DeployConfig, {
12
12
  type: T;
13
13
  }>;
14
- export declare const isOfDeployType: <T extends ("custom" | "dockerTag" | "google-cloudrun" | "kubernetes")[]>(t: DeployConfig | false | null | undefined, ...types: T) => t is Extract<DeployConfigCustom, {
14
+ export declare const isOfDeployType: <T extends ("kubernetes" | "custom" | "dockerTag" | "google-cloudrun")[]>(t: DeployConfig | false | null | undefined, ...types: T) => t is Extract<DeployConfigKubernetes, {
15
15
  type: T[number];
16
- }> | Extract<DeployConfigDockerTag, {
16
+ }> | Extract<DeployConfigCustom, {
17
17
  type: T[number];
18
18
  }> | Extract<DeployConfigCloudRun, {
19
19
  type: T[number];
20
- }> | Extract<DeployConfigKubernetes, {
20
+ }> | Extract<DeployConfigDockerTag, {
21
21
  type: T[number];
22
22
  }>;
@@ -200,7 +200,8 @@ var createMainPipeline = function (pipelineType, config) {
200
200
  case 1:
201
201
  allJobsPerTrigger = _a.sent();
202
202
  allWorkspaceJobs = allJobsPerTrigger.filter(function (j) {
203
- return j.context.type === "workspace";
203
+ var _a;
204
+ return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "workspace";
204
205
  }) // sort by componentName in the same order as they appear in the config
205
206
  // this is purely for better readability in git diffs when you add new components
206
207
  .sort(function (a, b) {
@@ -215,7 +216,8 @@ var createMainPipeline = function (pipelineType, config) {
215
216
  return aIndex - bIndex;
216
217
  });
217
218
  allComponentJobs = allJobsPerTrigger.filter(function (j) {
218
- return j.context.type === "component";
219
+ var _a;
220
+ return ((_a = j.context) === null || _a === void 0 ? void 0 : _a.type) === "component";
219
221
  })
220
222
  // sort by componentName in the same order as they appear in the config
221
223
  // this is purely for better readability in git diffs when you add new components
@@ -232,19 +234,31 @@ var createMainPipeline = function (pipelineType, config) {
232
234
  allJobs = __spreadArray(__spreadArray([], __read(allWorkspaceJobs), false), __read(allComponentJobs), false).reduce(function (acc, _a) {
233
235
  var _b, _c;
234
236
  var gitlabJob = _a.gitlabJob,
235
- name = _a.name;
237
+ name = _a.name,
238
+ context = _a.context;
236
239
  // merge jobs, if a job is already there, merge the rules
237
240
  // this is currently needed because of envMode: "none", which creates the same job for all triggers, so it can appear multiple times
238
241
  if (acc[name]) {
239
- acc[name].rules = __spreadArray(__spreadArray([], __read((_b = acc[name].rules) !== null && _b !== void 0 ? _b : []), false), __read((_c = gitlabJob.rules) !== null && _c !== void 0 ? _c : []), false);
242
+ acc[name].gitlabJob.rules = __spreadArray(__spreadArray([], __read((_b = acc[name].gitlabJob.rules) !== null && _b !== void 0 ? _b : []), false), __read((_c = gitlabJob.rules) !== null && _c !== void 0 ? _c : []), false);
240
243
  } else {
241
- acc[name] = gitlabJob;
244
+ acc[name] = {
245
+ context: context,
246
+ gitlabJob: gitlabJob
247
+ };
242
248
  }
243
249
  return acc;
244
250
  }, {});
245
251
  return [2 /*return*/, (0, createGitlabPipeline_1.createGitlabPipelineWithDefaults)({
246
252
  stages: __spreadArray(__spreadArray([], __read(stages), false), ["release"], false),
247
- jobs: __assign(__assign({}, allJobs), (0, gitlabReleaseJobs_1.getGitlabReleaseJobs)()),
253
+ jobs: __assign(__assign({}, allJobs), Object.fromEntries(Object.entries((0, gitlabReleaseJobs_1.getGitlabReleaseJobs)()).map(function (_a) {
254
+ var _b = __read(_a, 2),
255
+ name = _b[0],
256
+ gitlabJob = _b[1];
257
+ return [name, {
258
+ gitlabJob: gitlabJob,
259
+ context: null
260
+ }];
261
+ }))),
248
262
  variables: config.runnerVariables
249
263
  })];
250
264
  case 2:
@@ -1,40 +1,7 @@
1
- import type { Config, PipelineMode, PipelineType } from "../types";
2
- export declare function generateChildPipelineContent<T extends PipelineType>(config: Config, pipelineType: T): Promise<{
3
- image: string;
4
- stages: string[];
5
- variables: import("../types/gitlab-ci-yml").JobVariables1 | undefined;
6
- workflow: {
7
- rules: {
8
- if?: string | undefined;
9
- changes?: import("../types/gitlab-ci-yml").Changes | undefined;
10
- exists?: import("../types/gitlab-ci-yml").Exists | undefined;
11
- variables?: import("../types/gitlab-ci-yml").RulesVariables | undefined;
12
- when?: import("../types/gitlab-ci-yml").When | undefined;
13
- start_in?: string | undefined;
14
- allow_failure?: import("../types/gitlab-ci-yml").AllowFailure | undefined;
15
- needs?: import("../types/gitlab-ci-yml").RulesNeeds | undefined;
16
- }[];
17
- } | undefined;
18
- } & Omit<import("../types").Pipeline<T>, "image" | "jobs" | "variables" | "workflow" | "stages"> & {
19
- [k: string]: import("../types").GitlabJobDef;
20
- }>;
21
- export declare function generateLocalPipelineContent<T extends PipelineType>(config: Config, pipelineType: T): Promise<{
22
- image: string;
23
- stages: string[];
24
- variables: import("../types/gitlab-ci-yml").JobVariables1 | undefined;
25
- workflow: {
26
- rules: {
27
- if?: string | undefined;
28
- changes?: import("../types/gitlab-ci-yml").Changes | undefined;
29
- exists?: import("../types/gitlab-ci-yml").Exists | undefined;
30
- variables?: import("../types/gitlab-ci-yml").RulesVariables | undefined;
31
- when?: import("../types/gitlab-ci-yml").When | undefined;
32
- start_in?: string | undefined;
33
- allow_failure?: import("../types/gitlab-ci-yml").AllowFailure | undefined;
34
- needs?: import("../types/gitlab-ci-yml").RulesNeeds | undefined;
35
- }[];
36
- } | undefined;
37
- } & Omit<import("../types").Pipeline<T>, "image" | "jobs" | "variables" | "workflow" | "stages"> & {
38
- [k: string]: import("../types").GitlabJobDef;
39
- }>;
40
- export declare function generatePipelineFiles<T extends PipelineType>(config: Config, pipelineType: T, mode: PipelineMode<T>): Promise<void>;
1
+ import type { Config, PipelineType } from "../types";
2
+ export declare function generatePipelineFiles<T extends PipelineType>(config: Config, pipelineType: T): Promise<void>;
3
+ /**
4
+ *
5
+ * for testing purposes
6
+ */
7
+ export declare function getGitlabCompletePipeline(config: Config): Promise<{}>;
@@ -155,86 +155,150 @@ var __read = this && this.__read || function (o, n) {
155
155
  }
156
156
  return ar;
157
157
  };
158
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
159
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
160
+ if (ar || !(i in from)) {
161
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
162
+ ar[i] = from[i];
163
+ }
164
+ }
165
+ return to.concat(ar || Array.prototype.slice.call(from));
166
+ };
158
167
  Object.defineProperty(exports, "__esModule", {
159
168
  value: true
160
169
  });
161
- exports.generatePipelineFiles = exports.generateLocalPipelineContent = exports.generateChildPipelineContent = void 0;
170
+ exports.getGitlabCompletePipeline = exports.generatePipelineFiles = void 0;
171
+ var promises_1 = require("fs/promises");
172
+ var path_1 = require("path");
162
173
  var writeFiles_1 = require("../utils/writeFiles");
163
- var createChildPipeline_1 = require("./createChildPipeline");
164
174
  var createMainPipeline_1 = require("./createMainPipeline");
165
- var getPipelineTriggerForGitlabChildPipeline_1 = require("./gitlab/getPipelineTriggerForGitlabChildPipeline");
166
175
  var sortGitLabJobDefProps_1 = require("./gitlab/sortGitLabJobDefProps");
167
- function generateChildPipelineContent(config, pipelineType) {
176
+ var CATLADDER_GENERATED_FOLDER = ".catladder-generated";
177
+ var GITLAB_GENERATED_FOLDER = CATLADDER_GENERATED_FOLDER + "/gitlab";
178
+ function generatePipelineFiles(config, pipelineType) {
168
179
  return __awaiter(this, void 0, void 0, function () {
169
- var trigger, _a, jobs, image, stages, variables, workflow, pipelineRest, jobsWithSortedProps;
170
- return __generator(this, function (_b) {
171
- switch (_b.label) {
180
+ var includes, mainFile, files;
181
+ var _this = this;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
172
184
  case 0:
173
- trigger = (0, getPipelineTriggerForGitlabChildPipeline_1.getPipelineTriggerForGitlabChildPipeline)();
174
- return [4 /*yield*/, (0, createChildPipeline_1.createChildPipeline)(pipelineType, trigger, config)];
185
+ if (pipelineType !== "gitlab") {
186
+ throw new Error("Pipeline type not supported");
187
+ }
188
+ return [4 /*yield*/, getGitlabPipelineIncludes(config)];
175
189
  case 1:
176
- _a = _b.sent(), jobs = _a.jobs, image = _a.image, stages = _a.stages, variables = _a.variables, workflow = _a.workflow, pipelineRest = __rest(_a, ["jobs", "image", "stages", "variables", "workflow"]);
177
- jobsWithSortedProps = Object.fromEntries(Object.entries(jobs).map(function (_a) {
178
- var _b = __read(_a, 2),
179
- jobName = _b[0],
180
- job = _b[1];
181
- return [jobName, (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(job)];
182
- }));
183
- return [2 /*return*/, __assign(__assign({
184
- image: image,
185
- stages: stages,
186
- variables: variables,
187
- workflow: workflow
188
- }, pipelineRest), jobsWithSortedProps)];
190
+ includes = _a.sent();
191
+ mainFile = {
192
+ path: ".gitlab-ci.yml",
193
+ content: {
194
+ include: includes.map(function (i) {
195
+ return i.path;
196
+ })
197
+ }
198
+ };
199
+ files = __spreadArray([mainFile], __read(includes), false);
200
+ // first clean up the folder
201
+ return [4 /*yield*/, (0, promises_1.rm)(GITLAB_GENERATED_FOLDER, {
202
+ recursive: true
203
+ })];
204
+ case 2:
205
+ // first clean up the folder
206
+ _a.sent();
207
+ // write files
208
+ return [4 /*yield*/, Promise.all(files.map(function (_a) {
209
+ return __awaiter(_this, [_a], void 0, function (_b) {
210
+ var path = _b.path,
211
+ content = _b.content;
212
+ return __generator(this, function (_c) {
213
+ switch (_c.label) {
214
+ case 0:
215
+ return [4 /*yield*/, (0, promises_1.mkdir)((0, path_1.dirname)(path), {
216
+ recursive: true
217
+ })];
218
+ case 1:
219
+ _c.sent();
220
+ return [4 /*yield*/, (0, writeFiles_1.writeYamlfile)(path, content)];
221
+ case 2:
222
+ _c.sent();
223
+ return [2 /*return*/];
224
+ }
225
+ });
226
+ });
227
+ }))];
228
+ case 3:
229
+ // write files
230
+ _a.sent();
231
+ return [2 /*return*/];
189
232
  }
190
233
  });
191
234
  });
192
235
  }
193
- exports.generateChildPipelineContent = generateChildPipelineContent;
194
- function generateLocalPipelineContent(config, pipelineType) {
236
+ exports.generatePipelineFiles = generatePipelineFiles;
237
+ function getGitlabPipelineIncludes(config) {
195
238
  return __awaiter(this, void 0, void 0, function () {
196
- var _a, jobs, image, stages, variables, workflow, pipelineRest, jobsWithSortedProps;
239
+ var _a, jobs, image, stages, variables, workflow, pipelineRest, groups, componentIncludes, mainInclude, includes;
197
240
  return __generator(this, function (_b) {
198
241
  switch (_b.label) {
199
242
  case 0:
200
- return [4 /*yield*/, (0, createMainPipeline_1.createMainPipeline)(pipelineType, config)];
243
+ return [4 /*yield*/, (0, createMainPipeline_1.createMainPipeline)("gitlab", config)];
201
244
  case 1:
202
245
  _a = _b.sent(), jobs = _a.jobs, image = _a.image, stages = _a.stages, variables = _a.variables, workflow = _a.workflow, pipelineRest = __rest(_a, ["jobs", "image", "stages", "variables", "workflow"]);
203
- jobsWithSortedProps = Object.fromEntries(Object.entries(jobs).map(function (_a) {
246
+ groups = Object.entries(jobs).reduce(function (acc, _a) {
204
247
  var _b = __read(_a, 2),
205
248
  jobName = _b[0],
206
- job = _b[1];
207
- return [jobName, (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(job)];
208
- }));
209
- return [2 /*return*/, __assign(__assign({
210
- image: image,
211
- stages: stages,
212
- variables: variables,
213
- workflow: workflow
214
- }, pipelineRest), jobsWithSortedProps)];
249
+ _c = _b[1],
250
+ gitlabJob = _c.gitlabJob,
251
+ context = _c.context;
252
+ var group = !context ? "global-jobs" : (context === null || context === void 0 ? void 0 : context.type) + "/" + context.name;
253
+ if (!acc[group]) {
254
+ acc[group] = {};
255
+ }
256
+ acc[group][jobName] = (0, sortGitLabJobDefProps_1.sortGitLabJobDefProps)(gitlabJob); // also sort properties for more consistent diffing
257
+ return acc;
258
+ }, {});
259
+ componentIncludes = Object.entries(groups).map(function (_a) {
260
+ var _b = __read(_a, 2),
261
+ group = _b[0],
262
+ jobs = _b[1];
263
+ return {
264
+ path: GITLAB_GENERATED_FOLDER + "/" + group + ".yaml",
265
+ content: jobs
266
+ };
267
+ });
268
+ mainInclude = {
269
+ path: GITLAB_GENERATED_FOLDER + "/main.yaml",
270
+ content: __assign({
271
+ image: image,
272
+ stages: stages,
273
+ variables: variables,
274
+ workflow: workflow
275
+ }, pipelineRest)
276
+ };
277
+ includes = __spreadArray([mainInclude], __read(componentIncludes), false);
278
+ return [2 /*return*/, includes];
215
279
  }
216
280
  });
217
281
  });
218
282
  }
219
- exports.generateLocalPipelineContent = generateLocalPipelineContent;
220
- function generatePipelineFiles(config, pipelineType, mode) {
283
+ /**
284
+ *
285
+ * for testing purposes
286
+ */
287
+ function getGitlabCompletePipeline(config) {
221
288
  return __awaiter(this, void 0, void 0, function () {
222
- var pipelineContent_1, pipelineContent;
289
+ var includes;
223
290
  return __generator(this, function (_a) {
224
291
  switch (_a.label) {
225
292
  case 0:
226
- if (!(mode === "childpipeline")) return [3 /*break*/, 2];
227
- return [4 /*yield*/, generateChildPipelineContent(config, pipelineType)];
293
+ return [4 /*yield*/, getGitlabPipelineIncludes(config)];
228
294
  case 1:
229
- pipelineContent_1 = _a.sent();
230
- return [2 /*return*/, (0, writeFiles_1.writeYamlfile)("__pipeline.yml", pipelineContent_1)];
231
- case 2:
232
- return [4 /*yield*/, generateLocalPipelineContent(config, pipelineType)];
233
- case 3:
234
- pipelineContent = _a.sent();
235
- return [2 /*return*/, (0, writeFiles_1.writeYamlfile)(".gitlab-ci.yml", pipelineContent)];
295
+ includes = _a.sent();
296
+ return [2 /*return*/, includes.reduce(function (acc, _a) {
297
+ var content = _a.content;
298
+ return __assign(__assign({}, acc), content);
299
+ }, {})];
236
300
  }
237
301
  });
238
302
  });
239
303
  }
240
- exports.generatePipelineFiles = generatePipelineFiles;
304
+ exports.getGitlabCompletePipeline = getGitlabCompletePipeline;
@@ -1,11 +1,13 @@
1
1
  import type { Context, GitlabJobDef, GitlabRule } from "../../types";
2
2
  import type { CatladderJob } from "../../types/jobs";
3
3
  import type { AllCatladderJobs } from "../createAllJobs";
4
- export type AllGitlabJobs = {
5
- name: string;
4
+ export type GitlabJobWithContext = {
6
5
  gitlabJob: GitlabJobDef;
7
- context: Context;
8
- }[];
6
+ context: Context | null;
7
+ };
8
+ export type AllGitlabJobs = (GitlabJobWithContext & {
9
+ name: string;
10
+ })[];
9
11
  export declare const GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
10
12
  export declare const makeGitlabJob: (context: Context, job: CatladderJob<string>, allJobs: AllCatladderJobs, baseRules?: GitlabRule[]) => [fullName: string, job: GitlabJobDef];
11
13
  export declare const createGitlabJobs: (allJobs: AllCatladderJobs, baseRules?: GitlabRule[]) => Promise<AllGitlabJobs>;
@@ -3,7 +3,6 @@ export declare const getGitlabReleaseJobs: () => {
3
3
  stage: string;
4
4
  image: string;
5
5
  script: string[];
6
- after_script: string[];
7
6
  rules: {
8
7
  if?: string | undefined;
9
8
  changes?: import("../../types/gitlab-ci-yml").Changes | undefined;
@@ -19,7 +18,6 @@ export declare const getGitlabReleaseJobs: () => {
19
18
  stage: string;
20
19
  image: string;
21
20
  script: string[];
22
- after_script: string[];
23
21
  needs: never[];
24
22
  rules: {
25
23
  if?: string | undefined;
@@ -12,14 +12,12 @@ var getGitlabReleaseJobs = function () {
12
12
  return _a = {}, _a["create release"] = {
13
13
  stage: "release",
14
14
  image: (0, runner_1.getRunnerImage)("semantic-release"),
15
- script: ["semanticRelease"],
16
- after_script: [EXPIRED_TOKEN_HELP],
15
+ script: ["semanticRelease", EXPIRED_TOKEN_HELP],
17
16
  rules: rules_1.RULES_RELEASE
18
17
  }, _a["⚠️ force create release"] = {
19
18
  stage: "release",
20
19
  image: (0, runner_1.getRunnerImage)("semantic-release"),
21
- script: ["semanticRelease"],
22
- after_script: [EXPIRED_TOKEN_HELP],
20
+ script: ["semanticRelease", EXPIRED_TOKEN_HELP],
23
21
  needs: [],
24
22
  rules: rules_1.RULES_MANUAL_RELEASE
25
23
  }, _a;
@@ -1,4 +1,3 @@
1
- export * from "./createChildPipeline";
2
1
  export * from "./createJobsForComponent";
3
2
  export * from "./generatePipelineFiles";
4
3
  export * from "./gitlab/gitlabReleaseJobs";
@@ -22,7 +22,6 @@ var __exportStar = this && this.__exportStar || function (m, exports) {
22
22
  Object.defineProperty(exports, "__esModule", {
23
23
  value: true
24
24
  });
25
- __exportStar(require("./createChildPipeline"), exports);
26
25
  __exportStar(require("./createJobsForComponent"), exports);
27
26
  __exportStar(require("./generatePipelineFiles"), exports);
28
27
  __exportStar(require("./gitlab/gitlabReleaseJobs"), exports);