@catladder/pipeline 4.6.4 → 4.7.1

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 (44) hide show
  1. package/dist/constants.js +1 -1
  2. package/dist/context/getEnvironmentVariables.js +6 -5
  3. package/dist/deploy/cloudRun/index.js +14 -2
  4. package/dist/deploy/cloudRun/utils/database.d.ts +6 -5
  5. package/dist/deploy/cloudRun/utils/database.js +22 -15
  6. package/dist/deploy/index.d.ts +7 -2
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +1 -0
  9. package/dist/pipeline/createJobsForComponent.js +5 -4
  10. package/dist/tsconfig.tsbuildinfo +1 -1
  11. package/dist/types/config.d.ts +8 -0
  12. package/dist/variables/VariableValueContainingReferences.d.ts +6 -0
  13. package/dist/variables/VariableValueContainingReferences.js +21 -0
  14. package/dist/variables/resolveAllReferences.d.ts +1 -2
  15. package/dist/variables/resolveAllReferences.js +7 -8
  16. package/dist/variables/resolveAllReferencesOnce.d.ts +1 -4
  17. package/dist/variables/resolveAllReferencesOnce.js +3 -3
  18. package/dist/verify/createVerifyJobs.d.ts +4 -0
  19. package/dist/verify/createVerifyJobs.js +229 -0
  20. package/dist/verify/index.d.ts +2 -0
  21. package/dist/verify/index.js +26 -0
  22. package/dist/verify/types.d.ts +16 -0
  23. package/dist/verify/types.js +5 -0
  24. package/examples/__snapshots__/cloud-run-verify.test.ts.snap +3061 -0
  25. package/examples/__snapshots__/cloud-run-with-sql-multiple-dbs.test.ts.snap +35 -35
  26. package/examples/__snapshots__/cloud-run-with-sql-reuse-db.test.ts.snap +64 -64
  27. package/examples/cloud-run-verify.test.ts +12 -0
  28. package/examples/cloud-run-verify.ts +50 -0
  29. package/examples/cloud-run-with-sql-reuse-db.ts +4 -0
  30. package/package.json +1 -1
  31. package/src/context/getEnvironmentVariables.ts +19 -10
  32. package/src/deploy/cloudRun/index.ts +25 -1
  33. package/src/deploy/cloudRun/utils/database.ts +54 -22
  34. package/src/deploy/index.ts +7 -2
  35. package/src/index.ts +1 -0
  36. package/src/pipeline/createJobsForComponent.ts +4 -2
  37. package/src/types/config.ts +9 -0
  38. package/src/variables/VariableValueContainingReferences.ts +11 -0
  39. package/src/variables/__tests__/resolveAllReferences.test.ts +49 -0
  40. package/src/variables/resolveAllReferences.ts +18 -14
  41. package/src/variables/resolveAllReferencesOnce.ts +17 -12
  42. package/src/verify/createVerifyJobs.ts +81 -0
  43. package/src/verify/index.ts +2 -0
  44. package/src/verify/types.ts +18 -0
@@ -7,6 +7,7 @@ import type { PipelineType, WorkspaceBuildConfig } from "..";
7
7
  import type { AgentConfig } from "./agent";
8
8
  import type { Hooks } from "./hooks";
9
9
  import type { ReleaseConfig } from "./release";
10
+ import type { VerifyConfig } from "../verify/types";
10
11
  export declare const ALL_PIPELINE_TRIGGERS: readonly ["mainBranch", "mr", "taggedRelease"];
11
12
  export type PipelineTrigger = (typeof ALL_PIPELINE_TRIGGERS)[number];
12
13
  /**
@@ -71,6 +72,13 @@ export type DefaultEnvConfig = {
71
72
  * environment variables
72
73
  */
73
74
  vars?: EnvVars;
75
+ /**
76
+ * post-deploy verification: runs a job in the `verify` stage after the deploy,
77
+ * e.g. an e2e test suite against the freshly deployed environment.
78
+ *
79
+ * Runs in all deployed envs by default, disable per env with `verify: false`
80
+ */
81
+ verify?: VerifyConfig | false;
74
82
  };
75
83
  export type DevLocalEnvConfig = {
76
84
  vars?: EnvVars;
@@ -16,6 +16,12 @@ type MaybeArray<T> = T | T[];
16
16
  export declare class VariableValueContainingReferences {
17
17
  parts: VariableValuePart[];
18
18
  constructor(parts: MaybeArray<VariableValuePart | VariableValueContainingReferences>);
19
+ /**
20
+ * concats values to this one and returns a new VariableValueContainingReferences.
21
+ * mirrors String.prototype.concat / BashExpression.concat so a VariableValue
22
+ * can be extended regardless of its concrete type
23
+ */
24
+ concat(...values: Array<VariableValuePart | VariableValueContainingReferences>): VariableValueContainingReferences;
19
25
  toString(options?: EscapeOptions): string;
20
26
  }
21
27
  export declare const createVariableValueContainingReferencesFromString: (value: string, options: {
@@ -22,6 +22,15 @@ var __read = this && this.__read || function (o, n) {
22
22
  }
23
23
  return ar;
24
24
  };
25
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
25
34
  Object.defineProperty(exports, "__esModule", {
26
35
  value: true
27
36
  });
@@ -55,6 +64,18 @@ var VariableValueContainingReferences = /** @class */function () {
55
64
  return part instanceof VariableValueContainingReferences ? part.parts : part === "" ? [] : [part];
56
65
  });
57
66
  }
67
+ /**
68
+ * concats values to this one and returns a new VariableValueContainingReferences.
69
+ * mirrors String.prototype.concat / BashExpression.concat so a VariableValue
70
+ * can be extended regardless of its concrete type
71
+ */
72
+ VariableValueContainingReferences.prototype.concat = function () {
73
+ var values = [];
74
+ for (var _i = 0; _i < arguments.length; _i++) {
75
+ values[_i] = arguments[_i];
76
+ }
77
+ return new VariableValueContainingReferences(__spreadArray(__spreadArray([], __read(this.parts), false), __read(values), false));
78
+ };
58
79
  VariableValueContainingReferences.prototype.toString = function (options) {
59
80
  if (options === void 0) {
60
81
  options = {
@@ -1,3 +1,2 @@
1
1
  import type { VariableValue } from "./VariableValue";
2
- import type { VariableValueContainingReferences } from "./VariableValueContainingReferences";
3
- export declare const resolveAllReferences: (values: Record<string, VariableValueContainingReferences>, getEnvVars: (componentName: string) => Promise<Record<string, VariableValue | null | undefined>>) => Promise<Record<string, VariableValueContainingReferences>>;
2
+ export declare const resolveAllReferences: <T extends Record<string, VariableValue | null | undefined>>(values: T, getEnvVars: (componentName: string) => Promise<Record<string, VariableValue | null | undefined>>) => Promise<T>;
@@ -143,6 +143,11 @@ Object.defineProperty(exports, "__esModule", {
143
143
  exports.resolveAllReferences = void 0;
144
144
  var VariableValueContainingReferences_1 = require("./VariableValueContainingReferences");
145
145
  var resolveAllReferencesOnce_1 = require("./resolveAllReferencesOnce");
146
+ var hasUnresolvedReferences = function (value) {
147
+ return value instanceof VariableValueContainingReferences_1.VariableValueContainingReferences && value.parts.some(function (part) {
148
+ return part instanceof VariableValueContainingReferences_1.VariableReference;
149
+ });
150
+ };
146
151
  var resolveAllReferences = function (values, getEnvVars) {
147
152
  return __awaiter(void 0, void 0, void 0, function () {
148
153
  var result, i, replaced, unresolved;
@@ -153,11 +158,7 @@ var resolveAllReferences = function (values, getEnvVars) {
153
158
  i = 0;
154
159
  _a.label = 1;
155
160
  case 1:
156
- if (!Object.values(result).some(function (value) {
157
- return value.parts.some(function (part) {
158
- return part instanceof VariableValueContainingReferences_1.VariableReference;
159
- });
160
- })) return [3 /*break*/, 3];
161
+ if (!Object.values(result).some(hasUnresolvedReferences)) return [3 /*break*/, 3];
161
162
  return [4 /*yield*/, (0, resolveAllReferencesOnce_1.resolveAllReferencesOnce)(result, getEnvVars)];
162
163
  case 2:
163
164
  replaced = _a.sent();
@@ -168,9 +169,7 @@ var resolveAllReferences = function (values, getEnvVars) {
168
169
  var _b = __read(_a, 2),
169
170
  key = _b[0],
170
171
  value = _b[1];
171
- return value.parts.some(function (part) {
172
- return part instanceof VariableValueContainingReferences_1.VariableReference;
173
- });
172
+ return hasUnresolvedReferences(value);
174
173
  });
175
174
  throw new Error("Infinite loop detected in these variables: " + unresolved.map(function (_a) {
176
175
  var _b = __read(_a, 2),
@@ -1,5 +1,2 @@
1
1
  import type { VariableValue } from "./VariableValue";
2
- import type { VariableValueContainingReferences } from "./VariableValueContainingReferences";
3
- export declare const resolveAllReferencesOnce: (values: Record<string, VariableValueContainingReferences>, getEnvVars: (componentName: string) => Promise<Record<string, VariableValue | undefined | null>>) => Promise<{
4
- [k: string]: VariableValueContainingReferences;
5
- }>;
2
+ export declare const resolveAllReferencesOnce: <T extends Record<string, VariableValue | null | undefined>>(values: T, getEnvVars: (componentName: string) => Promise<Record<string, VariableValue | undefined | null>>) => Promise<T>;
@@ -150,9 +150,9 @@ var resolveAllReferencesOnce = function (values, getEnvVars) {
150
150
  switch (_c.label) {
151
151
  case 0:
152
152
  allReferences = Object.values(values).flatMap(function (value) {
153
- return value === null || value === void 0 ? void 0 : value.parts.filter(function (part) {
153
+ return value instanceof VariableValueContainingReferences_1.VariableValueContainingReferences ? value.parts.filter(function (part) {
154
154
  return part instanceof VariableValueContainingReferences_1.VariableReference;
155
- });
155
+ }) : [];
156
156
  });
157
157
  allComponentsUnique = Array.from(new Set(allReferences.map(function (reference) {
158
158
  return reference.componentName;
@@ -178,7 +178,7 @@ var resolveAllReferencesOnce = function (values, getEnvVars) {
178
178
  var _b = __read(_a, 2),
179
179
  key = _b[0],
180
180
  value = _b[1];
181
- return [key, value !== null && value !== undefined ? (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, function (_a) {
181
+ return [key, value instanceof VariableValueContainingReferences_1.VariableValueContainingReferences ? (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, function (_a) {
182
182
  var componentName = _a.componentName,
183
183
  variableName = _a.variableName;
184
184
  return allEnvVarsInComponents[componentName][variableName];
@@ -0,0 +1,4 @@
1
+ import type { ComponentContext } from "../types/context";
2
+ import type { CatladderJob } from "../types/jobs";
3
+ export declare const VERIFY_JOB_NAME = "\uD83D\uDD0D verify";
4
+ export declare const createVerifyJobs: (context: ComponentContext) => Promise<CatladderJob[]>;
@@ -0,0 +1,229 @@
1
+ "use strict";
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
+ };
13
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) {
15
+ return value instanceof P ? value : new P(function (resolve) {
16
+ resolve(value);
17
+ });
18
+ }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ }
27
+ function rejected(value) {
28
+ try {
29
+ step(generator["throw"](value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ }
34
+ function step(result) {
35
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
36
+ }
37
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
38
+ });
39
+ };
40
+ var __generator = this && this.__generator || function (thisArg, body) {
41
+ var _ = {
42
+ label: 0,
43
+ sent: function () {
44
+ if (t[0] & 1) throw t[1];
45
+ return t[1];
46
+ },
47
+ trys: [],
48
+ ops: []
49
+ },
50
+ f,
51
+ y,
52
+ t,
53
+ g;
54
+ return g = {
55
+ next: verb(0),
56
+ "throw": verb(1),
57
+ "return": verb(2)
58
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
59
+ return this;
60
+ }), g;
61
+ function verb(n) {
62
+ return function (v) {
63
+ return step([n, v]);
64
+ };
65
+ }
66
+ function step(op) {
67
+ if (f) throw new TypeError("Generator is already executing.");
68
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
69
+ 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;
70
+ if (y = 0, t) op = [op[0] & 2, t.value];
71
+ switch (op[0]) {
72
+ case 0:
73
+ case 1:
74
+ t = op;
75
+ break;
76
+ case 4:
77
+ _.label++;
78
+ return {
79
+ value: op[1],
80
+ done: false
81
+ };
82
+ case 5:
83
+ _.label++;
84
+ y = op[1];
85
+ op = [0];
86
+ continue;
87
+ case 7:
88
+ op = _.ops.pop();
89
+ _.trys.pop();
90
+ continue;
91
+ default:
92
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
93
+ _ = 0;
94
+ continue;
95
+ }
96
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
97
+ _.label = op[1];
98
+ break;
99
+ }
100
+ if (op[0] === 6 && _.label < t[1]) {
101
+ _.label = t[1];
102
+ t = op;
103
+ break;
104
+ }
105
+ if (t && _.label < t[2]) {
106
+ _.label = t[2];
107
+ _.ops.push(op);
108
+ break;
109
+ }
110
+ if (t[2]) _.ops.pop();
111
+ _.trys.pop();
112
+ continue;
113
+ }
114
+ op = body.call(thisArg, _);
115
+ } catch (e) {
116
+ op = [6, e];
117
+ y = 0;
118
+ } finally {
119
+ f = t = 0;
120
+ }
121
+ if (op[0] & 5) throw op[1];
122
+ return {
123
+ value: op[0] ? op[1] : void 0,
124
+ done: true
125
+ };
126
+ }
127
+ };
128
+ var __read = this && this.__read || function (o, n) {
129
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
130
+ if (!m) return o;
131
+ var i = m.call(o),
132
+ r,
133
+ ar = [],
134
+ e;
135
+ try {
136
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
137
+ } catch (error) {
138
+ e = {
139
+ error: error
140
+ };
141
+ } finally {
142
+ try {
143
+ if (r && !r.done && (m = i["return"])) m.call(i);
144
+ } finally {
145
+ if (e) throw e.error;
146
+ }
147
+ }
148
+ return ar;
149
+ };
150
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
151
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
152
+ if (ar || !(i in from)) {
153
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
154
+ ar[i] = from[i];
155
+ }
156
+ }
157
+ return to.concat(ar || Array.prototype.slice.call(from));
158
+ };
159
+ Object.defineProperty(exports, "__esModule", {
160
+ value: true
161
+ });
162
+ exports.createVerifyJobs = exports.VERIFY_JOB_NAME = void 0;
163
+ var createArtifactsConfig_1 = require("../build/base/createArtifactsConfig");
164
+ var createJobCache_1 = require("../build/cache/createJobCache");
165
+ var cache_1 = require("../build/node/cache");
166
+ var constants_1 = require("../build/node/constants");
167
+ var yarn_1 = require("../build/node/yarn");
168
+ var deploy_1 = require("../deploy");
169
+ var deploy_2 = require("../deploy/base/deploy");
170
+ var runner_1 = require("../runner");
171
+ var utils_1 = require("../utils");
172
+ exports.VERIFY_JOB_NAME = "🔍 verify";
173
+ var createVerifyJobs = function (context) {
174
+ return __awaiter(void 0, void 0, void 0, function () {
175
+ var verifyConfig, deployConfig, isNodeBuild, _a, yarnInstall, nodeCache, _b, setupScript;
176
+ var _c, _d, _e, _f, _g, _h, _j;
177
+ return __generator(this, function (_k) {
178
+ switch (_k.label) {
179
+ case 0:
180
+ verifyConfig = context.componentConfig.verify;
181
+ if (!verifyConfig) {
182
+ return [2 /*return*/, []];
183
+ }
184
+ deployConfig = (_c = context.deploy) === null || _c === void 0 ? void 0 : _c.config;
185
+ if (!deployConfig) {
186
+ // nothing is deployed, so there is nothing to verify
187
+ return [2 /*return*/, []];
188
+ }
189
+ isNodeBuild = context.build.type !== "disabled" && context.build.buildType === "node";
190
+ if (!isNodeBuild) return [3 /*break*/, 2];
191
+ return [4 /*yield*/, Promise.all([(0, yarn_1.getYarnInstall)(context), (0, cache_1.getNodeCache)(context, "pull")])];
192
+ case 1:
193
+ _b = _k.sent();
194
+ return [3 /*break*/, 3];
195
+ case 2:
196
+ _b = [null, null];
197
+ _k.label = 3;
198
+ case 3:
199
+ _a = __read.apply(void 0, [_b, 2]), yarnInstall = _a[0], nodeCache = _a[1];
200
+ setupScript = (_f = (_e = (_d = deploy_1.DEPLOY_TYPES[deployConfig.type]).verifyJobSetupScript) === null || _e === void 0 ? void 0 : _e.call(_d, context)) !== null && _f !== void 0 ? _f : [];
201
+ return [2 /*return*/, [__assign({
202
+ name: exports.VERIFY_JOB_NAME,
203
+ stage: "verify",
204
+ envMode: "stagePerEnv",
205
+ // wait for this component's own deploy
206
+ needsStages: [{
207
+ stage: "deploy",
208
+ artifacts: false
209
+ }],
210
+ // ...and for the deploys of the components listed in waitFor
211
+ needs: ((_g = verifyConfig.waitFor) !== null && _g !== void 0 ? _g : []).map(function (componentName) {
212
+ return {
213
+ job: deploy_2.DEPLOY_JOB_NAME,
214
+ componentName: componentName,
215
+ artifacts: false
216
+ };
217
+ }),
218
+ image: (_h = verifyConfig.jobImage) !== null && _h !== void 0 ? _h : (0, runner_1.getRunnerImage)("jobs-testing-chrome"),
219
+ cache: nodeCache ? (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, nodeCache) : undefined,
220
+ variables: __assign({}, context.environment.envVars),
221
+ runnerVariables: __assign(__assign({}, constants_1.NODE_RUNNER_BUILD_VARIABLES), (_j = verifyConfig.runnerVariables) !== null && _j !== void 0 ? _j : {}),
222
+ script: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(setupScript), false), __read(yarnInstall ? (0, yarn_1.ensureNodeVersion)(context) : []), false), ["cd ".concat(context.build.dir)], false), __read(yarnInstall !== null && yarnInstall !== void 0 ? yarnInstall : []), false), __read((0, utils_1.ensureArray)(verifyConfig.command)), false),
223
+ allow_failure: verifyConfig.allowFailure
224
+ }, (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, verifyConfig.artifactsReports, verifyConfig.artifacts))]];
225
+ }
226
+ });
227
+ });
228
+ };
229
+ exports.createVerifyJobs = createVerifyJobs;
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export * from "./createVerifyJobs";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = this && this.__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./types"), exports);
26
+ __exportStar(require("./createVerifyJobs"), exports);
@@ -0,0 +1,16 @@
1
+ import type { TestJobCustom } from "../build/types";
2
+ /**
3
+ * post-deploy verification job configuration
4
+ */
5
+ export type VerifyConfig = TestJobCustom & {
6
+ /**
7
+ * command(s) to run against the deployed environment (e.g. `yarn e2e`).
8
+ * Runs in the component's directory.
9
+ */
10
+ command: string | string[];
11
+ /**
12
+ * names of other components whose deploy must finish before this verify job runs
13
+ * (in addition to this component's own deploy, which is always awaited)
14
+ */
15
+ waitFor?: string[];
16
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });