@catladder/pipeline 1.165.1 → 1.166.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 (69) hide show
  1. package/dist/build/base/createAppBuildJob.d.ts +3 -1
  2. package/dist/build/base/createAppBuildJob.js +6 -4
  3. package/dist/build/base/createBuildJobDefinition.d.ts +7 -0
  4. package/dist/build/base/createBuildJobDefinition.js +58 -0
  5. package/dist/build/cache/createJobCache.d.ts +6 -0
  6. package/dist/build/cache/createJobCache.js +109 -0
  7. package/dist/build/cache/getAllCacheConfigsFromConfig.d.ts +3 -0
  8. package/dist/build/cache/getAllCacheConfigsFromConfig.js +66 -0
  9. package/dist/build/cache/transformLegacyJobCache.d.ts +3 -0
  10. package/dist/build/cache/transformLegacyJobCache.js +29 -0
  11. package/dist/build/custom/buildJob.js +2 -45
  12. package/dist/build/custom/testJob.d.ts +1 -1
  13. package/dist/build/custom/testJob.js +12 -11
  14. package/dist/build/docker.d.ts +4 -3
  15. package/dist/build/docker.js +5 -2
  16. package/dist/build/node/buildJob.js +5 -17
  17. package/dist/build/node/cache.d.ts +6 -6
  18. package/dist/build/node/cache.js +8 -9
  19. package/dist/build/node/meteor.js +2 -3
  20. package/dist/build/node/testJob.js +6 -5
  21. package/dist/build/node/yarn.js +1 -2
  22. package/dist/build/rails/test.js +3 -3
  23. package/dist/build/sbom.js +1 -1
  24. package/dist/build/types.d.ts +43 -4
  25. package/dist/bundles/catladder-gitlab/index.js +2 -2
  26. package/dist/constants.js +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/dist/types/gitlab-types.d.ts +2 -2
  29. package/dist/types/index.d.ts +1 -0
  30. package/dist/types/index.js +1 -0
  31. package/dist/types/jobDefinition.d.ts +5 -0
  32. package/dist/types/jobDefinition.js +5 -0
  33. package/dist/types/jobs.d.ts +3 -2
  34. package/dist/utils/index.d.ts +2 -1
  35. package/dist/utils/index.js +7 -2
  36. package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +817 -1717
  37. package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +0 -4
  38. package/examples/__snapshots__/custom-build-job.test.ts.snap +0 -4
  39. package/examples/__snapshots__/custom-sbom-java.test.ts.snap +0 -4
  40. package/examples/__snapshots__/native-app.test.ts.snap +24 -20
  41. package/examples/__snapshots__/workspace-api-www-custom-cache.test.ts.snap +2374 -0
  42. package/examples/__snapshots__/workspace-api-www.test.ts.snap +2354 -0
  43. package/examples/cloud-run-with-sql.ts +1 -23
  44. package/examples/workspace-api-www-custom-cache.test.ts +11 -0
  45. package/examples/workspace-api-www-custom-cache.ts +51 -0
  46. package/examples/workspace-api-www.test.ts +11 -0
  47. package/examples/workspace-api-www.ts +45 -0
  48. package/package.json +1 -1
  49. package/src/build/base/createAppBuildJob.ts +6 -4
  50. package/src/build/base/createBuildJobDefinition.ts +38 -0
  51. package/src/build/cache/createJobCache.ts +85 -0
  52. package/src/build/cache/getAllCacheConfigsFromConfig.ts +33 -0
  53. package/src/build/cache/transformLegacyJobCache.ts +14 -0
  54. package/src/build/custom/buildJob.ts +2 -14
  55. package/src/build/custom/testJob.ts +7 -6
  56. package/src/build/docker.ts +5 -3
  57. package/src/build/node/buildJob.ts +6 -29
  58. package/src/build/node/cache.ts +20 -21
  59. package/src/build/node/meteor.ts +7 -8
  60. package/src/build/node/testJob.ts +7 -6
  61. package/src/build/node/yarn.ts +1 -1
  62. package/src/build/rails/test.ts +4 -4
  63. package/src/build/sbom.ts +2 -2
  64. package/src/build/types.ts +54 -4
  65. package/src/types/gitlab-types.ts +2 -2
  66. package/src/types/index.ts +1 -0
  67. package/src/types/jobDefinition.ts +9 -0
  68. package/src/types/jobs.ts +5 -8
  69. package/src/utils/index.ts +4 -1
@@ -1,9 +1,11 @@
1
1
  import type { BuildContextStandalone, ComponentContext, WorkspaceContext } from "../..";
2
+ import type { JobDefintion } from "../../types/jobDefinition";
2
3
  import type { CatladderJob } from "../../types/jobs";
3
- export type AppBuildJobDefinition = Partial<Omit<CatladderJob, "artifacts">>;
4
+ export type AppBuildJobDefinition = JobDefintion;
4
5
  export declare const createAppBuildJob: (context: ComponentContext<BuildContextStandalone> | WorkspaceContext, {
5
6
  script,
6
7
  variables,
7
8
  runnerVariables,
9
+ cache,
8
10
  ...def
9
11
  }: AppBuildJobDefinition) => CatladderJob;
@@ -57,30 +57,32 @@ var lodash_1 = require("lodash");
57
57
  var __1 = require("../..");
58
58
  var utils_1 = require("../../utils");
59
59
  var createBuildJobArtifact_1 = require("../artifacts/createBuildJobArtifact");
60
+ var createJobCache_1 = require("../cache/createJobCache");
60
61
  var yarn_1 = require("../node/yarn");
61
62
  var constants_1 = require("./constants");
62
63
  var writeBuildInfo_1 = require("./writeBuildInfo");
63
64
  var writeDotEnv_1 = require("./writeDotEnv");
64
65
  var createAppBuildJob = function (context, _a) {
65
- var _b, _c, _d;
66
+ var _b, _c;
66
67
  var script = _a.script,
67
68
  variables = _a.variables,
68
69
  runnerVariables = _a.runnerVariables,
69
- def = __rest(_a, ["script", "variables", "runnerVariables"]);
70
+ cache = _a.cache,
71
+ def = __rest(_a, ["script", "variables", "runnerVariables", "cache"]);
70
72
  return (0, lodash_1.merge)({
71
73
  name: constants_1.APP_BUILD_JOB_NAME,
72
74
  envMode: "jobPerEnv",
73
75
  stage: "build",
74
76
  image: (0, __1.getRunnerImage)("jobs-default"),
75
77
  needs: [],
76
- cache: [],
78
+ cache: cache ? (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, cache) : undefined,
77
79
  variables: __assign(__assign({}, variables !== null && variables !== void 0 ? variables : {}), context.type === "component" ? __assign(__assign(__assign({}, context.environment.envVars), context.environment.jobOnlyVars.build.envVars), (_b = context.build.config.extraVars) !== null && _b !== void 0 ? _b : {}) : {}),
78
80
  runnerVariables: __assign(__assign(__assign({}, constants_1.RUNNER_BUILD_RESOURCE_VARIABLES), runnerVariables !== null && runnerVariables !== void 0 ? runnerVariables : {}), (_c = context.build.config.runnerVariables) !== null && _c !== void 0 ? _c : {}),
79
81
  script: __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(context.type === "component" ? (0, writeDotEnv_1.componentContextNeedsBuildTimeDotEnv)(context) ? (0, writeDotEnv_1.writeDotEnv)(context) : [] : context.type === "workspace" ? context.components.filter(function (c) {
80
82
  return (0, writeDotEnv_1.componentContextNeedsBuildTimeDotEnv)(c);
81
83
  }).flatMap(function (c) {
82
84
  return (0, writeDotEnv_1.writeDotEnv)(c);
83
- }) : []), false), __read(context.type === "component" ? (0, writeBuildInfo_1.writeBuildInfo)(context) : []), false), __read((0, yarn_1.ensureNodeVersion)(context)), false), ["cd ".concat(context.build.dir)], false), __read((_d = (0, utils_1.ensureArray)(script)) !== null && _d !== void 0 ? _d : []), false),
85
+ }) : []), false), __read(context.type === "component" ? (0, writeBuildInfo_1.writeBuildInfo)(context) : []), false), __read((0, yarn_1.ensureNodeVersion)(context)), false), ["cd ".concat(context.build.dir)], false), __read((0, utils_1.ensureArray)(script)), false),
84
86
  artifacts: (0, createBuildJobArtifact_1.createBuildJobArtifacts)(context)
85
87
  }, def);
86
88
  };
@@ -0,0 +1,7 @@
1
+ import type { BuildConfigStandalone, WorkspaceBuildConfig } from "..";
2
+ import type { Context } from "../../types";
3
+ import type { JobDefintion } from "../../types/jobDefinition";
4
+ export declare const createBuildJobDefinition: (context: Context, buildConfig: BuildConfigStandalone | WorkspaceBuildConfig, customize?: Pick<JobDefintion, "cache"> & {
5
+ prescript?: string[];
6
+ postscript?: string[];
7
+ }) => JobDefintion | undefined;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var __read = this && this.__read || function (o, n) {
4
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
5
+ if (!m) return o;
6
+ var i = m.call(o),
7
+ r,
8
+ ar = [],
9
+ e;
10
+ try {
11
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
12
+ } catch (error) {
13
+ e = {
14
+ error: error
15
+ };
16
+ } finally {
17
+ try {
18
+ if (r && !r.done && (m = i["return"])) m.call(i);
19
+ } finally {
20
+ if (e) throw e.error;
21
+ }
22
+ }
23
+ return ar;
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
+ };
34
+ Object.defineProperty(exports, "__esModule", {
35
+ value: true
36
+ });
37
+ exports.createBuildJobDefinition = void 0;
38
+ var runner_1 = require("../../runner");
39
+ var utils_1 = require("../../utils");
40
+ var getAllCacheConfigsFromConfig_1 = require("../cache/getAllCacheConfigsFromConfig");
41
+ var constants_1 = require("../node/constants");
42
+ var createBuildJobDefinition = function (context, buildConfig, customize) {
43
+ var _a, _b, _c, _d;
44
+ if (customize === void 0) {
45
+ customize = {};
46
+ }
47
+ if (buildConfig.buildCommand === null) return undefined;
48
+ var defaultImage = (0, runner_1.getRunnerImage)("jobs-default");
49
+ return {
50
+ image: (_a = buildConfig.jobImage) !== null && _a !== void 0 ? _a : defaultImage,
51
+ runnerVariables: constants_1.NODE_RUNNER_BUILD_VARIABLES,
52
+ cache: __spreadArray(__spreadArray([], __read((_b = customize.cache) !== null && _b !== void 0 ? _b : []), false), __read((0, getAllCacheConfigsFromConfig_1.getAllCacheConfigsFromConfig)(context, buildConfig)), false),
53
+ services: "jobServices" in buildConfig ? buildConfig.jobServices : undefined,
54
+ script: __spreadArray(__spreadArray(__spreadArray([], __read((_c = customize.prescript) !== null && _c !== void 0 ? _c : []), false), __read((0, utils_1.ensureArray)(buildConfig.buildCommand)), false), __read((_d = customize.postscript) !== null && _d !== void 0 ? _d : []), false),
55
+ jobTags: buildConfig.jobTags
56
+ };
57
+ };
58
+ exports.createBuildJobDefinition = createBuildJobDefinition;
@@ -0,0 +1,6 @@
1
+ import type { BuildConfigStandalone, CacheConfig, WorkspaceBuildConfig } from "..";
2
+ import type { Context } from "../../types";
3
+ import type { CatladderJobCache } from "../../types/jobs";
4
+ export declare const createJobCacheFromCacheConfigs: (context: Context, caches: CacheConfig[]) => CatladderJobCache[] | undefined;
5
+ /** shortcut, used in some build types */
6
+ export declare const createJobCacheFromConfig: (context: Context, buildConfig: BuildConfigStandalone | WorkspaceBuildConfig) => import("../../types").GitlabJobCache[] | undefined;
@@ -0,0 +1,109 @@
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 __rest = this && this.__rest || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ var __read = this && this.__read || function (o, n) {
22
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
23
+ if (!m) return o;
24
+ var i = m.call(o),
25
+ r,
26
+ ar = [],
27
+ e;
28
+ try {
29
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
+ } catch (error) {
31
+ e = {
32
+ error: error
33
+ };
34
+ } finally {
35
+ try {
36
+ if (r && !r.done && (m = i["return"])) m.call(i);
37
+ } finally {
38
+ if (e) throw e.error;
39
+ }
40
+ }
41
+ return ar;
42
+ };
43
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
44
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
45
+ if (ar || !(i in from)) {
46
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
47
+ ar[i] = from[i];
48
+ }
49
+ }
50
+ return to.concat(ar || Array.prototype.slice.call(from));
51
+ };
52
+ Object.defineProperty(exports, "__esModule", {
53
+ value: true
54
+ });
55
+ exports.createJobCacheFromConfig = exports.createJobCacheFromCacheConfigs = void 0;
56
+ var path_1 = require("path");
57
+ var getAllCacheConfigsFromConfig_1 = require("./getAllCacheConfigsFromConfig");
58
+ var createJobCacheFromCacheConfigs = function (context, caches) {
59
+ if (caches.length === 0) return undefined;
60
+ var simpleCacheDefs = caches.filter(function (c) {
61
+ return !("key" in c);
62
+ });
63
+ var advancedCacheDefs = caches.filter(function (c) {
64
+ return "key" in c;
65
+ });
66
+ // simple caches are merged together into one. This is because e.g. gitlab has a limit of 4 caches, see https://gitlab.com/gitlab-org/gitlab/-/issues/421962
67
+ var simpleCaches = simpleCacheDefs.length > 0 ? [{
68
+ key: context.name + "-default",
69
+ policy: "pull-push",
70
+ paths: simpleCacheDefs.flatMap(function (c) {
71
+ return c.paths.map(function (p) {
72
+ var _a;
73
+ var baseDir = c.pathMode === "absolute" ? "" : (_a = c.baseDir) !== null && _a !== void 0 ? _a : context.build.dir;
74
+ return (0, path_1.join)(baseDir, p);
75
+ });
76
+ })
77
+ }] : [];
78
+ var advancedCaches = advancedCacheDefs.map(function (_a) {
79
+ var _b;
80
+ var key = _a.key,
81
+ paths = _a.paths,
82
+ policy = _a.policy,
83
+ scope = _a.scope,
84
+ pathMode = _a.pathMode,
85
+ buildDir = _a.buildDir,
86
+ rest = __rest(_a, ["key", "paths", "policy", "scope", "pathMode", "buildDir"]);
87
+ var baseDir = pathMode === "absolute" ? "" : buildDir !== null && buildDir !== void 0 ? buildDir : context.build.dir;
88
+ var transformedKey = scope === "global" ? key : typeof key === "string" ? (scope === "buildDir" // really edge case...
89
+ ? baseDir : context.name) + "-" + key : __assign(__assign({}, key), {
90
+ files: (_b = key.files) === null || _b === void 0 ? void 0 : _b.map(function (f) {
91
+ return pathMode === "absolute" ? f : (0, path_1.join)(baseDir, f);
92
+ })
93
+ });
94
+ return __assign({
95
+ key: transformedKey,
96
+ policy: policy !== null && policy !== void 0 ? policy : "pull-push",
97
+ paths: pathMode === "absolute" ? paths : paths === null || paths === void 0 ? void 0 : paths.map(function (p) {
98
+ return (0, path_1.join)(baseDir, p);
99
+ })
100
+ }, rest);
101
+ });
102
+ return __spreadArray(__spreadArray([], __read(advancedCaches), false), __read(simpleCaches), false);
103
+ };
104
+ exports.createJobCacheFromCacheConfigs = createJobCacheFromCacheConfigs;
105
+ /** shortcut, used in some build types */
106
+ var createJobCacheFromConfig = function (context, buildConfig) {
107
+ return (0, exports.createJobCacheFromCacheConfigs)(context, (0, getAllCacheConfigsFromConfig_1.getAllCacheConfigsFromConfig)(context, buildConfig));
108
+ };
109
+ exports.createJobCacheFromConfig = createJobCacheFromConfig;
@@ -0,0 +1,3 @@
1
+ import type { Context } from "../../types";
2
+ import type { BuildConfigStandalone, CacheConfig, WorkspaceBuildConfig } from "../types";
3
+ export declare const getAllCacheConfigsFromConfig: (context: Context, buildConfig: BuildConfigStandalone | WorkspaceBuildConfig) => CacheConfig[];
@@ -0,0 +1,66 @@
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 __read = this && this.__read || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o),
17
+ r,
18
+ ar = [],
19
+ e;
20
+ try {
21
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
22
+ } catch (error) {
23
+ e = {
24
+ error: error
25
+ };
26
+ } finally {
27
+ try {
28
+ if (r && !r.done && (m = i["return"])) m.call(i);
29
+ } finally {
30
+ if (e) throw e.error;
31
+ }
32
+ }
33
+ return ar;
34
+ };
35
+ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
36
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
37
+ if (ar || !(i in from)) {
38
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
39
+ ar[i] = from[i];
40
+ }
41
+ }
42
+ return to.concat(ar || Array.prototype.slice.call(from));
43
+ };
44
+ Object.defineProperty(exports, "__esModule", {
45
+ value: true
46
+ });
47
+ exports.getAllCacheConfigsFromConfig = void 0;
48
+ var index_1 = require("../../utils/index");
49
+ var transformLegacyJobCache_1 = require("./transformLegacyJobCache");
50
+ var getAllCacheConfigsFromConfig = function (context, buildConfig) {
51
+ return __spreadArray(__spreadArray(__spreadArray([], __read("jobCache" in buildConfig ? (0, transformLegacyJobCache_1.transformLegacyJobCache)(buildConfig.jobCache) : []), false), __read((0, index_1.ensureArray)(buildConfig.cache).map(function (c) {
52
+ return __assign(__assign({}, c), {
53
+ context: context
54
+ });
55
+ })), false), __read(context.type === "workspace" ?
56
+ // also add cache configs of the components of that workspace
57
+ context.components.flatMap(function (componentContext) {
58
+ var _a;
59
+ return (_a = (0, index_1.ensureArray)(componentContext.build.config.cache).map(function (c) {
60
+ return __assign(__assign({}, c), {
61
+ baseDir: componentContext.build.dir
62
+ });
63
+ })) !== null && _a !== void 0 ? _a : [];
64
+ }) : []), false);
65
+ };
66
+ exports.getAllCacheConfigsFromConfig = getAllCacheConfigsFromConfig;
@@ -0,0 +1,3 @@
1
+ import type { CacheConfigAdvanced } from "..";
2
+ import type { CatladderJobCache } from "../../types/jobs";
3
+ export declare function transformLegacyJobCache(jobCache: CatladderJobCache | CatladderJobCache[] | undefined): CacheConfigAdvanced[];
@@ -0,0 +1,29 @@
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
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.transformLegacyJobCache = void 0;
17
+ var utils_1 = require("../../utils");
18
+ function transformLegacyJobCache(jobCache) {
19
+ return (0, utils_1.ensureArray)(jobCache).map(function (cache) {
20
+ var _a, _b;
21
+ return __assign(__assign({
22
+ pathMode: "absolute"
23
+ }, cache), {
24
+ key: (_a = cache.key) !== null && _a !== void 0 ? _a : "default",
25
+ paths: (_b = cache.paths) !== null && _b !== void 0 ? _b : []
26
+ });
27
+ });
28
+ }
29
+ exports.transformLegacyJobCache = transformLegacyJobCache;
@@ -1,63 +1,20 @@
1
1
  "use strict";
2
2
 
3
- var __read = this && this.__read || function (o, n) {
4
- var m = typeof Symbol === "function" && o[Symbol.iterator];
5
- if (!m) return o;
6
- var i = m.call(o),
7
- r,
8
- ar = [],
9
- e;
10
- try {
11
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
12
- } catch (error) {
13
- e = {
14
- error: error
15
- };
16
- } finally {
17
- try {
18
- if (r && !r.done && (m = i["return"])) m.call(i);
19
- } finally {
20
- if (e) throw e.error;
21
- }
22
- }
23
- return ar;
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
- };
34
3
  Object.defineProperty(exports, "__esModule", {
35
4
  value: true
36
5
  });
37
6
  exports.createCustomBuildJobs = void 0;
38
- var utils_1 = require("../../utils");
39
7
  var docker_1 = require("../docker");
40
8
  var types_1 = require("../types");
41
9
  var base_1 = require("../base");
42
- var RUNNER_BUILD_VARIABLES = {
43
- KUBERNETES_CPU_REQUEST: "0.45",
44
- KUBERNETES_MEMORY_REQUEST: "1Gi",
45
- KUBERNETES_MEMORY_LIMIT: "4Gi"
46
- };
10
+ var createBuildJobDefinition_1 = require("../base/createBuildJobDefinition");
47
11
  var createCustomBuildJobs = function (context) {
48
- var _a;
49
12
  var buildConfig = context.build.config;
50
13
  if (!(0, types_1.isOfBuildType)(buildConfig, "custom")) {
51
14
  throw new Error("deploy config is not custom");
52
15
  }
53
16
  return (0, base_1.createComponentBuildJobs)(context, {
54
- appBuild: buildConfig.buildCommand !== null ? {
55
- image: buildConfig.jobImage,
56
- runnerVariables: RUNNER_BUILD_VARIABLES,
57
- cache: buildConfig.jobCache,
58
- services: buildConfig.jobServices,
59
- script: __spreadArray([], __read((_a = (0, utils_1.ensureArray)(buildConfig.buildCommand)) !== null && _a !== void 0 ? _a : []), false)
60
- } : undefined,
17
+ appBuild: buildConfig.buildCommand !== null ? (0, createBuildJobDefinition_1.createBuildJobDefinition)(context, buildConfig) : undefined,
61
18
  dockerBuild: {
62
19
  script: (0, docker_1.getDockerBuildScriptWithBuiltInDockerFile)(context),
63
20
  variables: {}
@@ -1,6 +1,6 @@
1
+ import type { Artifacts } from "../../types";
1
2
  import type { ComponentContext } from "../../types/context";
2
3
  import type { CatladderJob } from "../../types/jobs";
3
- import type { Artifacts } from "../../types";
4
4
  export declare const createCustomTestJobs: (context: ComponentContext) => CatladderJob[];
5
5
  export type OptionalArtifacts = {
6
6
  artifacts: Artifacts;
@@ -46,15 +46,16 @@ Object.defineProperty(exports, "__esModule", {
46
46
  });
47
47
  exports.createCustomTestJobs = void 0;
48
48
  var utils_1 = require("../../utils");
49
- var types_1 = require("../types");
50
49
  var createArtifactsConfig_1 = require("../base/createArtifactsConfig");
50
+ var createJobCache_1 = require("../cache/createJobCache");
51
+ var types_1 = require("../types");
51
52
  var RUNNER_CUSTOM_TEST_VARIABLES = {
52
53
  KUBERNETES_CPU_REQUEST: "0.45",
53
54
  KUBERNETES_MEMORY_REQUEST: "1Gi",
54
55
  KUBERNETES_MEMORY_LIMIT: "4Gi"
55
56
  };
56
57
  var createCustomTestJobs = function (context) {
57
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
58
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
58
59
  // don't run tests after release
59
60
  // TODO: this will be replaced by using rules
60
61
  if (context.trigger === "taggedRelease") {
@@ -70,7 +71,7 @@ var createCustomTestJobs = function (context) {
70
71
  }, context.environment.jobOnlyVars.build.envVars), (_a = buildConfig.extraVars) !== null && _a !== void 0 ? _a : {}),
71
72
  runnerVariables: RUNNER_CUSTOM_TEST_VARIABLES,
72
73
  services: buildConfig.jobServices,
73
- cache: buildConfig.jobCache,
74
+ cache: (0, createJobCache_1.createJobCacheFromConfig)(context, buildConfig),
74
75
  stage: "test",
75
76
  needs: [],
76
77
  envMode: "none"
@@ -80,21 +81,21 @@ var createCustomTestJobs = function (context) {
80
81
  }, base), {
81
82
  image: (_c = (_b = buildConfig.audit) === null || _b === void 0 ? void 0 : _b.jobImage) !== null && _c !== void 0 ? _c : buildConfig.jobImage,
82
83
  cache: undefined,
83
- script: __spreadArray([], __read((_e = (0, utils_1.ensureArray)((_d = buildConfig.audit) === null || _d === void 0 ? void 0 : _d.command)) !== null && _e !== void 0 ? _e : []), false),
84
+ script: __spreadArray([], __read((0, utils_1.ensureArray)((_d = buildConfig.audit) === null || _d === void 0 ? void 0 : _d.command)), false),
84
85
  allow_failure: true
85
- }), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_f = buildConfig.audit) === null || _f === void 0 ? void 0 : _f.artifactsReports, (_g = buildConfig.audit) === null || _g === void 0 ? void 0 : _g.artifacts)) : null;
86
+ }), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_e = buildConfig.audit) === null || _e === void 0 ? void 0 : _e.artifactsReports, (_f = buildConfig.audit) === null || _f === void 0 ? void 0 : _f.artifacts)) : null;
86
87
  var lintJob = buildConfig.lint ? __assign(__assign(__assign({
87
88
  name: "👮 lint"
88
89
  }, base), {
89
- image: (_j = (_h = buildConfig.lint) === null || _h === void 0 ? void 0 : _h.jobImage) !== null && _j !== void 0 ? _j : buildConfig.jobImage,
90
- script: __spreadArray([], __read((_l = (0, utils_1.ensureArray)((_k = buildConfig.lint) === null || _k === void 0 ? void 0 : _k.command)) !== null && _l !== void 0 ? _l : []), false)
91
- }), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_m = buildConfig.lint) === null || _m === void 0 ? void 0 : _m.artifactsReports, (_o = buildConfig.lint) === null || _o === void 0 ? void 0 : _o.artifacts)) : null;
90
+ image: (_h = (_g = buildConfig.lint) === null || _g === void 0 ? void 0 : _g.jobImage) !== null && _h !== void 0 ? _h : buildConfig.jobImage,
91
+ script: __spreadArray([], __read((0, utils_1.ensureArray)((_j = buildConfig.lint) === null || _j === void 0 ? void 0 : _j.command)), false)
92
+ }), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_k = buildConfig.lint) === null || _k === void 0 ? void 0 : _k.artifactsReports, (_l = buildConfig.lint) === null || _l === void 0 ? void 0 : _l.artifacts)) : null;
92
93
  var testJob = buildConfig.test ? __assign(__assign(__assign({
93
94
  name: "🧪 test"
94
95
  }, base), {
95
- image: (_q = (_p = buildConfig.test) === null || _p === void 0 ? void 0 : _p.jobImage) !== null && _q !== void 0 ? _q : buildConfig.jobImage,
96
- script: __spreadArray([], __read((_s = (0, utils_1.ensureArray)((_r = buildConfig.test) === null || _r === void 0 ? void 0 : _r.command)) !== null && _s !== void 0 ? _s : []), false)
97
- }), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_t = buildConfig.test) === null || _t === void 0 ? void 0 : _t.artifactsReports, (_u = buildConfig.test) === null || _u === void 0 ? void 0 : _u.artifacts)) : null;
96
+ image: (_o = (_m = buildConfig.test) === null || _m === void 0 ? void 0 : _m.jobImage) !== null && _o !== void 0 ? _o : buildConfig.jobImage,
97
+ script: __spreadArray([], __read((0, utils_1.ensureArray)((_p = buildConfig.test) === null || _p === void 0 ? void 0 : _p.command)), false)
98
+ }), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_q = buildConfig.test) === null || _q === void 0 ? void 0 : _q.artifactsReports, (_r = buildConfig.test) === null || _r === void 0 ? void 0 : _r.artifacts)) : null;
98
99
  return [auditJob, lintJob, testJob].filter(utils_1.notNil);
99
100
  };
100
101
  exports.createCustomTestJobs = createCustomTestJobs;
@@ -1,5 +1,5 @@
1
1
  import type { BuildConfigDocker } from ".";
2
- import type { ComponentContext } from "../types";
2
+ import type { ComponentContext, JobDefintion } from "../types";
3
3
  import type { CatladderJob } from "../types/jobs";
4
4
  export declare const getDockerImageVariables: (context: ComponentContext) => {
5
5
  DOCKER_IMAGE_TAG: string;
@@ -58,11 +58,12 @@ export declare const getDockerBuildVariables: (context: ComponentContext) => {
58
58
  };
59
59
  export declare const DOCKER_BUILD_JOB_NAME = "\uD83D\uDD28 docker";
60
60
  export declare const getDockerJobBaseProps: () => Pick<CatladderJob, "image" | "services" | "variables" | "runnerVariables">;
61
- export type DockerBuildJobDefinition = Partial<CatladderJob>;
61
+ export type DockerBuildJobDefinition = JobDefintion;
62
62
  export declare const createDockerBuildJobBase: (context: ComponentContext, {
63
63
  script,
64
+ cache,
64
65
  ...def
65
- }: Partial<CatladderJob>) => CatladderJob;
66
+ }: JobDefintion) => CatladderJob;
66
67
  export declare const gitlabDockerLogin: (context: ComponentContext) => string[];
67
68
  export declare const getDockerBuildScriptWithBuiltInDockerFile: (context: ComponentContext, defaultType?: BuildConfigDocker["type"]) => (string | undefined)[];
68
69
  export declare const getDockerBuildDefaultScript: (context: ComponentContext, ensureDockerFileScript?: string | null) => (string | undefined)[];
@@ -66,6 +66,7 @@ var artifactsRegistry_1 = require("../deploy/cloudRun/artifactsRegistry");
66
66
  var gcloudServiceAccountLoginCommands_1 = require("../deploy/cloudRun/utils/gcloudServiceAccountLoginCommands");
67
67
  var runner_1 = require("../runner");
68
68
  var gitlab_1 = require("../utils/gitlab");
69
+ var createJobCache_1 = require("./cache/createJobCache");
69
70
  var DOCKER_BUILD_RUNNER_REQUESTS = {
70
71
  KUBERNETES_CPU_REQUEST: "0.45",
71
72
  KUBERNETES_MEMORY_REQUEST: "1Gi",
@@ -143,11 +144,13 @@ var getDockerJobBaseProps = function () {
143
144
  exports.getDockerJobBaseProps = getDockerJobBaseProps;
144
145
  var createDockerBuildJobBase = function (context, _a) {
145
146
  var script = _a.script,
146
- def = __rest(_a, ["script"]);
147
+ cache = _a.cache,
148
+ def = __rest(_a, ["script", "cache"]);
147
149
  return (0, lodash_1.merge)(__assign(__assign({
148
150
  name: exports.DOCKER_BUILD_JOB_NAME,
149
151
  envMode: "jobPerEnv",
150
- stage: "build"
152
+ stage: "build",
153
+ cache: cache ? (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, cache) : undefined
151
154
  }, (0, exports.getDockerJobBaseProps)()), {
152
155
  script: script || []
153
156
  }), {
@@ -35,14 +35,11 @@ Object.defineProperty(exports, "__esModule", {
35
35
  value: true
36
36
  });
37
37
  exports.createNodeDockerJobDefinition = exports.createNodeBuildJobDefinition = exports.createNodeBuildJobs = void 0;
38
- var runner_1 = require("../../runner");
39
38
  var context_1 = require("../../types/context");
40
- var utils_1 = require("../../utils");
41
39
  var base_1 = require("../base");
40
+ var createBuildJobDefinition_1 = require("../base/createBuildJobDefinition");
42
41
  var docker_1 = require("../docker");
43
- var types_1 = require("../types");
44
42
  var cache_1 = require("./cache");
45
- var constants_1 = require("./constants");
46
43
  var yarn_1 = require("./yarn");
47
44
  var createNodeBuildJobs = function (context) {
48
45
  if (context.type === "workspace") {
@@ -57,21 +54,12 @@ var createNodeBuildJobs = function (context) {
57
54
  };
58
55
  exports.createNodeBuildJobs = createNodeBuildJobs;
59
56
  var createNodeBuildJobDefinition = function (context) {
60
- var _a, _b, _c;
61
57
  var buildConfig = context.build.config;
62
- if (!(0, types_1.isOfBuildType)(buildConfig, "node", "node-static", "storybook")) {
63
- throw new Error("deploy config is not node, node-static or storybook");
64
- }
65
- if (buildConfig.buildCommand === null) return undefined;
66
- var defaultImage = (0, runner_1.getRunnerImage)("jobs-default");
67
58
  var yarnInstall = (0, yarn_1.getYarnInstall)(context);
68
- return {
69
- image: (_a = buildConfig.jobImage) !== null && _a !== void 0 ? _a : defaultImage,
70
- runnerVariables: constants_1.NODE_RUNNER_BUILD_VARIABLES,
71
- cache: __spreadArray(__spreadArray(__spreadArray([], __read((_b = (0, utils_1.ensureArray)(buildConfig.jobCache)) !== null && _b !== void 0 ? _b : []), false), __read((0, cache_1.getNodeCache)(context)), false), __read((0, cache_1.getNextCache)(context)), false),
72
- script: __spreadArray(__spreadArray([], __read(yarnInstall), false), __read((_c = (0, utils_1.ensureArray)(buildConfig.buildCommand)) !== null && _c !== void 0 ? _c : []), false),
73
- jobTags: buildConfig.jobTags
74
- };
59
+ return (0, createBuildJobDefinition_1.createBuildJobDefinition)(context, buildConfig, {
60
+ prescript: yarnInstall,
61
+ cache: __spreadArray(__spreadArray([], __read((0, cache_1.getNodeCache)(context)), false), __read((0, cache_1.getNextCache)(context)), false)
62
+ });
75
63
  };
76
64
  exports.createNodeBuildJobDefinition = createNodeBuildJobDefinition;
77
65
  var createNodeDockerJobDefinition = function (context) {
@@ -1,7 +1,7 @@
1
1
  import type { Context, WorkspaceContext } from "../../types/context";
2
- import type { GitlabJobCache } from "../../types/gitlab-types";
3
- export declare const getYarnCache: (context: Context, policy?: string) => GitlabJobCache[];
4
- export declare const getNodeModulesCache: (context: Context, policy?: string) => GitlabJobCache[];
5
- export declare const getNodeCache: (context: Context, policy?: string) => GitlabJobCache[];
6
- export declare const getNextCache: (context: Context) => GitlabJobCache[];
7
- export declare const getWorkspaceDefaultCaches: (context: WorkspaceContext) => GitlabJobCache[];
2
+ import type { CacheConfig } from "../types";
3
+ export declare const getYarnCache: (context: Context, policy?: string) => CacheConfig[];
4
+ export declare const getNodeModulesCache: (context: Context, policy?: string) => CacheConfig[];
5
+ export declare const getNodeCache: (context: Context, policy?: string) => CacheConfig[];
6
+ export declare const getNextCache: (context: Context) => CacheConfig[];
7
+ export declare const getWorkspaceDefaultCaches: (context: WorkspaceContext) => CacheConfig[];
@@ -48,14 +48,11 @@ var getYarnCache = function (context, policy) {
48
48
  policy = "pull-push";
49
49
  }
50
50
  var componentIsInWorkspace = context.type === "component" && context.packageManagerInfo.componentIsInWorkspace;
51
- return [componentIsInWorkspace ? {
51
+ return [{
52
+ scope: componentIsInWorkspace ? "global" : "buildDir",
52
53
  key: "yarn",
53
54
  policy: policy,
54
55
  paths: [".yarn"]
55
- } : {
56
- key: (0, slugify_1.default)(context.build.dir) + "-yarn",
57
- policy: policy,
58
- paths: [(0, path_1.join)(context.build.dir, ".yarn")]
59
56
  }];
60
57
  };
61
58
  exports.getYarnCache = getYarnCache;
@@ -68,6 +65,8 @@ var getNodeModulesCache = function (context, policy) {
68
65
  // We intentionally do not use the contents of yarn.lock as a cache key, as yarn install should always guarantee that the files are updated, but it can still use part of the cache if not all packages are up-to-date.
69
66
  // It would slow down all pipelines whenever one adds a new dependency as it will need to download all node_modules again.
70
67
  return [{
68
+ scope: "global",
69
+ pathMode: "absolute",
71
70
  // if component is in a shared workspace, use workspace cache. use individual cache else
72
71
  key: componentIsInWorkspace ? "node-modules-workspace" : (0, slugify_1.default)(context.build.dir) + "-node-modules",
73
72
  // we use the dirname, not the component name, because in certain cases we have two apps in the same directory and want to share the cache, e.g. when having storybook in the same package.json
@@ -86,12 +85,12 @@ var getNodeCache = function (context, policy) {
86
85
  };
87
86
  exports.getNodeCache = getNodeCache;
88
87
  var getNextCache = function (context) {
89
- var key = context.name + "-next-cache";
90
88
  var paths = context.build.getComponentDirs("direct").map(function (c) {
91
89
  return (0, path_1.join)(c, ".next/cache");
92
90
  });
93
91
  return [{
94
- key: key,
92
+ pathMode: "absolute",
93
+ key: "next-cache",
95
94
  policy: "pull-push",
96
95
  paths: paths
97
96
  }];
@@ -100,9 +99,9 @@ exports.getNextCache = getNextCache;
100
99
  var getWorkspaceDefaultCaches = function (context) {
101
100
  return [{
102
101
  // turbo repo
103
- key: context.name + "-turbo",
102
+ key: "turbo",
104
103
  policy: "pull-push",
105
- paths: [(0, path_1.join)(context.build.dir, ".turbo")]
104
+ paths: [".turbo"]
106
105
  }];
107
106
  };
108
107
  exports.getWorkspaceDefaultCaches = getWorkspaceDefaultCaches;