@catladder/pipeline 1.150.1 → 1.150.3
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.
- package/dist/build/base/createAppBuildJob.js +1 -1
- package/dist/build/node/buildJob.js +6 -6
- package/dist/build/node/cache.d.ts +4 -4
- package/dist/build/node/cache.js +5 -5
- package/dist/build/node/meteor.js +2 -2
- package/dist/build/node/testJob.js +6 -6
- package/dist/build/node/yarn.d.ts +4 -4
- package/dist/build/node/yarn.js +1 -1
- package/dist/build/sbom.js +1 -1
- package/dist/bundles/catladder-gitlab/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/createComponentContext.js +1 -1
- package/dist/deploy/custom/deployJob.js +1 -1
- package/dist/pipeline/createAllJobs.d.ts +6 -6
- package/dist/pipeline/createAllJobs.js +7 -24
- package/dist/pipeline/createMainPipeline.js +2 -2
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +5 -6
- package/dist/pipeline/gitlab/createGitlabJobs.js +31 -29
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/context.d.ts +3 -12
- package/package.json +1 -1
- package/src/build/base/createAppBuildJob.ts +1 -1
- package/src/build/node/buildJob.ts +7 -9
- package/src/build/node/cache.ts +9 -9
- package/src/build/node/meteor.ts +2 -2
- package/src/build/node/testJob.ts +6 -6
- package/src/build/node/yarn.ts +8 -6
- package/src/build/sbom.ts +1 -1
- package/src/context/createComponentContext.ts +1 -1
- package/src/deploy/custom/deployJob.ts +1 -1
- package/src/pipeline/createAllJobs.ts +9 -19
- package/src/pipeline/createMainPipeline.ts +6 -2
- package/src/pipeline/gitlab/createGitlabJobs.ts +47 -46
- package/src/types/context.ts +3 -11
|
@@ -30,7 +30,7 @@ export const createNodeTestJobs = (
|
|
|
30
30
|
needs: [],
|
|
31
31
|
envMode: "none",
|
|
32
32
|
};
|
|
33
|
-
const yarnInstall = getYarnInstall(context
|
|
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.
|
|
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
|
|
64
|
+
cache: getNodeCache(context),
|
|
65
65
|
script: [
|
|
66
|
-
...ensureNodeVersion(context
|
|
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
|
|
86
|
+
cache: getNodeCache(context),
|
|
87
87
|
script: [
|
|
88
|
-
...ensureNodeVersion(context
|
|
88
|
+
...ensureNodeVersion(context),
|
|
89
89
|
`cd ${context.build.dir}`,
|
|
90
90
|
...yarnInstall,
|
|
91
91
|
...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
|
package/src/build/node/yarn.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
29
|
+
context: Context,
|
|
30
30
|
options?: {
|
|
31
31
|
noCustomPostInstall: boolean;
|
|
32
32
|
},
|
|
33
33
|
) => {
|
|
34
34
|
const postInstall =
|
|
35
|
-
"postInstall" in context.
|
|
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:
|
|
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.
|
|
14
|
+
context.packageManagerInfo.componentIsInWorkspace
|
|
15
15
|
? "."
|
|
16
16
|
: context.build.dir
|
|
17
17
|
}`,
|
|
@@ -64,10 +64,10 @@ export const createComponentContext = async (
|
|
|
64
64
|
const context: Omit<ComponentContext, "customJobs"> = {
|
|
65
65
|
fullConfig: ctx.config,
|
|
66
66
|
componentConfig,
|
|
67
|
+
env: ctx.env,
|
|
67
68
|
|
|
68
69
|
build: {
|
|
69
70
|
dir: dir,
|
|
70
|
-
packageManagerInfo: packageManagerInfo,
|
|
71
71
|
config: build,
|
|
72
72
|
},
|
|
73
73
|
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
|
|
22
|
+
const yarnInstall = getYarnInstall(context, {
|
|
23
23
|
noCustomPostInstall: true,
|
|
24
24
|
});
|
|
25
25
|
return createDeployementJobs(context, {
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { getAllEnvsByTrigger } from "../config";
|
|
2
2
|
import { createComponentContext } from "../context";
|
|
3
3
|
import type {
|
|
4
|
-
CatladderJobWithContext,
|
|
5
4
|
ComponentContext,
|
|
6
5
|
Config,
|
|
7
6
|
PipelineTrigger,
|
|
8
7
|
PipelineType,
|
|
9
8
|
} from "../types";
|
|
9
|
+
import type { CatladderJob } from "../types/jobs";
|
|
10
10
|
import { createJobsForComponentContext } from "./createJobsForComponent";
|
|
11
11
|
|
|
12
|
-
export type AllCatladderJobs = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
12
|
+
export type AllCatladderJobs = Array<{
|
|
13
|
+
context: ComponentContext;
|
|
14
|
+
jobs: Array<CatladderJob>;
|
|
15
|
+
}>;
|
|
17
16
|
|
|
18
17
|
export type AllJobsContext = {
|
|
19
18
|
config: Config;
|
|
@@ -65,17 +64,8 @@ export const createAllJobs = async ({
|
|
|
65
64
|
pipelineType,
|
|
66
65
|
});
|
|
67
66
|
|
|
68
|
-
return allComponentContext.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
acc[componentName][env] = createJobsForComponentContext(context).map(
|
|
73
|
-
(job) => ({
|
|
74
|
-
...job,
|
|
75
|
-
context,
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
return acc;
|
|
80
|
-
}, {} as AllCatladderJobs);
|
|
67
|
+
return allComponentContext.map(({ context }) => ({
|
|
68
|
+
context,
|
|
69
|
+
jobs: createJobsForComponentContext(context),
|
|
70
|
+
}));
|
|
81
71
|
};
|
|
@@ -43,8 +43,12 @@ export const createMainPipeline = async <T extends PipelineType>(
|
|
|
43
43
|
// this is purely for better readability in git diffs when you add new components
|
|
44
44
|
.sort((a, b) => {
|
|
45
45
|
const componentNames = Object.keys(config.components);
|
|
46
|
-
const aIndex = componentNames.findIndex(
|
|
47
|
-
|
|
46
|
+
const aIndex = componentNames.findIndex(
|
|
47
|
+
(c) => c === a.context.componentName,
|
|
48
|
+
);
|
|
49
|
+
const bIndex = componentNames.findIndex(
|
|
50
|
+
(c) => c === b.context.componentName,
|
|
51
|
+
);
|
|
48
52
|
return aIndex - bIndex;
|
|
49
53
|
})
|
|
50
54
|
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import { isObject, merge } from "lodash";
|
|
2
2
|
import { getInjectVarsScript } from "../../bash/getInjectVarsScript";
|
|
3
3
|
import { BASE_RETRY } from "../../defaults";
|
|
4
|
-
import type {
|
|
5
|
-
CatladderJobWithContext,
|
|
6
|
-
ComponentContext,
|
|
7
|
-
GitlabJobDef,
|
|
8
|
-
GitlabRule,
|
|
9
|
-
} from "../../types";
|
|
4
|
+
import type { ComponentContext, GitlabJobDef, GitlabRule } from "../../types";
|
|
10
5
|
import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
|
|
11
6
|
import { notNil } from "../../utils";
|
|
12
7
|
import { collapseableSection } from "../../utils/gitlab";
|
|
13
|
-
import type { AllCatladderJobs } from "../createAllJobs";
|
|
14
8
|
import { removeUndefined } from "../../utils/removeUndefined";
|
|
9
|
+
import type { AllCatladderJobs } from "../createAllJobs";
|
|
15
10
|
|
|
16
11
|
export type AllGitlabJobs = {
|
|
17
12
|
name: string;
|
|
18
13
|
gitlabJob: GitlabJobDef;
|
|
19
|
-
|
|
20
|
-
env: string;
|
|
14
|
+
context: ComponentContext;
|
|
21
15
|
}[];
|
|
22
16
|
|
|
23
17
|
export const GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
|
|
@@ -38,9 +32,12 @@ const getFullReferencedJobName = (
|
|
|
38
32
|
env: string,
|
|
39
33
|
allJobs: AllCatladderJobs,
|
|
40
34
|
) => {
|
|
41
|
-
const referencedJob = allJobs
|
|
42
|
-
(
|
|
43
|
-
|
|
35
|
+
const referencedJob = allJobs
|
|
36
|
+
.find(
|
|
37
|
+
(j) => j.context.componentName === componentName && j.context.env === env,
|
|
38
|
+
)
|
|
39
|
+
?.jobs?.find((j) => j.name === referencedJobName);
|
|
40
|
+
|
|
44
41
|
if (!referencedJob) {
|
|
45
42
|
throw new Error(
|
|
46
43
|
`unknown job referenced: '${referencedJobName}' from '${env}:${componentName}'`,
|
|
@@ -54,8 +51,7 @@ const getJobName = (need: CatladderJobNeed) =>
|
|
|
54
51
|
isObject(need) ? need.job : need;
|
|
55
52
|
|
|
56
53
|
export const makeGitlabJob = (
|
|
57
|
-
|
|
58
|
-
env: string,
|
|
54
|
+
context: ComponentContext,
|
|
59
55
|
{
|
|
60
56
|
environment,
|
|
61
57
|
envMode,
|
|
@@ -65,21 +61,28 @@ export const makeGitlabJob = (
|
|
|
65
61
|
needs,
|
|
66
62
|
jobTags,
|
|
67
63
|
script,
|
|
68
|
-
|
|
64
|
+
|
|
69
65
|
variables,
|
|
70
66
|
runnerVariables,
|
|
71
67
|
when,
|
|
72
68
|
...job
|
|
73
|
-
}:
|
|
69
|
+
}: CatladderJob<string>,
|
|
74
70
|
allJobs: AllCatladderJobs,
|
|
75
71
|
baseRules?: GitlabRule[],
|
|
76
72
|
): [fullName: string, job: GitlabJobDef] => {
|
|
77
|
-
const stage =
|
|
73
|
+
const stage =
|
|
74
|
+
envMode === "stagePerEnv" ? `${job.stage} ${context.env}` : job.stage;
|
|
78
75
|
|
|
79
76
|
const needsFromStages: CatladderJob["needs"] = needsStages?.flatMap((n) => {
|
|
80
|
-
const referencedComponentName = componentName;
|
|
77
|
+
const referencedComponentName = context.componentName;
|
|
81
78
|
const allJobNamesFromThatStage =
|
|
82
|
-
allJobs
|
|
79
|
+
allJobs
|
|
80
|
+
.filter(
|
|
81
|
+
(j) =>
|
|
82
|
+
j.context.componentName === referencedComponentName &&
|
|
83
|
+
j.context.env === context.env,
|
|
84
|
+
)
|
|
85
|
+
.flatMap((j) => j.jobs)
|
|
83
86
|
?.filter((j) => j.stage === n.stage)
|
|
84
87
|
?.map((j) => j.name) ?? [];
|
|
85
88
|
|
|
@@ -102,13 +105,18 @@ export const makeGitlabJob = (
|
|
|
102
105
|
? {
|
|
103
106
|
job: getFullReferencedJobName(
|
|
104
107
|
n.job,
|
|
105
|
-
n.componentName ?? componentName,
|
|
106
|
-
env,
|
|
108
|
+
n.componentName ?? context.componentName,
|
|
109
|
+
context.env,
|
|
107
110
|
allJobs,
|
|
108
111
|
),
|
|
109
112
|
artifacts: n.artifacts,
|
|
110
113
|
}
|
|
111
|
-
: getFullReferencedJobName(
|
|
114
|
+
: getFullReferencedJobName(
|
|
115
|
+
n,
|
|
116
|
+
context.componentName,
|
|
117
|
+
context.env,
|
|
118
|
+
allJobs,
|
|
119
|
+
),
|
|
112
120
|
) // sort in a predictable manner for snapshot tests
|
|
113
121
|
.sort((a, b) => getJobName(a).localeCompare(getJobName(b)));
|
|
114
122
|
|
|
@@ -118,8 +126,8 @@ export const makeGitlabJob = (
|
|
|
118
126
|
|
|
119
127
|
const fullJobName = getFullJobName(
|
|
120
128
|
name,
|
|
121
|
-
componentName,
|
|
122
|
-
envMode !== "none" ? env : undefined,
|
|
129
|
+
context.componentName,
|
|
130
|
+
envMode !== "none" ? context.env : undefined,
|
|
123
131
|
);
|
|
124
132
|
|
|
125
133
|
// backwards compatibility, some may still use KUBERNETES_CPU_REQUEST, KUBERNETES_MEMORY_REQUEST, etc. in variables.
|
|
@@ -189,8 +197,8 @@ export const makeGitlabJob = (
|
|
|
189
197
|
retry: BASE_RETRY,
|
|
190
198
|
interruptible: true,
|
|
191
199
|
},
|
|
192
|
-
componentName,
|
|
193
|
-
env,
|
|
200
|
+
context.componentName,
|
|
201
|
+
context.env,
|
|
194
202
|
allJobs,
|
|
195
203
|
);
|
|
196
204
|
|
|
@@ -255,26 +263,19 @@ export const createGitlabJobs = async (
|
|
|
255
263
|
allJobs: AllCatladderJobs,
|
|
256
264
|
baseRules?: GitlabRule[],
|
|
257
265
|
): Promise<AllGitlabJobs> => {
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
name: fullJobName,
|
|
273
|
-
gitlabJob,
|
|
274
|
-
componentName,
|
|
275
|
-
env,
|
|
276
|
-
};
|
|
277
|
-
});
|
|
266
|
+
return allJobs.flatMap(({ context, jobs }) => {
|
|
267
|
+
return jobs.map((job) => {
|
|
268
|
+
const [fullJobName, gitlabJob] = makeGitlabJob(
|
|
269
|
+
context,
|
|
270
|
+
job,
|
|
271
|
+
allJobs,
|
|
272
|
+
baseRules,
|
|
273
|
+
);
|
|
274
|
+
return {
|
|
275
|
+
name: fullJobName,
|
|
276
|
+
gitlabJob,
|
|
277
|
+
context,
|
|
278
|
+
};
|
|
278
279
|
});
|
|
279
280
|
});
|
|
280
281
|
};
|
package/src/types/context.ts
CHANGED
|
@@ -87,7 +87,7 @@ export type ContextBeforeConfig = {
|
|
|
87
87
|
|
|
88
88
|
export type BuildContextComponent = {
|
|
89
89
|
dir: string;
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
config: BuildConfig;
|
|
92
92
|
};
|
|
93
93
|
|
|
@@ -97,6 +97,7 @@ export type DeployContext = {
|
|
|
97
97
|
};
|
|
98
98
|
export type ComponentContext = {
|
|
99
99
|
componentName: string;
|
|
100
|
+
env: string;
|
|
100
101
|
|
|
101
102
|
/**
|
|
102
103
|
* the merged component config.
|
|
@@ -112,19 +113,10 @@ export type ComponentContext = {
|
|
|
112
113
|
|
|
113
114
|
trigger?: PipelineTrigger;
|
|
114
115
|
pipelineType?: PipelineType;
|
|
115
|
-
|
|
116
|
-
* @deprecated use buildContext.packageManagerInfo instead
|
|
117
|
-
*/
|
|
116
|
+
|
|
118
117
|
packageManagerInfo: PackageManagerInfoComponent;
|
|
119
118
|
|
|
120
119
|
customJobs?: CatladderJob[];
|
|
121
120
|
};
|
|
122
121
|
|
|
123
|
-
/**
|
|
124
|
-
* @deprecated use ComponentContext instead
|
|
125
|
-
*/
|
|
126
122
|
export type Context = ComponentContext;
|
|
127
|
-
|
|
128
|
-
export type CatladderJobWithContext<S = BaseStage> = CatladderJob<S> & {
|
|
129
|
-
context: ComponentContext;
|
|
130
|
-
};
|