@catladder/pipeline 1.146.2 → 1.148.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.
- package/dist/build/base/createAppBuildJob.js +6 -6
- package/dist/build/base/writeBuildInfo.js +1 -1
- package/dist/build/base/writeDotEnv.js +1 -1
- package/dist/build/custom/__tests__/testJob.test.js +11 -14
- package/dist/build/custom/buildJob.js +5 -5
- package/dist/build/custom/testJob.js +5 -5
- package/dist/build/docker.d.ts +26 -9
- package/dist/build/docker.js +41 -20
- package/dist/build/node/buildJob.js +8 -8
- package/dist/build/node/cache.js +1 -1
- package/dist/build/node/meteor.js +6 -6
- package/dist/build/node/testJob.js +11 -11
- package/dist/build/rails/build.js +3 -3
- package/dist/build/rails/test.js +4 -4
- package/dist/build/sbom.js +2 -2
- package/dist/build/types.d.ts +34 -26
- package/dist/bundles/catladder-gitlab/index.js +2 -2
- package/dist/constants.js +1 -1
- package/dist/context/getLabels.js +1 -1
- package/dist/context/index.js +34 -12
- package/dist/deploy/base/deploy.js +9 -8
- package/dist/deploy/cloudRun/artifactsRegistry.d.ts +1 -5
- package/dist/deploy/cloudRun/artifactsRegistry.js +8 -9
- package/dist/deploy/cloudRun/cloudRunRevisions.js +4 -5
- package/dist/deploy/cloudRun/createJobs/cloudRunServices.js +1 -1
- package/dist/deploy/cloudRun/createJobs/common.d.ts +4 -4
- package/dist/deploy/cloudRun/createJobs/common.js +2 -1
- package/dist/deploy/cloudRun/createJobs/index.js +2 -4
- package/dist/deploy/custom/deployJob.js +7 -10
- package/dist/deploy/dockerTag/deployJob.js +3 -5
- package/dist/deploy/kubernetes/cloudSql/index.js +11 -9
- package/dist/deploy/kubernetes/deployJob.js +4 -7
- package/dist/deploy/kubernetes/kubeEnv.js +2 -1
- package/dist/deploy/kubernetes/kubeValues.js +10 -10
- package/dist/deploy/kubernetes/mongodb.js +11 -11
- package/dist/deploy/sbom.js +1 -1
- package/dist/deploy/types/index.d.ts +1 -1
- package/dist/deploy/types/index.js +1 -1
- package/dist/deploy/utils.js +2 -1
- package/dist/pipeline/createJobsForComponent.js +5 -5
- package/dist/pipeline/generatePipelineFiles.js +40 -9
- package/dist/pipeline/gitlab/createGitlabJobs.js +2 -9
- package/dist/pipeline/gitlab/sortGitLabJobDefProps.d.ts +7 -0
- package/dist/pipeline/gitlab/sortGitLabJobDefProps.js +27 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/context.d.ts +13 -1
- package/dist/utils/removeUndefined.d.ts +1 -0
- package/dist/utils/removeUndefined.js +36 -0
- package/examples/__snapshots__/cloud-run-storybook.ts.snap +1687 -0
- package/examples/__snapshots__/cloud-run-with-ngnix.ts.snap +1971 -0
- package/examples/cloud-run-storybook.ts +24 -0
- package/examples/cloud-run-with-ngnix.ts +24 -0
- package/package.json +1 -1
- package/src/build/base/createAppBuildJob.ts +7 -7
- package/src/build/base/writeBuildInfo.ts +1 -1
- package/src/build/base/writeDotEnv.ts +1 -1
- package/src/build/custom/__tests__/testJob.test.ts +5 -8
- package/src/build/custom/buildJob.ts +6 -9
- package/src/build/custom/testJob.ts +5 -5
- package/src/build/docker.ts +68 -24
- package/src/build/node/buildJob.ts +12 -12
- package/src/build/node/cache.ts +1 -1
- package/src/build/node/meteor.ts +11 -17
- package/src/build/node/testJob.ts +14 -14
- package/src/build/rails/build.ts +3 -3
- package/src/build/rails/test.ts +4 -4
- package/src/build/sbom.ts +3 -3
- package/src/build/types.ts +53 -38
- package/src/context/getLabels.ts +1 -1
- package/src/context/index.ts +21 -5
- package/src/deploy/base/deploy.ts +8 -14
- package/src/deploy/cloudRun/artifactsRegistry.ts +5 -10
- package/src/deploy/cloudRun/cloudRunRevisions.ts +3 -5
- package/src/deploy/cloudRun/createJobs/cloudRunServices.ts +1 -1
- package/src/deploy/cloudRun/createJobs/common.ts +5 -5
- package/src/deploy/cloudRun/createJobs/index.ts +1 -4
- package/src/deploy/custom/deployJob.ts +4 -6
- package/src/deploy/dockerTag/deployJob.ts +2 -5
- package/src/deploy/kubernetes/cloudSql/index.ts +7 -4
- package/src/deploy/kubernetes/deployJob.ts +1 -4
- package/src/deploy/kubernetes/kubeEnv.ts +1 -1
- package/src/deploy/kubernetes/kubeValues.ts +3 -3
- package/src/deploy/kubernetes/mongodb.ts +6 -6
- package/src/deploy/sbom.ts +1 -2
- package/src/deploy/types/index.ts +2 -2
- package/src/deploy/utils.ts +1 -1
- package/src/pipeline/createJobsForComponent.ts +6 -10
- package/src/pipeline/generatePipelineFiles.ts +21 -8
- package/src/pipeline/gitlab/createGitlabJobs.ts +2 -7
- package/src/pipeline/gitlab/sortGitLabJobDefProps.ts +59 -0
- package/src/types/config.ts +3 -1
- package/src/types/context.ts +16 -1
- package/src/utils/removeUndefined.ts +4 -0
|
@@ -3,6 +3,7 @@ import { writeYamlfile } from "../utils/writeFiles";
|
|
|
3
3
|
import { createChildPipeline } from "./createChildPipeline";
|
|
4
4
|
import { createMainPipeline } from "./createMainPipeline";
|
|
5
5
|
import { getPipelineTriggerForGitlabChildPipeline } from "./gitlab/getPipelineTriggerForGitlabChildPipeline";
|
|
6
|
+
import { sortGitLabJobDefProps } from "./gitlab/sortGitLabJobDefProps";
|
|
6
7
|
export async function generatePipelineFiles<T extends PipelineType>(
|
|
7
8
|
config: Config,
|
|
8
9
|
pipelineType: T,
|
|
@@ -11,28 +12,40 @@ export async function generatePipelineFiles<T extends PipelineType>(
|
|
|
11
12
|
if (mode === "childpipeline") {
|
|
12
13
|
const trigger = getPipelineTriggerForGitlabChildPipeline();
|
|
13
14
|
|
|
14
|
-
const { jobs, image, stages, variables, workflow, ...
|
|
15
|
+
const { jobs, image, stages, variables, workflow, ...pipelineRest } =
|
|
15
16
|
await createChildPipeline(pipelineType, trigger, config);
|
|
16
|
-
|
|
17
|
+
const jobsWithSortedProps = Object.fromEntries(
|
|
18
|
+
Object.entries(jobs).map(([jobName, job]) => [
|
|
19
|
+
jobName,
|
|
20
|
+
sortGitLabJobDefProps(job),
|
|
21
|
+
]),
|
|
22
|
+
);
|
|
17
23
|
await writeYamlfile(`__pipeline.yml`, {
|
|
18
24
|
image,
|
|
19
25
|
stages,
|
|
20
26
|
variables,
|
|
21
27
|
workflow,
|
|
22
|
-
...
|
|
23
|
-
|
|
28
|
+
...pipelineRest,
|
|
29
|
+
// jobs need to be spread into main YAML, because GitLab pipeline YAML has no jobs key - jobs are top level with their key as their name
|
|
30
|
+
...jobsWithSortedProps,
|
|
24
31
|
});
|
|
25
32
|
} else {
|
|
26
|
-
const { jobs, image, stages, variables, workflow, ...
|
|
33
|
+
const { jobs, image, stages, variables, workflow, ...pipelineRest } =
|
|
27
34
|
await createMainPipeline(pipelineType, config);
|
|
28
|
-
|
|
35
|
+
const jobsWithSortedProps = Object.fromEntries(
|
|
36
|
+
Object.entries(jobs).map(([jobName, job]) => [
|
|
37
|
+
jobName,
|
|
38
|
+
sortGitLabJobDefProps(job),
|
|
39
|
+
]),
|
|
40
|
+
);
|
|
29
41
|
await writeYamlfile(`.gitlab-ci.yml`, {
|
|
30
42
|
image,
|
|
31
43
|
stages,
|
|
32
44
|
variables,
|
|
33
45
|
workflow,
|
|
34
|
-
...
|
|
35
|
-
|
|
46
|
+
...pipelineRest,
|
|
47
|
+
// jobs need to be spread into main YAML, because GitLab pipeline YAML has no jobs key - jobs are top level with their key as their name
|
|
48
|
+
...jobsWithSortedProps,
|
|
36
49
|
});
|
|
37
50
|
}
|
|
38
51
|
}
|
|
@@ -11,6 +11,7 @@ import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
|
|
|
11
11
|
import { notNil } from "../../utils";
|
|
12
12
|
import { collapseableSection } from "../../utils/gitlab";
|
|
13
13
|
import type { AllCatladderJobs } from "../createAllJobs";
|
|
14
|
+
import { removeUndefined } from "../../utils/removeUndefined";
|
|
14
15
|
|
|
15
16
|
export type AllGitlabJobs = {
|
|
16
17
|
name: string;
|
|
@@ -20,10 +21,6 @@ export type AllGitlabJobs = {
|
|
|
20
21
|
}[];
|
|
21
22
|
|
|
22
23
|
export const GITLAB_ENVIRONMENT_URL_VARIABLE = "CL_GITLAB_ENVIRONMENT_URL";
|
|
23
|
-
const removeUndefined = (obj: GitlabJobDef): GitlabJobDef =>
|
|
24
|
-
Object.fromEntries(
|
|
25
|
-
Object.entries(obj).filter(([, value]) => value !== undefined),
|
|
26
|
-
) as GitlabJobDef;
|
|
27
24
|
const getFullJobName = (
|
|
28
25
|
name: string,
|
|
29
26
|
componentName: string,
|
|
@@ -197,9 +194,7 @@ export const makeGitlabJob = (
|
|
|
197
194
|
allJobs,
|
|
198
195
|
);
|
|
199
196
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return [fullJobName, gitlabJob];
|
|
197
|
+
return [fullJobName, removeUndefined(modified)];
|
|
203
198
|
};
|
|
204
199
|
|
|
205
200
|
const addGitlabEnvironment = (
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { GitlabJobDef } from "../../types";
|
|
2
|
+
|
|
3
|
+
type GitlabJobDefKey = keyof GitlabJobDef;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The desired order of GitLab job definition keys.
|
|
7
|
+
*/
|
|
8
|
+
const jobDefOrder: GitlabJobDefKey[] = [
|
|
9
|
+
"stage",
|
|
10
|
+
"tags",
|
|
11
|
+
"image",
|
|
12
|
+
"services",
|
|
13
|
+
"variables",
|
|
14
|
+
"before_script",
|
|
15
|
+
"script",
|
|
16
|
+
"after_script",
|
|
17
|
+
"cache",
|
|
18
|
+
"coverage",
|
|
19
|
+
"environment",
|
|
20
|
+
"release",
|
|
21
|
+
"artifacts",
|
|
22
|
+
"rules",
|
|
23
|
+
"only",
|
|
24
|
+
"except",
|
|
25
|
+
"needs",
|
|
26
|
+
"dependencies",
|
|
27
|
+
"trigger",
|
|
28
|
+
"retry",
|
|
29
|
+
"interruptible",
|
|
30
|
+
"allow_failure",
|
|
31
|
+
"parallel",
|
|
32
|
+
"hooks",
|
|
33
|
+
"resource_group",
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const sortGitLabJobDefKeys = (jobDef: GitlabJobDef): GitlabJobDefKey[] =>
|
|
37
|
+
(Object.keys(jobDef) as GitlabJobDefKey[]).sort((a, b) =>
|
|
38
|
+
jobDefOrder.indexOf(a) === -1 && jobDefOrder.indexOf(b) === -1
|
|
39
|
+
? 0
|
|
40
|
+
: jobDefOrder.indexOf(a) === -1
|
|
41
|
+
? 1
|
|
42
|
+
: jobDefOrder.indexOf(b) === -1
|
|
43
|
+
? -1
|
|
44
|
+
: jobDefOrder.indexOf(a) - jobDefOrder.indexOf(b),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Sorts the properties of a GitLab job definition based on the desired order.
|
|
49
|
+
*
|
|
50
|
+
* This is only useful when generating a GitLab pipeline YAML file.
|
|
51
|
+
*/
|
|
52
|
+
export const sortGitLabJobDefProps = (jobDef: GitlabJobDef): GitlabJobDef =>
|
|
53
|
+
sortGitLabJobDefKeys(jobDef).reduce(
|
|
54
|
+
(acc, key) =>
|
|
55
|
+
jobDef[key] !== undefined
|
|
56
|
+
? Object.assign(acc, { [key]: jobDef[key] })
|
|
57
|
+
: acc,
|
|
58
|
+
{} as GitlabJobDef,
|
|
59
|
+
);
|
package/src/types/config.ts
CHANGED
|
@@ -151,7 +151,9 @@ export type ComponentConfig<C extends ConfigProps = never> = {
|
|
|
151
151
|
* to let us know about why you need to use custom jobs.
|
|
152
152
|
* This feedback will help us to generalize use cases
|
|
153
153
|
*/
|
|
154
|
-
customJobs?:
|
|
154
|
+
customJobs?:
|
|
155
|
+
| CatladderJob[]
|
|
156
|
+
| ((context: Omit<ComponentContext, "customJobs">) => CatladderJob[]);
|
|
155
157
|
|
|
156
158
|
/**
|
|
157
159
|
* whether to create a .env
|
package/src/types/context.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { StringOrBashExpression } from "../bash/BashExpression";
|
|
2
2
|
import type { BuildConfig } from "../build";
|
|
3
3
|
import type { PredefinedVariables, SecretEnvVar } from "../context";
|
|
4
|
+
import type { DeployConfig } from "../deploy";
|
|
4
5
|
import type {
|
|
5
6
|
PipelineTrigger,
|
|
6
7
|
ComponentConfig,
|
|
@@ -89,10 +90,22 @@ export type BuildContext = {
|
|
|
89
90
|
packageManagerInfo?: PackageManagerInfo;
|
|
90
91
|
config: BuildConfig;
|
|
91
92
|
};
|
|
93
|
+
|
|
94
|
+
export type DeployContext = {
|
|
95
|
+
config: DeployConfig;
|
|
96
|
+
};
|
|
92
97
|
export type ComponentContext = {
|
|
93
98
|
componentName: string;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* the merged component config.
|
|
102
|
+
*
|
|
103
|
+
* use build.config and deploy.config instead if you need something from there
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
94
106
|
componentConfig: ComponentConfig;
|
|
95
|
-
|
|
107
|
+
build: BuildContext;
|
|
108
|
+
deploy?: DeployContext | null;
|
|
96
109
|
fullConfig: Config;
|
|
97
110
|
environment: Environment;
|
|
98
111
|
|
|
@@ -102,6 +115,8 @@ export type ComponentContext = {
|
|
|
102
115
|
* @deprecated use buildContext.packageManagerInfo instead
|
|
103
116
|
*/
|
|
104
117
|
packageManagerInfo?: PackageManagerInfo;
|
|
118
|
+
|
|
119
|
+
customJobs?: CatladderJob[];
|
|
105
120
|
};
|
|
106
121
|
|
|
107
122
|
/**
|