@catladder/pipeline 1.89.0 → 1.89.1
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/rails/build.js +4 -8
- package/dist/bundles/catladder-gitlab/index.js +3 -3
- package/dist/constants.js +1 -1
- package/dist/pipeline/createAllJobs.d.ts +8 -0
- package/dist/pipeline/createAllJobs.js +164 -0
- package/dist/pipeline/createChildPipeline.js +24 -48
- package/dist/pipeline/createJobsForComponent.d.ts +3 -0
- package/dist/pipeline/{createJobs.js → createJobsForComponent.js} +8 -100
- package/dist/pipeline/gitlab/createGitlabJobs.d.ts +14 -0
- package/dist/pipeline/gitlab/createGitlabJobs.js +260 -0
- package/dist/pipeline/index.d.ts +1 -1
- package/dist/pipeline/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/build/rails/build.ts +2 -5
- package/src/pipeline/createAllJobs.ts +38 -0
- package/src/pipeline/createChildPipeline.ts +6 -22
- package/src/pipeline/createJobsForComponent.ts +64 -0
- package/src/pipeline/gitlab/createGitlabJobs.ts +149 -0
- package/src/pipeline/index.ts +1 -1
- package/dist/pipeline/createJobs.d.ts +0 -3
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +0 -10
- package/dist/pipeline/gitlab/makeGitlabJob.js +0 -75
- package/src/pipeline/createJobs.ts +0 -196
- package/src/pipeline/gitlab/makeGitlabJob.ts +0 -25
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isFunction } from "lodash";
|
|
2
|
+
import { BUILD_TYPES } from "../build";
|
|
3
|
+
import { createContext } from "../context";
|
|
4
|
+
import { DEPLOY_TYPES } from "../deploy";
|
|
5
|
+
import type { Config, PipelineTrigger } from "../types/config";
|
|
6
|
+
import type { CommitInfo, Context } from "../types/context";
|
|
7
|
+
import type { CatladderJob } from "../types/jobs";
|
|
8
|
+
import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
|
|
9
|
+
import { getPackageManagerInfo } from "./packageManager";
|
|
10
|
+
|
|
11
|
+
const injectDefaultVarsInCustomJobs = (
|
|
12
|
+
context: Context,
|
|
13
|
+
jobs: CatladderJob[]
|
|
14
|
+
) =>
|
|
15
|
+
jobs.map(({ variables, ...job }) => ({
|
|
16
|
+
variables: {
|
|
17
|
+
...(context.environment.envVars ?? {}),
|
|
18
|
+
...(variables ?? {}),
|
|
19
|
+
},
|
|
20
|
+
...job,
|
|
21
|
+
}));
|
|
22
|
+
const getCustomJobs = (context: Context) => {
|
|
23
|
+
if (!context.componentConfig.customJobs) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const rawJobs = isFunction(context.componentConfig.customJobs)
|
|
27
|
+
? context.componentConfig.customJobs(context)
|
|
28
|
+
: context.componentConfig.customJobs;
|
|
29
|
+
return injectDefaultVarsInCustomJobs(context, rawJobs);
|
|
30
|
+
};
|
|
31
|
+
const createRawJobs = (context: Context): CatladderJob[] => {
|
|
32
|
+
if (context.componentConfig.deploy === false) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
const buildJobs =
|
|
36
|
+
BUILD_TYPES[context.componentConfig.build.type].jobs(context);
|
|
37
|
+
const deployJobs =
|
|
38
|
+
DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context);
|
|
39
|
+
|
|
40
|
+
const customJobs = getCustomJobs(context);
|
|
41
|
+
return [...buildJobs, ...deployJobs, ...customJobs];
|
|
42
|
+
};
|
|
43
|
+
export const createJobsForComponent = async (
|
|
44
|
+
config: Config,
|
|
45
|
+
componentName: string,
|
|
46
|
+
env: string,
|
|
47
|
+
trigger: PipelineTrigger
|
|
48
|
+
): Promise<Array<CatladderJob>> => {
|
|
49
|
+
const commitInfo: CommitInfo = {
|
|
50
|
+
...(await getBaseCommitInfo()),
|
|
51
|
+
trigger,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const packageManagerInfo = await getPackageManagerInfo(config, componentName);
|
|
55
|
+
|
|
56
|
+
const context = await createContext(
|
|
57
|
+
config,
|
|
58
|
+
componentName,
|
|
59
|
+
env,
|
|
60
|
+
commitInfo,
|
|
61
|
+
packageManagerInfo
|
|
62
|
+
);
|
|
63
|
+
return createRawJobs(context);
|
|
64
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { isObject } from "lodash";
|
|
2
|
+
import { BASE_RETRY } from "../../defaults";
|
|
3
|
+
import type { GitlabJobDef } from "../../types";
|
|
4
|
+
import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
|
|
5
|
+
import type { AllCatladderJobs } from "../createAllJobs";
|
|
6
|
+
|
|
7
|
+
type AllGitlabJobs = Record<string, GitlabJobDef>;
|
|
8
|
+
|
|
9
|
+
const getFullJobName = (
|
|
10
|
+
name: string,
|
|
11
|
+
componentName: string,
|
|
12
|
+
env?: string | null
|
|
13
|
+
) => {
|
|
14
|
+
if (env) {
|
|
15
|
+
return `${componentName} ${name} | ${env} `;
|
|
16
|
+
}
|
|
17
|
+
return `${componentName} ${name}`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getFullReferencedJobName = (
|
|
21
|
+
referencedJobName: string,
|
|
22
|
+
componentName: string,
|
|
23
|
+
env: string,
|
|
24
|
+
allJobs: AllCatladderJobs
|
|
25
|
+
) => {
|
|
26
|
+
const referencedJob = allJobs[componentName]?.[env]?.find(
|
|
27
|
+
(j) => j.name === referencedJobName
|
|
28
|
+
);
|
|
29
|
+
if (!referencedJob) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`unknown job referenced: '${referencedJobName}' from '${env}:${componentName}'`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const envToSet = referencedJob.envMode !== "none" ? env : null;
|
|
35
|
+
return getFullJobName(referencedJobName, componentName, envToSet);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getJobName = (need: CatladderJobNeed) =>
|
|
39
|
+
isObject(need) ? need.job : need;
|
|
40
|
+
|
|
41
|
+
export const makeGitlabJob = (
|
|
42
|
+
componentName: string,
|
|
43
|
+
env: string,
|
|
44
|
+
{
|
|
45
|
+
envMode,
|
|
46
|
+
needsStages,
|
|
47
|
+
needsOtherComponent,
|
|
48
|
+
name,
|
|
49
|
+
needs,
|
|
50
|
+
...job
|
|
51
|
+
}: CatladderJob<string>,
|
|
52
|
+
allJobs: AllCatladderJobs
|
|
53
|
+
): [fullName: string, job: GitlabJobDef] => {
|
|
54
|
+
const stage = envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
|
|
55
|
+
|
|
56
|
+
const needsFromStages: CatladderJob["needs"] = needsStages?.flatMap((n) => {
|
|
57
|
+
const referencedComponentName = componentName;
|
|
58
|
+
const allJobNamesFromThatStage =
|
|
59
|
+
allJobs[referencedComponentName]?.[env]
|
|
60
|
+
?.filter((j) => j.stage === n.stage)
|
|
61
|
+
?.map((j) => j.name) ?? [];
|
|
62
|
+
|
|
63
|
+
return allJobNamesFromThatStage.map((job) => ({
|
|
64
|
+
job,
|
|
65
|
+
artifacts: n.artifacts ?? false,
|
|
66
|
+
componentName: referencedComponentName,
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
const cleanedNeeds: CatladderJob["needs"] = [
|
|
70
|
+
...(needs ?? []),
|
|
71
|
+
// pull in legacy needs from other component, which is now identical to needs
|
|
72
|
+
...(needsOtherComponent ?? []),
|
|
73
|
+
...(needsFromStages ?? []),
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const gitlabNeeds: GitlabJobDef["needs"] = cleanedNeeds
|
|
77
|
+
?.map((n) =>
|
|
78
|
+
isObject(n)
|
|
79
|
+
? {
|
|
80
|
+
job: getFullReferencedJobName(
|
|
81
|
+
n.job,
|
|
82
|
+
n.componentName ?? componentName,
|
|
83
|
+
env,
|
|
84
|
+
allJobs
|
|
85
|
+
),
|
|
86
|
+
artifacts: n.artifacts,
|
|
87
|
+
}
|
|
88
|
+
: getFullReferencedJobName(n, componentName, env, allJobs)
|
|
89
|
+
) // sort in a predictable manner for snapshot tests
|
|
90
|
+
.sort((a, b) => getJobName(a).localeCompare(getJobName(b)));
|
|
91
|
+
|
|
92
|
+
const fullJobName = getFullJobName(
|
|
93
|
+
name,
|
|
94
|
+
componentName,
|
|
95
|
+
envMode !== "none" ? env : undefined
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const gitlabJob = {
|
|
99
|
+
...job,
|
|
100
|
+
stage,
|
|
101
|
+
environment: job.environment?.on_stop
|
|
102
|
+
? {
|
|
103
|
+
...job.environment,
|
|
104
|
+
on_stop: getFullReferencedJobName(
|
|
105
|
+
job.environment.on_stop,
|
|
106
|
+
componentName,
|
|
107
|
+
env,
|
|
108
|
+
allJobs
|
|
109
|
+
),
|
|
110
|
+
}
|
|
111
|
+
: job.environment,
|
|
112
|
+
// sort in a predictable manner for snapshot tests
|
|
113
|
+
needs: gitlabNeeds,
|
|
114
|
+
retry: BASE_RETRY,
|
|
115
|
+
interruptible: true,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return [fullJobName, gitlabJob];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const createGitlabJobs = async (
|
|
122
|
+
allJobs: AllCatladderJobs
|
|
123
|
+
): Promise<AllGitlabJobs> => {
|
|
124
|
+
return Object.keys(allJobs).reduce((accForComponents, componentName) => {
|
|
125
|
+
const componentJobs = allJobs[componentName];
|
|
126
|
+
return {
|
|
127
|
+
...accForComponents,
|
|
128
|
+
...Object.keys(componentJobs).reduce((accForEnvs, env) => {
|
|
129
|
+
const jobs = componentJobs[env];
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
...accForEnvs,
|
|
133
|
+
...jobs.reduce((accForJobs, job) => {
|
|
134
|
+
const [fullJobName, gitlabJob] = makeGitlabJob(
|
|
135
|
+
componentName,
|
|
136
|
+
env,
|
|
137
|
+
job,
|
|
138
|
+
allJobs
|
|
139
|
+
);
|
|
140
|
+
return {
|
|
141
|
+
...accForJobs,
|
|
142
|
+
[fullJobName]: gitlabJob,
|
|
143
|
+
};
|
|
144
|
+
}, {} as AllGitlabJobs),
|
|
145
|
+
};
|
|
146
|
+
}, {} as AllGitlabJobs),
|
|
147
|
+
};
|
|
148
|
+
}, {} as AllGitlabJobs);
|
|
149
|
+
};
|
package/src/pipeline/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./createChildPipeline";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./createJobsForComponent";
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { PipelineJob } from "../types";
|
|
2
|
-
import type { Config, PipelineTrigger } from "../types/config";
|
|
3
|
-
export declare const createJobs: <T extends "gitlab">(type: T, envs: string[], config: Config, componentName: string, trigger: PipelineTrigger) => Promise<Record<string, PipelineJob<T>>>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { GitlabJobDef } from "../../types";
|
|
2
|
-
import type { CatladderJob } from "../../types/jobs";
|
|
3
|
-
export declare const makeGitlabJob: ({
|
|
4
|
-
envMode,
|
|
5
|
-
needsStages,
|
|
6
|
-
needsOtherComponent,
|
|
7
|
-
name,
|
|
8
|
-
needs,
|
|
9
|
-
...rest
|
|
10
|
-
}: CatladderJob<string>) => GitlabJobDef;
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
-
exports.__esModule = true;
|
|
53
|
-
exports.makeGitlabJob = void 0;
|
|
54
|
-
var lodash_1 = require("lodash");
|
|
55
|
-
var defaults_1 = require("../../defaults");
|
|
56
|
-
var getJobName = function (need) {
|
|
57
|
-
return (0, lodash_1.isObject)(need) ? need.job : need;
|
|
58
|
-
};
|
|
59
|
-
var makeGitlabJob = function (_a) {
|
|
60
|
-
var envMode = _a.envMode,
|
|
61
|
-
needsStages = _a.needsStages,
|
|
62
|
-
needsOtherComponent = _a.needsOtherComponent,
|
|
63
|
-
name = _a.name,
|
|
64
|
-
needs = _a.needs,
|
|
65
|
-
rest = __rest(_a, ["envMode", "needsStages", "needsOtherComponent", "name", "needs"]);
|
|
66
|
-
return __assign(__assign({}, rest), {
|
|
67
|
-
// sort in a predictable manner for snapshot tests
|
|
68
|
-
needs: needs ? __spreadArray([], __read(needs), false).sort(function (a, b) {
|
|
69
|
-
return getJobName(a).localeCompare(getJobName(b));
|
|
70
|
-
}) : undefined,
|
|
71
|
-
retry: defaults_1.BASE_RETRY,
|
|
72
|
-
interruptible: true
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
exports.makeGitlabJob = makeGitlabJob;
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { isFunction, isObject } from "lodash";
|
|
2
|
-
import { BUILD_TYPES } from "../build";
|
|
3
|
-
import { createContext } from "../context";
|
|
4
|
-
import { DEPLOY_TYPES } from "../deploy";
|
|
5
|
-
import type { PipelineJob, PipelineType } from "../types";
|
|
6
|
-
import type { Config, PipelineTrigger } from "../types/config";
|
|
7
|
-
import type { CommitInfo, Context } from "../types/context";
|
|
8
|
-
import type { CatladderJob } from "../types/jobs";
|
|
9
|
-
import { notNil } from "../utils";
|
|
10
|
-
import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
|
|
11
|
-
import { makeGitlabJob } from "./gitlab/makeGitlabJob";
|
|
12
|
-
import { getPackageManagerInfo } from "./packageManager";
|
|
13
|
-
|
|
14
|
-
const injectDefaultVarsInCustomJobs = (
|
|
15
|
-
context: Context,
|
|
16
|
-
jobs: CatladderJob[]
|
|
17
|
-
) =>
|
|
18
|
-
jobs.map(({ variables, ...job }) => ({
|
|
19
|
-
variables: {
|
|
20
|
-
...(context.environment.envVars ?? {}),
|
|
21
|
-
...(variables ?? {}),
|
|
22
|
-
},
|
|
23
|
-
...job,
|
|
24
|
-
}));
|
|
25
|
-
const getCustomJobs = (context: Context) => {
|
|
26
|
-
if (!context.componentConfig.customJobs) {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
const rawJobs = isFunction(context.componentConfig.customJobs)
|
|
30
|
-
? context.componentConfig.customJobs(context)
|
|
31
|
-
: context.componentConfig.customJobs;
|
|
32
|
-
return injectDefaultVarsInCustomJobs(context, rawJobs);
|
|
33
|
-
};
|
|
34
|
-
const createRawJobs = (context: Context): CatladderJob[] => {
|
|
35
|
-
if (context.componentConfig.deploy === false) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
const buildJobs =
|
|
39
|
-
BUILD_TYPES[context.componentConfig.build.type].jobs(context);
|
|
40
|
-
const deployJobs =
|
|
41
|
-
DEPLOY_TYPES[context.componentConfig.deploy.type].jobs(context);
|
|
42
|
-
|
|
43
|
-
const customJobs = getCustomJobs(context);
|
|
44
|
-
return [...buildJobs, ...deployJobs, ...customJobs];
|
|
45
|
-
};
|
|
46
|
-
const getFullJobName = (
|
|
47
|
-
name: string,
|
|
48
|
-
componentName: string,
|
|
49
|
-
env?: string | null
|
|
50
|
-
) => {
|
|
51
|
-
if (env) {
|
|
52
|
-
return `${componentName} ${name} | ${env} `;
|
|
53
|
-
}
|
|
54
|
-
return `${componentName} ${name}`;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const getFullReferencedJobName = (
|
|
58
|
-
referencedJobName: string,
|
|
59
|
-
componentName: string,
|
|
60
|
-
env: string,
|
|
61
|
-
allRawJobs: CatladderJob[]
|
|
62
|
-
) => {
|
|
63
|
-
const referencedJob = allRawJobs.find((j) => j.name === referencedJobName);
|
|
64
|
-
if (!referencedJob) {
|
|
65
|
-
throw new Error("unknown job referenced: " + referencedJobName);
|
|
66
|
-
}
|
|
67
|
-
const envToSet = referencedJob.envMode !== "none" ? env : null;
|
|
68
|
-
return getFullJobName(referencedJobName, componentName, envToSet);
|
|
69
|
-
};
|
|
70
|
-
// replaces references to other jobs with the full name
|
|
71
|
-
// the full name contains the componentname and the env name (if any)
|
|
72
|
-
const replaceReferences = (
|
|
73
|
-
job: CatladderJob,
|
|
74
|
-
componentName: string,
|
|
75
|
-
env: string,
|
|
76
|
-
allRawJobs: CatladderJob[]
|
|
77
|
-
): CatladderJob<string> => {
|
|
78
|
-
const stage =
|
|
79
|
-
job.envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.stage;
|
|
80
|
-
|
|
81
|
-
const cleanedNeeds: CatladderJob["needs"] = [
|
|
82
|
-
...(job.needs ?? []),
|
|
83
|
-
// pull in legacy needs from other component, which is now identical to needs
|
|
84
|
-
...(job.needsOtherComponent ?? []),
|
|
85
|
-
];
|
|
86
|
-
const needs: CatladderJob["needs"] = cleanedNeeds?.map((n) =>
|
|
87
|
-
isObject(n)
|
|
88
|
-
? {
|
|
89
|
-
job: getFullReferencedJobName(
|
|
90
|
-
n.job,
|
|
91
|
-
n.componentName ?? componentName,
|
|
92
|
-
env,
|
|
93
|
-
allRawJobs
|
|
94
|
-
),
|
|
95
|
-
artifacts: n.artifacts,
|
|
96
|
-
}
|
|
97
|
-
: getFullReferencedJobName(n, componentName, env, allRawJobs)
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
...job,
|
|
102
|
-
stage,
|
|
103
|
-
needs,
|
|
104
|
-
environment: job.environment?.on_stop
|
|
105
|
-
? {
|
|
106
|
-
...job.environment,
|
|
107
|
-
on_stop: getFullReferencedJobName(
|
|
108
|
-
job.environment.on_stop,
|
|
109
|
-
componentName,
|
|
110
|
-
env,
|
|
111
|
-
allRawJobs
|
|
112
|
-
),
|
|
113
|
-
}
|
|
114
|
-
: job.environment,
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// this can be removed once https://gitlab.com/gitlab-org/gitlab/-/issues/220758 is resolved
|
|
119
|
-
const addStageNeeds = (jobs: CatladderJob[]): CatladderJob[] => {
|
|
120
|
-
// when a job defines needsStages, we add these as needs
|
|
121
|
-
return jobs.map((job) => {
|
|
122
|
-
if (!job.needsStages || job.needsStages.length === 0) {
|
|
123
|
-
return job;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const neededJobs = jobs
|
|
127
|
-
.map((j) => {
|
|
128
|
-
const neededStage = job.needsStages?.find((s) => j.stage === s.stage);
|
|
129
|
-
if (neededStage) {
|
|
130
|
-
return {
|
|
131
|
-
job: j.name,
|
|
132
|
-
artifacts: neededStage.artifacts ?? false,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
.filter(notNil);
|
|
137
|
-
return {
|
|
138
|
-
...job,
|
|
139
|
-
|
|
140
|
-
needs: [...(job.needs ?? []), ...neededJobs],
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export const createJobs = async <T extends PipelineType>(
|
|
146
|
-
type: T,
|
|
147
|
-
envs: string[],
|
|
148
|
-
config: Config,
|
|
149
|
-
componentName: string,
|
|
150
|
-
trigger: PipelineTrigger
|
|
151
|
-
): Promise<Record<string, PipelineJob<T>>> => {
|
|
152
|
-
const commitInfo: CommitInfo = {
|
|
153
|
-
...(await getBaseCommitInfo()),
|
|
154
|
-
trigger,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const packageManagerInfo = await getPackageManagerInfo(config, componentName);
|
|
158
|
-
|
|
159
|
-
return envs.reduce(async (acc, env) => {
|
|
160
|
-
const context = await createContext(
|
|
161
|
-
config,
|
|
162
|
-
componentName,
|
|
163
|
-
env,
|
|
164
|
-
commitInfo,
|
|
165
|
-
packageManagerInfo
|
|
166
|
-
);
|
|
167
|
-
const jobs = addStageNeeds(createRawJobs(context));
|
|
168
|
-
|
|
169
|
-
const result = {
|
|
170
|
-
...(await acc),
|
|
171
|
-
...jobs.reduce<Record<string, PipelineJob<T>>>((acc, job) => {
|
|
172
|
-
const jobWithResolvedReferences = replaceReferences(
|
|
173
|
-
job,
|
|
174
|
-
componentName,
|
|
175
|
-
env,
|
|
176
|
-
jobs
|
|
177
|
-
);
|
|
178
|
-
const jobName = getFullJobName(
|
|
179
|
-
job.name,
|
|
180
|
-
componentName,
|
|
181
|
-
job.envMode !== "none" ? env : undefined
|
|
182
|
-
);
|
|
183
|
-
if (type === "gitlab") {
|
|
184
|
-
return {
|
|
185
|
-
...acc,
|
|
186
|
-
[jobName]: makeGitlabJob(
|
|
187
|
-
jobWithResolvedReferences
|
|
188
|
-
) as PipelineJob<T>,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
throw new Error("not supported");
|
|
192
|
-
}, await Promise.resolve({})),
|
|
193
|
-
};
|
|
194
|
-
return result;
|
|
195
|
-
}, {});
|
|
196
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { isObject } from "lodash";
|
|
2
|
-
import { BASE_RETRY } from "../../defaults";
|
|
3
|
-
import type { GitlabJobDef } from "../../types";
|
|
4
|
-
import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
|
|
5
|
-
const getJobName = (need: CatladderJobNeed) =>
|
|
6
|
-
isObject(need) ? need.job : need;
|
|
7
|
-
|
|
8
|
-
export const makeGitlabJob = ({
|
|
9
|
-
envMode,
|
|
10
|
-
needsStages,
|
|
11
|
-
needsOtherComponent,
|
|
12
|
-
name,
|
|
13
|
-
needs,
|
|
14
|
-
...rest
|
|
15
|
-
}: CatladderJob<string>): GitlabJobDef => {
|
|
16
|
-
return {
|
|
17
|
-
...rest,
|
|
18
|
-
// sort in a predictable manner for snapshot tests
|
|
19
|
-
needs: needs
|
|
20
|
-
? [...needs].sort((a, b) => getJobName(a).localeCompare(getJobName(b)))
|
|
21
|
-
: undefined,
|
|
22
|
-
retry: BASE_RETRY,
|
|
23
|
-
interruptible: true,
|
|
24
|
-
};
|
|
25
|
-
};
|