@catladder/pipeline 1.150.0 → 1.150.2

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.
@@ -20,7 +20,7 @@ export const createNodeBuildJobs = (
20
20
  }
21
21
 
22
22
  const defaultImage = getRunnerImage("jobs-default");
23
- const yarnInstall = getYarnInstall(context.build);
23
+ const yarnInstall = getYarnInstall(context);
24
24
 
25
25
  return createBuildJobs(context, {
26
26
  appBuild:
@@ -30,7 +30,7 @@ export const createNodeBuildJobs = (
30
30
  runnerVariables: NODE_RUNNER_BUILD_VARIABLES,
31
31
  cache: [
32
32
  ...(ensureArray(buildConfig.jobCache) ?? []),
33
- ...getNodeCache(context.build),
33
+ ...getNodeCache(context),
34
34
  ...getNextCache(context),
35
35
  ],
36
36
  script: [
@@ -41,8 +41,8 @@ export const createNodeBuildJobs = (
41
41
  paths: [
42
42
  context.build.dir,
43
43
  // also copy workspace dependencies in monorepo if packages are shared and they create build artifacts
44
- ...(context.build.packageManagerInfo
45
- .currentWorkspaceDependencies ?? []),
44
+ ...(context.packageManagerInfo.currentWorkspaceDependencies ??
45
+ []),
46
46
  ].flatMap((dir) => [
47
47
  join(dir, "__build_info.json"),
48
48
  join(dir, "dist"),
@@ -65,14 +65,12 @@ export const createNodeBuildJobs = (
65
65
  ? "nginx"
66
66
  : "node",
67
67
  ),
68
- cache: [...getYarnCache(context.build, "pull")],
68
+ cache: [...getYarnCache(context, "pull")],
69
69
  variables: {
70
70
  // only required for non static
71
- DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(
72
- context.build,
73
- ),
71
+ DOCKER_COPY_AND_INSTALL_APP: getDockerAppCopyAndBuildScript(context),
74
72
  DOCKER_COPY_WORKSPACE_FILES:
75
- context.build.packageManagerInfo.pathsToCopyInDocker
73
+ context.packageManagerInfo.pathsToCopyInDocker
76
74
  .map((dir) => `COPY --chown=node:node ${dir} /app/${dir}`)
77
75
  ?.join("\n"),
78
76
  },
@@ -1,11 +1,11 @@
1
+ import { uniq } from "lodash";
1
2
  import { join } from "path";
2
3
  import slugify from "slugify";
3
- import type { BuildContext, ComponentContext } from "../../types/context";
4
+ import type { ComponentContext, Context } from "../../types/context";
4
5
  import type { GitlabJobCache } from "../../types/gitlab-types";
5
- import { uniq } from "lodash";
6
6
 
7
7
  export const getYarnCache = (
8
- context: BuildContext,
8
+ context: Context,
9
9
  policy = "pull-push",
10
10
  ): GitlabJobCache[] => {
11
11
  const componentIsInWorkspace =
@@ -18,15 +18,15 @@ export const getYarnCache = (
18
18
  paths: [".yarn"],
19
19
  }
20
20
  : {
21
- key: slugify(context.dir) + "-yarn",
21
+ key: slugify(context.build.dir) + "-yarn",
22
22
  policy,
23
- paths: [join(context.dir, ".yarn")],
23
+ paths: [join(context.build.dir, ".yarn")],
24
24
  },
25
25
  ];
26
26
  };
27
27
 
28
28
  export const getNodeModulesCache = (
29
- context: BuildContext,
29
+ context: Context,
30
30
  policy = "pull-push",
31
31
  ): GitlabJobCache[] => {
32
32
  const componentIsInWorkspace =
@@ -39,7 +39,7 @@ export const getNodeModulesCache = (
39
39
  // if component is in a shared workspace, use workspace cache. use individual cache else
40
40
  key: componentIsInWorkspace
41
41
  ? "node-modules-workspace"
42
- : slugify(context.dir) + "-node-modules", // 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
42
+ : slugify(context.build.dir) + "-node-modules", // 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
43
43
  policy,
44
44
  paths: [
45
45
  ...(componentIsInWorkspace
@@ -49,13 +49,13 @@ export const getNodeModulesCache = (
49
49
  join(w.location, "node_modules"),
50
50
  ) ?? []),
51
51
  ])
52
- : [join(context.dir, "node_modules")]),
52
+ : [join(context.build.dir, "node_modules")]),
53
53
  ],
54
54
  },
55
55
  ];
56
56
  };
57
57
  export const getNodeCache = (
58
- context: BuildContext,
58
+ context: Context,
59
59
  policy = "pull-push",
60
60
  ): GitlabJobCache[] => {
61
61
  return [
@@ -32,13 +32,13 @@ export const createMeteorBuildJobs = (
32
32
  throw new Error("deploy config is not meteor");
33
33
  }
34
34
 
35
- const yarnInstall = getYarnInstall(context.build);
35
+ const yarnInstall = getYarnInstall(context);
36
36
 
37
37
  return createBuildJobs(context, {
38
38
  appBuild:
39
39
  buildConfig.buildCommand !== null
40
40
  ? {
41
- cache: [...getNodeCache(context.build), ...getMeteorCache(context)],
41
+ cache: [...getNodeCache(context), ...getMeteorCache(context)],
42
42
  image: getRunnerImage("jobs-meteor"),
43
43
  variables: {
44
44
  METEOR_DISABLE_OPTIMISTIC_CACHING: "1", // see https://forums.meteor.com/t/veeery-long-building-time-inside-docker-container/58673/17?u=macrozone
@@ -30,7 +30,7 @@ export const createNodeTestJobs = (
30
30
  needs: [],
31
31
  envMode: "none",
32
32
  };
33
- const yarnInstall = getYarnInstall(context.build);
33
+ const yarnInstall = getYarnInstall(context);
34
34
  const auditJob: CatladderJob | null =
35
35
  buildConfig.audit !== false
36
36
  ? {
@@ -41,7 +41,7 @@ export const createNodeTestJobs = (
41
41
  script: [
42
42
  `cd ${context.build.dir}`,
43
43
  ...(ensureArray(buildConfig.audit?.command) ?? [
44
- context.build.packageManagerInfo.isClassic
44
+ context.packageManagerInfo.isClassic
45
45
  ? "yarn audit"
46
46
  : "yarn npm audit --environment production", // yarn 2
47
47
  ]),
@@ -61,9 +61,9 @@ export const createNodeTestJobs = (
61
61
  name: "👮 lint",
62
62
  ...base,
63
63
  image: buildConfig.lint?.jobImage ?? defaultImage,
64
- cache: getNodeCache(context.build),
64
+ cache: getNodeCache(context),
65
65
  script: [
66
- ...ensureNodeVersion(context.build),
66
+ ...ensureNodeVersion(context),
67
67
  `cd ${context.build.dir}`,
68
68
  ...yarnInstall,
69
69
  ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
@@ -83,9 +83,9 @@ export const createNodeTestJobs = (
83
83
  ...base,
84
84
  image:
85
85
  buildConfig.test?.jobImage ?? getRunnerImage("jobs-testing-chrome"),
86
- cache: getNodeCache(context.build),
86
+ cache: getNodeCache(context),
87
87
  script: [
88
- ...ensureNodeVersion(context.build),
88
+ ...ensureNodeVersion(context),
89
89
  `cd ${context.build.dir}`,
90
90
  ...yarnInstall,
91
91
  ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
@@ -1,5 +1,5 @@
1
1
  import { BashExpression } from "../../bash/BashExpression";
2
- import type { BuildContext, ComponentContext } from "../../types";
2
+ import type { BuildContext, ComponentContext, Context } from "../../types";
3
3
  import { ensureArray } from "../../utils";
4
4
  import { collapseableSection } from "../../utils/gitlab";
5
5
 
@@ -8,7 +8,7 @@ const YARN_INSTALL_CLASSIC = `yarn install --frozen-lockfile`;
8
8
  // FIXME: check why and when rebuild is needed
9
9
  const YARN_BERRY_PROD_REBUILD = `yarn workspaces focus --production && yarn rebuild`;
10
10
 
11
- const getYarnInstallCommand = (context: BuildContext) => {
11
+ const getYarnInstallCommand = (context: Context) => {
12
12
  if (context.packageManagerInfo.isClassic) {
13
13
  return YARN_INSTALL_CLASSIC;
14
14
  }
@@ -16,7 +16,7 @@ const getYarnInstallCommand = (context: BuildContext) => {
16
16
  return `yarn install --immutable`;
17
17
  };
18
18
 
19
- export const ensureNodeVersion = (context: BuildContext) =>
19
+ export const ensureNodeVersion = (context: Context) =>
20
20
  collapseableSection(
21
21
  "nodeinstall",
22
22
  "Ensure node version",
@@ -26,13 +26,15 @@ export const ensureNodeVersion = (context: BuildContext) =>
26
26
  ]);
27
27
 
28
28
  export const getYarnInstall = (
29
- context: BuildContext,
29
+ context: Context,
30
30
  options?: {
31
31
  noCustomPostInstall: boolean;
32
32
  },
33
33
  ) => {
34
34
  const postInstall =
35
- "postInstall" in context.config ? context.config.postInstall : null;
35
+ "postInstall" in context.build.config
36
+ ? context.build.config.postInstall
37
+ : null;
36
38
  return [
37
39
  ...ensureNodeVersion(context),
38
40
  ...collapseableSection(
@@ -50,7 +52,7 @@ export const getYarnInstall = (
50
52
 
51
53
  const DOCKER_COPY_FILES = `COPY --chown=node:node $APP_DIR .`;
52
54
 
53
- export const getDockerAppCopyAndBuildScript = (context: BuildContext) => {
55
+ export const getDockerAppCopyAndBuildScript = (context: Context) => {
54
56
  if (context.packageManagerInfo.isClassic) {
55
57
  return new BashExpression(
56
58
  `
package/src/build/sbom.ts CHANGED
@@ -11,7 +11,7 @@ export const createSbomBuildJob = (context: ComponentContext): CatladderJob => {
11
11
  const defaultImage = "aquasec/trivy:0.38.3";
12
12
  const defaultScript = [
13
13
  `trivy fs --quiet --format cyclonedx --output "${SBOM_FILE}" ${
14
- context.build.packageManagerInfo.componentIsInWorkspace
14
+ context.packageManagerInfo.componentIsInWorkspace
15
15
  ? "."
16
16
  : context.build.dir
17
17
  }`,
@@ -10,7 +10,7 @@ import type { PartialDeep } from "../types/utils";
10
10
  import { mergeWithMergingArrays } from "../utils";
11
11
  import { getEnvironment } from "./getEnvironment";
12
12
  import { getEnvironmentContext } from "./getEnvironmentContext";
13
- import { getPackageManagerInfo } from "../pipeline/packageManager";
13
+ import { getPackageManagerInfoForComponent } from "../pipeline/packageManager";
14
14
 
15
15
  export type CreateComponentContextContext = {
16
16
  config: Config;
@@ -29,7 +29,7 @@ export const createComponentContext = async (
29
29
  );
30
30
  }
31
31
 
32
- const packageManagerInfo = await getPackageManagerInfo(
32
+ const packageManagerInfo = await getPackageManagerInfoForComponent(
33
33
  ctx.config,
34
34
  ctx.componentName,
35
35
  );
@@ -67,7 +67,6 @@ export const createComponentContext = async (
67
67
 
68
68
  build: {
69
69
  dir: dir,
70
- packageManagerInfo: packageManagerInfo,
71
70
  config: build,
72
71
  },
73
72
  deploy: deploy
@@ -19,7 +19,7 @@ export const createCustomDeployJobs = (
19
19
  throw new Error("deploy config is not custom");
20
20
  }
21
21
  // FIXME: custom deploy currently assumes yarn-based project
22
- const yarnInstall = getYarnInstall(context.build, {
22
+ const yarnInstall = getYarnInstall(context, {
23
23
  noCustomPostInstall: true,
24
24
  });
25
25
  return createDeployementJobs(context, {
@@ -1,17 +1,17 @@
1
1
  import { existsSync } from "fs";
2
2
  import { join } from "path";
3
3
  import { pathEqual } from "path-equal";
4
- import type { Config, PackageManagerInfo } from "../types";
4
+ import type { Config, PackageManagerInfoComponent } from "../types";
5
5
  import {
6
6
  getWorkspaces,
7
7
  getYarnVersion,
8
8
  getWorkspaceDependencies,
9
9
  } from "./yarn/yarnUtils";
10
10
 
11
- export const getPackageManagerInfo = async (
11
+ export const getPackageManagerInfoForComponent = async (
12
12
  config: Config,
13
13
  componentName: string,
14
- ): Promise<PackageManagerInfo> => {
14
+ ): Promise<PackageManagerInfoComponent> => {
15
15
  // currently only supports yarn
16
16
  const version = await getYarnVersion();
17
17
  if (!version) throw new Error("could not get yarn version");
@@ -1,6 +1,6 @@
1
1
  import { exec } from "child-process-promise";
2
2
  import memoizee from "memoizee";
3
- import type { PackageManagerInfo, YarnWorkspace } from "../../types";
3
+ import type { PackageManagerInfoComponent, YarnWorkspace } from "../../types";
4
4
 
5
5
  const execOrFail = async (cmd: string, onFail: string): Promise<string> => {
6
6
  try {
@@ -18,7 +18,7 @@ export const getYarnVersion = memoizee(
18
18
  );
19
19
  // export for mocking
20
20
  export const getWorkspaces = memoizee(
21
- async (isClassic: boolean): Promise<PackageManagerInfo["workspaces"]> => {
21
+ async (isClassic: boolean): Promise<Array<YarnWorkspace>> => {
22
22
  return isClassic
23
23
  ? Object.values(
24
24
  JSON.parse(
@@ -66,7 +66,7 @@ export type YarnWorkspace = {
66
66
  workspaceDependencies: string[];
67
67
  mismatchedWorkspaceDependencies: string[];
68
68
  };
69
- export type YarnPackageManagerInfo = {
69
+ export type YarnPackageManagerInfoComponent = {
70
70
  type: "yarn";
71
71
  version: string;
72
72
  workspaces: YarnWorkspace[];
@@ -77,20 +77,21 @@ export type YarnPackageManagerInfo = {
77
77
  currentWorkspaceDependencies: string[];
78
78
  };
79
79
 
80
- export type PackageManagerInfo = YarnPackageManagerInfo;
80
+ export type PackageManagerInfoComponent = YarnPackageManagerInfoComponent;
81
81
 
82
82
  export type ContextBeforeConfig = {
83
83
  componentName: string;
84
84
  fullConfig: Config;
85
- packageManagerInfo?: PackageManagerInfo;
85
+ packageManagerInfo?: PackageManagerInfoComponent;
86
86
  };
87
87
 
88
- export type BuildContext = {
88
+ export type BuildContextComponent = {
89
89
  dir: string;
90
- packageManagerInfo: PackageManagerInfo;
90
+
91
91
  config: BuildConfig;
92
92
  };
93
93
 
94
+ export type BuildContext = BuildContextComponent;
94
95
  export type DeployContext = {
95
96
  config: DeployConfig;
96
97
  };
@@ -104,24 +105,19 @@ export type ComponentContext = {
104
105
  *
105
106
  */
106
107
  componentConfig: ComponentConfig;
107
- build: BuildContext;
108
+ build: BuildContextComponent;
108
109
  deploy?: DeployContext | null;
109
110
  fullConfig: Config;
110
111
  environment: Environment;
111
112
 
112
113
  trigger?: PipelineTrigger;
113
114
  pipelineType?: PipelineType;
114
- /**
115
- * @deprecated use buildContext.packageManagerInfo instead
116
- */
117
- packageManagerInfo: PackageManagerInfo;
115
+
116
+ packageManagerInfo: PackageManagerInfoComponent;
118
117
 
119
118
  customJobs?: CatladderJob[];
120
119
  };
121
120
 
122
- /**
123
- * @deprecated use ComponentContext instead
124
- */
125
121
  export type Context = ComponentContext;
126
122
 
127
123
  export type CatladderJobWithContext<S = BaseStage> = CatladderJob<S> & {