@catladder/pipeline 1.150.2 → 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/bundles/catladder-gitlab/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/context/createComponentContext.js +1 -0
- 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 -5
- package/package.json +1 -1
- package/src/context/createComponentContext.ts +1 -0
- 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 +1 -4
|
@@ -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
|
@@ -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.
|
|
@@ -119,7 +120,3 @@ export type ComponentContext = {
|
|
|
119
120
|
};
|
|
120
121
|
|
|
121
122
|
export type Context = ComponentContext;
|
|
122
|
-
|
|
123
|
-
export type CatladderJobWithContext<S = BaseStage> = CatladderJob<S> & {
|
|
124
|
-
context: ComponentContext;
|
|
125
|
-
};
|