@catladder/pipeline 1.165.0 → 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 (71) 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-meteor-with-worker.test.ts.snap +4 -4
  37. package/examples/__snapshots__/cloud-run-with-sql.test.ts.snap +817 -1717
  38. package/examples/__snapshots__/custom-build-job-with-tests.test.ts.snap +0 -4
  39. package/examples/__snapshots__/custom-build-job.test.ts.snap +0 -4
  40. package/examples/__snapshots__/custom-sbom-java.test.ts.snap +0 -4
  41. package/examples/__snapshots__/meteor-kubernetes.test.ts.snap +4 -4
  42. package/examples/__snapshots__/native-app.test.ts.snap +24 -20
  43. package/examples/__snapshots__/workspace-api-www-custom-cache.test.ts.snap +2374 -0
  44. package/examples/__snapshots__/workspace-api-www.test.ts.snap +2354 -0
  45. package/examples/cloud-run-with-sql.ts +1 -23
  46. package/examples/workspace-api-www-custom-cache.test.ts +11 -0
  47. package/examples/workspace-api-www-custom-cache.ts +51 -0
  48. package/examples/workspace-api-www.test.ts +11 -0
  49. package/examples/workspace-api-www.ts +45 -0
  50. package/package.json +1 -1
  51. package/src/build/base/createAppBuildJob.ts +6 -4
  52. package/src/build/base/createBuildJobDefinition.ts +38 -0
  53. package/src/build/cache/createJobCache.ts +85 -0
  54. package/src/build/cache/getAllCacheConfigsFromConfig.ts +33 -0
  55. package/src/build/cache/transformLegacyJobCache.ts +14 -0
  56. package/src/build/custom/buildJob.ts +2 -14
  57. package/src/build/custom/testJob.ts +7 -6
  58. package/src/build/docker.ts +5 -3
  59. package/src/build/node/buildJob.ts +6 -29
  60. package/src/build/node/cache.ts +20 -21
  61. package/src/build/node/meteor.ts +7 -8
  62. package/src/build/node/testJob.ts +7 -6
  63. package/src/build/node/yarn.ts +1 -1
  64. package/src/build/rails/test.ts +4 -4
  65. package/src/build/sbom.ts +2 -2
  66. package/src/build/types.ts +54 -4
  67. package/src/types/gitlab-types.ts +2 -2
  68. package/src/types/index.ts +1 -0
  69. package/src/types/jobDefinition.ts +9 -0
  70. package/src/types/jobs.ts +5 -8
  71. package/src/utils/index.ts +4 -1
@@ -1,25 +1,24 @@
1
- import { join } from "path";
2
1
  import { getRunnerImage } from "../../runner";
3
- import type { GitlabJobCache } from "../../types";
4
2
  import type { ComponentContext } from "../../types/context";
5
3
 
6
4
  import type { CatladderJob } from "../../types/jobs";
7
5
 
8
6
  import { createComponentBuildJobs } from "../base";
9
7
  import { getDockerBuildScriptWithBuiltInDockerFile } from "../docker";
8
+ import type { CacheConfig } from "../types";
10
9
  import { isOfBuildType } from "../types";
11
10
  import { getNodeCache } from "./cache";
12
11
  import { getYarnInstall } from "./yarn";
13
12
 
14
- const getMeteorCache = (context: ComponentContext): GitlabJobCache[] => [
13
+ const getMeteorCache = (context: ComponentContext): CacheConfig[] => [
15
14
  {
16
- key: context.name + "meteor-build-cache",
15
+ key: "meteor-build-cache",
17
16
  policy: "pull-push",
18
17
  paths: [
19
- join(context.build.dir, ".meteor/local/resolver-result-cache.json"),
20
- join(context.build.dir, ".meteor/local/plugin-cache"),
21
- join(context.build.dir, ".meteor/local/isopacks"),
22
- join(context.build.dir, ".meteor/local/bundler-cache/scanner"),
18
+ ".meteor/local/resolver-result-cache.json",
19
+ ".meteor/local/plugin-cache",
20
+ ".meteor/local/isopacks",
21
+ ".meteor/local/bundler-cache/scanner",
23
22
  ],
24
23
  },
25
24
  ];
@@ -5,11 +5,12 @@ import {
5
5
  type ComponentContext,
6
6
  } from "../../types/context";
7
7
  import type { CatladderJob } from "../../types/jobs";
8
- import { ensureArray, notNil } from "../../utils";
8
+ import { ensureArrayOrNull, notNil } from "../../utils";
9
9
  import { createArtifactsConfig } from "../base/createArtifactsConfig";
10
10
  import { getNodeCache } from "./cache";
11
11
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
12
12
  import { ensureNodeVersion, getYarnInstall } from "./yarn";
13
+ import { createJobCacheFromCacheConfigs } from "../cache/createJobCache";
13
14
 
14
15
  export const createNodeTestJobs = (
15
16
  context: ComponentContext | WorkspaceContext,
@@ -55,7 +56,7 @@ export const createNodeTestJobs = (
55
56
  cache: undefined, // audit does not need yarn install and no cache
56
57
  script: [
57
58
  `cd ${context.build.dir}`,
58
- ...(ensureArray(buildConfig.audit?.command) ?? [
59
+ ...(ensureArrayOrNull(buildConfig.audit?.command) ?? [
59
60
  context.packageManagerInfo.isClassic
60
61
  ? "yarn audit"
61
62
  : "yarn npm audit --environment production", // yarn 2
@@ -76,12 +77,12 @@ export const createNodeTestJobs = (
76
77
  name: "👮 lint",
77
78
  ...base,
78
79
  image: buildConfig.lint?.jobImage ?? defaultImage,
79
- cache: getNodeCache(context),
80
+ cache: createJobCacheFromCacheConfigs(context, getNodeCache(context)),
80
81
  script: [
81
82
  ...ensureNodeVersion(context),
82
83
  `cd ${context.build.dir}`,
83
84
  ...yarnInstall,
84
- ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
85
+ ...(ensureArrayOrNull(buildConfig.lint?.command) ?? ["yarn lint"]),
85
86
  ],
86
87
  ...createArtifactsConfig(
87
88
  context.build.dir,
@@ -98,12 +99,12 @@ export const createNodeTestJobs = (
98
99
  ...base,
99
100
  image:
100
101
  buildConfig.test?.jobImage ?? getRunnerImage("jobs-testing-chrome"),
101
- cache: getNodeCache(context),
102
+ cache: createJobCacheFromCacheConfigs(context, getNodeCache(context)),
102
103
  script: [
103
104
  ...ensureNodeVersion(context),
104
105
  `cd ${context.build.dir}`,
105
106
  ...yarnInstall,
106
- ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
107
+ ...(ensureArrayOrNull(buildConfig.test?.command) ?? ["yarn test"]),
107
108
  ],
108
109
  ...createArtifactsConfig(
109
110
  context.build.dir,
@@ -45,7 +45,7 @@ export const getYarnInstall = (
45
45
  ? collapseableSection(
46
46
  "postinstall",
47
47
  "Custom post install",
48
- )(ensureArray(postInstall) ?? [])
48
+ )(ensureArray(postInstall))
49
49
  : []),
50
50
  ];
51
51
  };
@@ -3,7 +3,7 @@ import {
3
3
  type ComponentContext,
4
4
  } from "../..";
5
5
  import type { CatladderJob } from "../../types/jobs";
6
- import { ensureArray, notNil } from "../../utils";
6
+ import { ensureArrayOrNull, notNil } from "../../utils";
7
7
 
8
8
  export const createRailsTestJobs = (
9
9
  context: ComponentContext,
@@ -54,7 +54,7 @@ export const createRailsTestJobs = (
54
54
  buildConfig.audit?.jobImage ?? buildConfig.jobImage ?? defaultImage,
55
55
  script: [
56
56
  `cd ${context.build.dir}`,
57
- ...(ensureArray(buildConfig.audit?.command) ?? [
57
+ ...(ensureArrayOrNull(buildConfig.audit?.command) ?? [
58
58
  "gem install bundler-audit",
59
59
  "bundle audit check",
60
60
  ]),
@@ -75,7 +75,7 @@ export const createRailsTestJobs = (
75
75
  script: [
76
76
  `cd ${context.build.dir}`,
77
77
  ...bundlerInstall,
78
- ...(ensureArray(buildConfig.lint?.command) ?? [
78
+ ...(ensureArrayOrNull(buildConfig.lint?.command) ?? [
79
79
  "bundle exec rubocop",
80
80
  ]),
81
81
  ],
@@ -93,7 +93,7 @@ export const createRailsTestJobs = (
93
93
  script: [
94
94
  `cd ${context.build.dir}`,
95
95
  ...bundlerInstall,
96
- ...(ensureArray(buildConfig.test?.command) ?? [
96
+ ...(ensureArrayOrNull(buildConfig.test?.command) ?? [
97
97
  "bundle exec rspec",
98
98
  ]),
99
99
  ],
package/src/build/sbom.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isStandaloneBuildConfig } from ".";
2
2
  import type { ComponentContext } from "../types/context";
3
3
  import type { CatladderJob } from "../types/jobs";
4
- import { ensureArray } from "../utils";
4
+ import { ensureArrayOrNull } from "../utils";
5
5
 
6
6
  export const SBOM_BUILD_JOB_NAME = "🧾 sbom";
7
7
  export const SBOM_FILE = "__sbom.json";
@@ -29,7 +29,7 @@ export const createSbomBuildJob = (context: ComponentContext): CatladderJob => {
29
29
  isStandaloneBuildConfig(buildConfig) &&
30
30
  buildConfig.type === "custom" &&
31
31
  buildConfig.sbom !== false
32
- ? ensureArray(buildConfig.sbom?.command) ?? defaultScript
32
+ ? ensureArrayOrNull(buildConfig.sbom?.command) ?? defaultScript
33
33
  : defaultScript;
34
34
 
35
35
  return {
@@ -1,7 +1,42 @@
1
1
  import type { Artifacts, EnvVars, GitlabJobImage } from "../types";
2
2
  import type { Services } from "../types/gitlab-ci-yml";
3
3
 
4
- import type { CatladderJob } from "../types/jobs";
4
+ import type { CatladderJob, CatladderJobCache } from "../types/jobs";
5
+
6
+ export type CacheConfigAdvanced = Omit<CatladderJobCache, "paths" | "key"> & {
7
+ /**
8
+ * if you set a key, the cache is scoped to the key. Be aware that there is a limit in gitlab of 4 caches.
9
+ *
10
+ * see https://gitlab.com/gitlab-org/gitlab/-/issues/421962
11
+ */
12
+ key: Required<CatladderJobCache>["key"];
13
+
14
+ /**
15
+ * whether the cache is scoped to the context (component or workspace) or the build directory.
16
+ *
17
+ * defaults to context
18
+ */
19
+ scope?: "context" | "buildDir" | "global";
20
+ } & CacheConfigSimple;
21
+
22
+ export type CacheConfigSimple = {
23
+ /**
24
+ * paths to cache. All Paths are relative to the context dir.
25
+ */
26
+ paths: string[];
27
+
28
+ /**
29
+ * whether paths are relative to the base dir. defaults to relative.
30
+ */
31
+ pathMode?: "relative" | "absolute";
32
+
33
+ /**
34
+ * custom base dir
35
+ */
36
+ baseDir?: string;
37
+ };
38
+
39
+ export type CacheConfig = CacheConfigSimple | CacheConfigAdvanced;
5
40
 
6
41
  export type BuildConfigArtifactsReports = {
7
42
  /**
@@ -13,6 +48,13 @@ export type BuildConfigArtifactsReports = {
13
48
  junit?: string[];
14
49
  };
15
50
 
51
+ export type WithCacheConfig = {
52
+ /*
53
+ cache config. All Paths are relative to the context dir.
54
+ */
55
+ cache?: CacheConfig | CacheConfig[];
56
+ };
57
+
16
58
  export type TestJobCustom = {
17
59
  command?: string | string[];
18
60
  jobImage?: GitlabJobImage;
@@ -87,6 +129,8 @@ export type BuildConfigBase = {
87
129
 
88
130
  /**
89
131
  * customize cache for the job
132
+ *
133
+ * @deprecated use cache
90
134
  */
91
135
  jobCache?: CatladderJob["cache"];
92
136
 
@@ -98,7 +142,7 @@ export type BuildConfigBase = {
98
142
  * custom image to use
99
143
  */
100
144
  jobImage?: GitlabJobImage;
101
- };
145
+ } & WithCacheConfig;
102
146
 
103
147
  export type BuildConfigNodeBase = BuildConfigBase & {
104
148
  /**
@@ -290,7 +334,7 @@ export type BuildConfigFromWorkspace = {
290
334
  * by default "dist" and ".next" are allways included
291
335
  */
292
336
  artifactsPaths?: string[];
293
- };
337
+ } & WithCacheConfig;
294
338
  export type BuildConfigStandalone =
295
339
  | BuildConfigNode
296
340
  | BuildConfigNodeStatic
@@ -351,7 +395,13 @@ export type WorkspaceBuildConfigBase = {
351
395
  * use to display information in merge requests, pipeline views and security dashboards.
352
396
  */
353
397
  artifactsReports?: BuildConfigArtifactsReports;
354
- };
398
+
399
+ jobImage?: GitlabJobImage;
400
+ /**
401
+ * tags for the underlying job runner (e.g gitlab)
402
+ */
403
+ jobTags?: string[];
404
+ } & WithCacheConfig;
355
405
 
356
406
  export type WorkspaceBuildConfigNode = {
357
407
  type: "node";
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  Artifacts as GitlabCiArtifacts,
3
3
  JobTemplate,
4
- Cache,
4
+ Cache as GitlabJobCache,
5
5
  Rules,
6
6
  } from "./gitlab-ci-yml";
7
7
 
@@ -9,7 +9,7 @@ export { Retry, Image as GitlabJobImage } from "./gitlab-ci-yml";
9
9
 
10
10
  // Reports won't show up on MRs until https://gitlab.com/groups/gitlab-org/-/epics/8205
11
11
  export type Artifacts = GitlabCiArtifacts;
12
- export type GitlabJobCache = Cache;
12
+ export type { GitlabJobCache };
13
13
  export type GitlabRule = Exclude<
14
14
  Exclude<Rules, null>[number],
15
15
  string | string[] // we only use the object version
@@ -1,4 +1,5 @@
1
1
  export * from "./config";
2
2
  export * from "./gitlab-types";
3
3
  export * from "./context";
4
+ export * from "./jobDefinition";
4
5
  export * from "./pipeline";
@@ -0,0 +1,9 @@
1
+ import type { CacheConfig } from "../build";
2
+ import { CacheConfigAdvanced, CacheConfigSimple } from "../build";
3
+ import type { CatladderJob } from "./jobs";
4
+
5
+ export type JobDefintion = Partial<
6
+ Omit<CatladderJob, "artifacts" | "cache">
7
+ > & {
8
+ cache?: CacheConfig[];
9
+ };
package/src/types/jobs.ts CHANGED
@@ -1,17 +1,14 @@
1
1
  import type { UnspecifiedEnvVars } from "..";
2
- import type {
3
- BashExpression,
4
- StringOrBashExpression,
5
- } from "../bash/BashExpression";
6
2
  import type {
7
3
  Artifacts,
4
+ GitlabEnvironment,
8
5
  GitlabJobCache,
9
- GitlabRule,
10
- GitlabJobImage,
11
6
  GitlabJobDef,
12
- GitlabEnvironment,
7
+ GitlabJobImage,
8
+ GitlabRule,
13
9
  } from "./gitlab-types";
14
10
 
11
+ export type CatladderJobCache = GitlabJobCache;
15
12
  export const BASE_STAGES = [
16
13
  "setup",
17
14
  "test",
@@ -84,7 +81,7 @@ export type CatladderJob<S = BaseStage> = {
84
81
  /**
85
82
  * cache config, we use here the same shape as gitlab itself
86
83
  */
87
- cache?: GitlabJobCache | GitlabJobCache[];
84
+ cache?: CatladderJobCache | CatladderJobCache[];
88
85
 
89
86
  /**
90
87
  * job artifacts, we also use gitlab shape here
@@ -6,9 +6,12 @@ export function notNil<TValue>(
6
6
  return value !== null && value !== undefined;
7
7
  }
8
8
 
9
- export const ensureArray = <T>(s: undefined | T | T[]): T[] | null =>
9
+ export const ensureArrayOrNull = <T>(s: undefined | T | T[]): T[] | null =>
10
10
  isNil(s) ? null : Array.isArray(s) ? s : [s];
11
11
 
12
+ export const ensureArray = <T>(s: undefined | T | T[]): T[] =>
13
+ ensureArrayOrNull(s) ?? [];
14
+
12
15
  // see https://github.com/lodash/lodash/issues/5384
13
16
  export const mergeWithMergingArrays = <A, B>(obj1: A, obj2: B): A & B => {
14
17
  return mergeWith({}, obj1, obj2, (prop1, prop2) =>