@catladder/pipeline 0.0.0-main-a6000978 โ†’ 0.0.0-main-57e22cfd

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.
@@ -1,5 +1,5 @@
1
1
  import { GitlabJobCache, GitlabJobs } from "../types/gitlab-types";
2
2
  import { Context } from "../types/context";
3
- export declare const getNodeCache: (policy?: string) => GitlabJobCache[];
3
+ export declare const getNodeCache: (context: Context) => GitlabJobCache[];
4
4
  export declare const createStorybookJobs: (context: Context) => GitlabJobs;
5
5
  export declare const createNodeJobs: (context: Context) => GitlabJobs;
@@ -58,6 +58,8 @@ var types_1 = require("./types");
58
58
 
59
59
  var utils_1 = require("../utils");
60
60
 
61
+ var path_1 = require("path");
62
+
61
63
  var NODE_RUNNER_BUILD_VARIABLES = {
62
64
  KUBERNETES_CPU_REQUEST: "0.5",
63
65
  KUBERNETES_CPU_LIMIT: "2",
@@ -71,18 +73,22 @@ var baseRetry = {
71
73
  };
72
74
 
73
75
  var getYarnInstall = function (context) {
74
- return ["cd ".concat(context.componentConfig.dir), "if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi", "yarn install --frozen-lockfile"];
76
+ var _a;
77
+
78
+ return ["cd ".concat(context.componentConfig.dir), "if [ -f ./.nvmrc ]; then source /root/.nvm/nvm.sh && nvm install <<< .nvmrc; fi", ((_a = context.yarnInfo) === null || _a === void 0 ? void 0 : _a.isClassic) ? "yarn install --frozen-lockfile" : "yarn install --immutable"];
75
79
  };
76
80
 
77
- var getNodeCache = function (policy) {
78
- if (policy === void 0) {
79
- policy = "pull-push";
80
- }
81
+ var getNodeCache = function (context) {
82
+ var _a, _b, _c;
81
83
 
84
+ var componentIsInWorkspace = (_a = context.yarnInfo) === null || _a === void 0 ? void 0 : _a.componentIsInWorkspace;
82
85
  return [{
83
- key: "node-modules",
84
- policy: policy,
85
- paths: [".yarn", "node_modules", "**/node_modules/"]
86
+ // if component is in a shared workspace, use workspace cache. use individual cache else
87
+ key: componentIsInWorkspace ? "node-modules-workspace" : context.componentName + "-node-modules",
88
+ policy: "pull-push",
89
+ paths: __spreadArray([".yarn"], __read(componentIsInWorkspace ? __spreadArray(["node_modules"], __read((_c = (_b = context.yarnInfo) === null || _b === void 0 ? void 0 : _b.workspaces.map(function (w) {
90
+ return (0, path_1.join)(w.location, "node_modules");
91
+ })) !== null && _c !== void 0 ? _c : []), false) : [(0, path_1.join)(context.componentConfig.dir, "node_modules")]), false)
86
92
  }];
87
93
  };
88
94
 
@@ -90,7 +96,7 @@ exports.getNodeCache = getNodeCache;
90
96
 
91
97
  var getNextCache = function (context) {
92
98
  return [{
93
- key: "next-cache",
99
+ key: context.componentName + "-next-cache",
94
100
  policy: "pull-push",
95
101
  paths: [context.componentConfig.dir + "/.next/cache/"]
96
102
  }];
@@ -128,7 +134,7 @@ var createNodeTestJobs = function (context) {
128
134
  name: "๐Ÿ‘ฎ lint",
129
135
  envMode: "none",
130
136
  job: __assign(__assign({}, base), {
131
- cache: (0, exports.getNodeCache)("pull-push"),
137
+ cache: (0, exports.getNodeCache)(context),
132
138
  script: __spreadArray(__spreadArray([], __read(yarnInstall), false), __read((_f = (0, utils_1.ensureArray)((_e = buildConfig.lint) === null || _e === void 0 ? void 0 : _e.command)) !== null && _f !== void 0 ? _f : ["yarn lint"]), false)
133
139
  })
134
140
  } : null;
@@ -136,7 +142,7 @@ var createNodeTestJobs = function (context) {
136
142
  name: "๐Ÿงช test",
137
143
  envMode: "none",
138
144
  job: __assign(__assign({}, base), {
139
- cache: (0, exports.getNodeCache)("pull-push"),
145
+ cache: (0, exports.getNodeCache)(context),
140
146
  script: __spreadArray(__spreadArray([], __read(yarnInstall), false), __read((_h = (0, utils_1.ensureArray)((_g = buildConfig.test) === null || _g === void 0 ? void 0 : _g.command)) !== null && _h !== void 0 ? _h : ["yarn test"]), false)
141
147
  })
142
148
  } : null;
@@ -160,7 +166,7 @@ var createNodeBuildJobs = function (context) {
160
166
  envMode: "jobPerEnv",
161
167
  job: {
162
168
  needs: [],
163
- cache: __spreadArray(__spreadArray([], __read((0, exports.getNodeCache)("pull")), false), __read(getNextCache(context)), false),
169
+ cache: __spreadArray(__spreadArray([], __read((0, exports.getNodeCache)(context)), false), __read(getNextCache(context)), false),
164
170
  variables: __assign(__assign(__assign({}, NODE_RUNNER_BUILD_VARIABLES), context.environment.envVars), (_a = context.componentConfig.build.extraVars) !== null && _a !== void 0 ? _a : {}),
165
171
  retry: baseRetry,
166
172
  interruptible: true,
package/dist/constants.js CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.DOCKER_REGISTRY = exports.PIPELINE_IMAGE_TAG = void 0;
5
- exports.PIPELINE_IMAGE_TAG = "main-a6000978" || "";
5
+ exports.PIPELINE_IMAGE_TAG = "main-57e22cfd" || "";
6
6
  exports.DOCKER_REGISTRY = "git.panter.ch:5001/catladder/catladder" || "";
@@ -1,4 +1,4 @@
1
1
  import { Config } from "../types/config";
2
- import { CommitInfo, Context, Environment } from "../types/context";
2
+ import { CommitInfo, Context, Environment, YarnInfo } from "../types/context";
3
3
  export declare const getEnvironment: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, skipReferences?: boolean) => Environment;
4
- export declare const createContext: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined) => Context;
4
+ export declare const createContext: (config: Config, componentName: string, env: string, commitInfo?: CommitInfo | undefined, yarnInfo?: YarnInfo | undefined) => Context;
@@ -107,13 +107,14 @@ var getEnvironment = function (config, componentName, env, commitInfo, skipRefer
107
107
  PORT: port.toString()
108
108
  };
109
109
  } else {
110
- var KUBE_APP_NAME = envType === "review" && commitInfo ? "".concat(componentName, "-").concat(commitInfo.refSlug) : componentName;
111
110
  var KUBE_NAMESPACE = "".concat(config.customerName, "-").concat(config.appName, "-").concat(env);
112
111
  var RELEASE_NAME = "".concat(config.customerName, "-").concat(config.appName, "-").concat(environmentSlug);
113
- var APP_SLUG = (0, slugify_1["default"])(KUBE_APP_NAME);
114
- var HOST_CANONICAL = "".concat(config.appName, "-").concat(APP_SLUG, ".").concat(env, ".").concat(config.customerName, ".panter.cloud");
112
+ var componentSlug = (0, slugify_1["default"])(componentName);
113
+ var envInUrl = envType === "review" && commitInfo ? "$".concat(commitInfo.refSlug, ".").concat(env) : env;
114
+ var HOST_CANONICAL = "".concat(config.appName, "-").concat(componentSlug, ".").concat(envInUrl, ".").concat(config.customerName, ".panter.cloud");
115
115
  hostname = (_e = mergedConfig === null || mergedConfig === void 0 ? void 0 : mergedConfig.hostname) !== null && _e !== void 0 ? _e : HOST_CANONICAL;
116
116
  var url_1 = "https://".concat(hostname);
117
+ var KUBE_APP_NAME = envType === "review" && commitInfo ? "".concat(componentName, "-").concat(commitInfo.refSlug) : componentName;
117
118
  predefinedVariables = __assign(__assign({}, basePredefinedVariables), {
118
119
  HOST_CANONICAL: HOST_CANONICAL,
119
120
  ROOT_URL: url_1,
@@ -161,7 +162,7 @@ var getEnvironment = function (config, componentName, env, commitInfo, skipRefer
161
162
 
162
163
  exports.getEnvironment = getEnvironment;
163
164
 
164
- var createContext = function (config, componentName, env, commitInfo) {
165
+ var createContext = function (config, componentName, env, commitInfo, yarnInfo) {
165
166
  var _a, _b;
166
167
 
167
168
  if (!/^[a-z0-9-]+$/.test(componentName)) {
@@ -191,7 +192,8 @@ var createContext = function (config, componentName, env, commitInfo) {
191
192
  componentConfig: componentConfig,
192
193
  componentName: componentName,
193
194
  environment: (0, exports.getEnvironment)(config, componentName, env, commitInfo),
194
- commitInfo: commitInfo
195
+ commitInfo: commitInfo,
196
+ yarnInfo: yarnInfo
195
197
  };
196
198
  };
197
199
 
@@ -207,27 +207,58 @@ var createChildPipeline = function (trigger, config) {
207
207
  return __awaiter(void 0, void 0, void 0, function () {
208
208
  var components, jobs, allEnvs, stages, childPipeline;
209
209
  return __generator(this, function (_a) {
210
- components = Object.keys(config.components);
211
- jobs = components.reduce(function (acc, componentName) {
212
- var envs = (0, config_1.getAllEnvsByTrigger)(config, componentName, trigger);
213
- return __assign(__assign({}, acc), (0, createJobs_1.createJobs)(envs, config, componentName, trigger));
214
- }, {});
215
- allEnvs = (0, config_1.getAllEnvsInAllComponents)(config);
216
- stages = baseStages.reduce(function (acc, baseStage) {
217
- return __spreadArray(__spreadArray(__spreadArray([], __read(acc), false), [baseStage], false), __read(allEnvs.map(function (e) {
218
- return "".concat(baseStage, " ").concat(e);
219
- })), false);
220
- }, []);
221
- childPipeline = __assign({
222
- image: (0, runner_1.getRunnerImage)("jobs"),
223
- workflow: {
224
- rules: rules_1.RULES_ALWAYS
225
- },
226
- stages: stages
227
- }, jobs);
228
- return [2
229
- /*return*/
230
- , childPipeline];
210
+ switch (_a.label) {
211
+ case 0:
212
+ components = Object.keys(config.components);
213
+ return [4
214
+ /*yield*/
215
+ , components.reduce(function (acc, componentName) {
216
+ return __awaiter(void 0, void 0, void 0, function () {
217
+ var envs, _a, _b;
218
+
219
+ return __generator(this, function (_c) {
220
+ switch (_c.label) {
221
+ case 0:
222
+ envs = (0, config_1.getAllEnvsByTrigger)(config, componentName, trigger);
223
+ _a = [{}];
224
+ return [4
225
+ /*yield*/
226
+ , acc];
227
+
228
+ case 1:
229
+ _b = [__assign.apply(void 0, _a.concat([_c.sent()]))];
230
+ return [4
231
+ /*yield*/
232
+ , (0, createJobs_1.createJobs)(envs, config, componentName, trigger)];
233
+
234
+ case 2:
235
+ return [2
236
+ /*return*/
237
+ , __assign.apply(void 0, _b.concat([_c.sent()]))];
238
+ }
239
+ });
240
+ });
241
+ }, Promise.resolve({}))];
242
+
243
+ case 1:
244
+ jobs = _a.sent();
245
+ allEnvs = (0, config_1.getAllEnvsInAllComponents)(config);
246
+ stages = baseStages.reduce(function (acc, baseStage) {
247
+ return __spreadArray(__spreadArray(__spreadArray([], __read(acc), false), [baseStage], false), __read(allEnvs.map(function (e) {
248
+ return "".concat(baseStage, " ").concat(e);
249
+ })), false);
250
+ }, []);
251
+ childPipeline = __assign({
252
+ image: (0, runner_1.getRunnerImage)("jobs"),
253
+ workflow: {
254
+ rules: rules_1.RULES_ALWAYS
255
+ },
256
+ stages: stages
257
+ }, jobs);
258
+ return [2
259
+ /*return*/
260
+ , childPipeline];
261
+ }
231
262
  });
232
263
  });
233
264
  };
@@ -1,3 +1,3 @@
1
1
  import { Config, PipelineTrigger } from "../types/config";
2
2
  import { GitlabJobDef } from "../types/gitlab-types";
3
- export declare const createJobs: (envs: string[], config: Config, componentName: string, trigger: PipelineTrigger) => Record<string, GitlabJobDef>;
3
+ export declare const createJobs: (envs: string[], config: Config, componentName: string, trigger: PipelineTrigger) => Promise<Record<string, GitlabJobDef>>;
@@ -14,6 +14,147 @@ var __assign = this && this.__assign || function () {
14
14
  return __assign.apply(this, arguments);
15
15
  };
16
16
 
17
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) {
19
+ return value instanceof P ? value : new P(function (resolve) {
20
+ resolve(value);
21
+ });
22
+ }
23
+
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) {
26
+ try {
27
+ step(generator.next(value));
28
+ } catch (e) {
29
+ reject(e);
30
+ }
31
+ }
32
+
33
+ function rejected(value) {
34
+ try {
35
+ step(generator["throw"](value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ }
40
+
41
+ function step(result) {
42
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
43
+ }
44
+
45
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
46
+ });
47
+ };
48
+
49
+ var __generator = this && this.__generator || function (thisArg, body) {
50
+ var _ = {
51
+ label: 0,
52
+ sent: function () {
53
+ if (t[0] & 1) throw t[1];
54
+ return t[1];
55
+ },
56
+ trys: [],
57
+ ops: []
58
+ },
59
+ f,
60
+ y,
61
+ t,
62
+ g;
63
+ return g = {
64
+ next: verb(0),
65
+ "throw": verb(1),
66
+ "return": verb(2)
67
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
68
+ return this;
69
+ }), g;
70
+
71
+ function verb(n) {
72
+ return function (v) {
73
+ return step([n, v]);
74
+ };
75
+ }
76
+
77
+ function step(op) {
78
+ if (f) throw new TypeError("Generator is already executing.");
79
+
80
+ while (_) try {
81
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
82
+ if (y = 0, t) op = [op[0] & 2, t.value];
83
+
84
+ switch (op[0]) {
85
+ case 0:
86
+ case 1:
87
+ t = op;
88
+ break;
89
+
90
+ case 4:
91
+ _.label++;
92
+ return {
93
+ value: op[1],
94
+ done: false
95
+ };
96
+
97
+ case 5:
98
+ _.label++;
99
+ y = op[1];
100
+ op = [0];
101
+ continue;
102
+
103
+ case 7:
104
+ op = _.ops.pop();
105
+
106
+ _.trys.pop();
107
+
108
+ continue;
109
+
110
+ default:
111
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
112
+ _ = 0;
113
+ continue;
114
+ }
115
+
116
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
117
+ _.label = op[1];
118
+ break;
119
+ }
120
+
121
+ if (op[0] === 6 && _.label < t[1]) {
122
+ _.label = t[1];
123
+ t = op;
124
+ break;
125
+ }
126
+
127
+ if (t && _.label < t[2]) {
128
+ _.label = t[2];
129
+
130
+ _.ops.push(op);
131
+
132
+ break;
133
+ }
134
+
135
+ if (t[2]) _.ops.pop();
136
+
137
+ _.trys.pop();
138
+
139
+ continue;
140
+ }
141
+
142
+ op = body.call(thisArg, _);
143
+ } catch (e) {
144
+ op = [6, e];
145
+ y = 0;
146
+ } finally {
147
+ f = t = 0;
148
+ }
149
+
150
+ if (op[0] & 5) throw op[1];
151
+ return {
152
+ value: op[0] ? op[1] : void 0,
153
+ done: true
154
+ };
155
+ }
156
+ };
157
+
17
158
  var __read = this && this.__read || function (o, n) {
18
159
  var m = typeof Symbol === "function" && o[Symbol.iterator];
19
160
  if (!m) return o;
@@ -62,6 +203,8 @@ var deploy_1 = require("../deploy");
62
203
 
63
204
  var utils_1 = require("../utils");
64
205
 
206
+ var yarnInfo_1 = require("./yarnInfo");
207
+
65
208
  var createRawJobs = function (context) {
66
209
  if (context.componentConfig.deploy === false) {
67
210
  return [];
@@ -150,22 +293,39 @@ var addStageNeeds = function (jobs) {
150
293
  };
151
294
 
152
295
  var createJobs = function (envs, config, componentName, trigger) {
153
- var _a, _b;
154
-
155
- var commitInfo = {
156
- refName: (_a = process.env.CI_COMMIT_REF_NAME) !== null && _a !== void 0 ? _a : "unknown",
157
- refSlug: (_b = process.env.CI_COMMIT_REF_SLUG) !== null && _b !== void 0 ? _b : "unknown",
158
- trigger: trigger
159
- };
160
- return envs.reduce(function (acc, env) {
161
- var context = (0, context_1.createContext)(config, componentName, env, commitInfo);
162
- var jobs = addStageNeeds(createRawJobs(context));
163
- return __assign(__assign({}, acc), jobs.reduce(function (acc, job) {
164
- var _a;
165
-
166
- return __assign(__assign({}, acc), (_a = {}, _a[getFullJobName(job.name, componentName, job.envMode !== "none" ? env : undefined)] = replaceReferences(job, componentName, env, jobs), _a));
167
- }, {}));
168
- }, {});
296
+ return __awaiter(void 0, void 0, void 0, function () {
297
+ var commitInfo, yarnInfo;
298
+
299
+ var _a, _b;
300
+
301
+ return __generator(this, function (_c) {
302
+ switch (_c.label) {
303
+ case 0:
304
+ commitInfo = {
305
+ refName: (_a = process.env.CI_COMMIT_REF_NAME) !== null && _a !== void 0 ? _a : "unknown",
306
+ refSlug: (_b = process.env.CI_COMMIT_REF_SLUG) !== null && _b !== void 0 ? _b : "unknown",
307
+ trigger: trigger
308
+ };
309
+ return [4
310
+ /*yield*/
311
+ , (0, yarnInfo_1.getYarnInfo)(config, componentName)];
312
+
313
+ case 1:
314
+ yarnInfo = _c.sent();
315
+ return [2
316
+ /*return*/
317
+ , envs.reduce(function (acc, env) {
318
+ var context = (0, context_1.createContext)(config, componentName, env, commitInfo, yarnInfo);
319
+ var jobs = addStageNeeds(createRawJobs(context));
320
+ return __assign(__assign({}, acc), jobs.reduce(function (acc, job) {
321
+ var _a;
322
+
323
+ return __assign(__assign({}, acc), (_a = {}, _a[getFullJobName(job.name, componentName, job.envMode !== "none" ? env : undefined)] = replaceReferences(job, componentName, env, jobs), _a));
324
+ }, {}));
325
+ }, {})];
326
+ }
327
+ });
328
+ });
169
329
  };
170
330
 
171
331
  exports.createJobs = createJobs;
@@ -0,0 +1,2 @@
1
+ import { Config, YarnInfo } from "../types";
2
+ export declare const getYarnInfo: (config: Config, componentName: string) => Promise<YarnInfo>;