@catladder/pipeline 1.94.2 โ 1.96.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/custom/index.js +2 -1
- package/dist/build/custom/testJob.d.ts +3 -0
- package/dist/build/custom/testJob.js +95 -0
- package/dist/build/types.d.ts +22 -1
- package/dist/bundles/catladder-gitlab/index.js +2 -2
- package/dist/constants.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/examples/__snapshots__/custom-build-job-with-tests.ts.snap +1358 -0
- package/examples/custom-build-job-with-tests.ts +40 -0
- package/package.json +1 -1
- package/src/build/custom/index.ts +2 -1
- package/src/build/custom/testJob.ts +66 -0
- package/src/build/types.ts +28 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const config: Config = {
|
|
5
|
+
appName: "test-app",
|
|
6
|
+
customerName: "pan",
|
|
7
|
+
components: {
|
|
8
|
+
www: {
|
|
9
|
+
dir: "www",
|
|
10
|
+
build: {
|
|
11
|
+
type: "custom",
|
|
12
|
+
jobImage: "foo",
|
|
13
|
+
docker: {
|
|
14
|
+
type: "nginx",
|
|
15
|
+
},
|
|
16
|
+
lint: {
|
|
17
|
+
command: "lint",
|
|
18
|
+
jobImage: "lint-image",
|
|
19
|
+
},
|
|
20
|
+
test: {
|
|
21
|
+
command: "test",
|
|
22
|
+
jobImage: "test-image",
|
|
23
|
+
},
|
|
24
|
+
audit: {
|
|
25
|
+
command: "audit",
|
|
26
|
+
jobImage: "audit-image",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
deploy: {
|
|
30
|
+
type: "google-cloudrun",
|
|
31
|
+
projectId: "asdf",
|
|
32
|
+
region: "asia-east1",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
it("matches snapshot", async () => {
|
|
39
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
40
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Context } from "../../types/context";
|
|
2
2
|
import type { CatladderJob } from "../../types/jobs";
|
|
3
3
|
import { createCustomBuildJobs } from "./buildJob";
|
|
4
|
+
import { createCustomTestJobs } from "./testJob";
|
|
4
5
|
|
|
5
6
|
export const createCustomJobs = (context: Context): CatladderJob[] => {
|
|
6
|
-
return [...createCustomBuildJobs(context)];
|
|
7
|
+
return [...createCustomTestJobs(context), ...createCustomBuildJobs(context)];
|
|
7
8
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Context } from "../../types/context";
|
|
2
|
+
import type { CatladderJob } from "../../types/jobs";
|
|
3
|
+
import { ensureArray, notNil } from "../../utils";
|
|
4
|
+
import { isOfBuildType } from "../types";
|
|
5
|
+
|
|
6
|
+
const RUNNER_CUSTOM_TEST_VARIABLES = {
|
|
7
|
+
KUBERNETES_CPU_REQUEST: "0.5",
|
|
8
|
+
KUBERNETES_CPU_LIMIT: "2",
|
|
9
|
+
KUBERNETES_MEMORY_REQUEST: "2Gi",
|
|
10
|
+
KUBERNETES_MEMORY_LIMIT: "4Gi",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const createCustomTestJobs = (context: Context): CatladderJob[] => {
|
|
14
|
+
// don't run tests after release
|
|
15
|
+
if (context.commitInfo?.trigger === "taggedRelease") {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const buildConfig = context.componentConfig.build;
|
|
20
|
+
|
|
21
|
+
if (!isOfBuildType(buildConfig, "custom")) {
|
|
22
|
+
throw new Error("deploy config is not custom");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const base: Omit<CatladderJob, "script" | "name"> = {
|
|
26
|
+
variables: {
|
|
27
|
+
APP_PATH: context.componentConfig.dir,
|
|
28
|
+
...RUNNER_CUSTOM_TEST_VARIABLES,
|
|
29
|
+
...(buildConfig.extraVars ?? {}),
|
|
30
|
+
},
|
|
31
|
+
cache: buildConfig.jobCache,
|
|
32
|
+
stage: "test",
|
|
33
|
+
needs: [],
|
|
34
|
+
envMode: "none",
|
|
35
|
+
};
|
|
36
|
+
const auditJob: CatladderJob | null = buildConfig.audit
|
|
37
|
+
? {
|
|
38
|
+
name: "๐ก audit",
|
|
39
|
+
...base,
|
|
40
|
+
image: buildConfig.audit?.jobImage ?? buildConfig.jobImage,
|
|
41
|
+
cache: undefined,
|
|
42
|
+
script: [...(ensureArray(buildConfig.audit?.command) ?? [])],
|
|
43
|
+
allow_failure: true,
|
|
44
|
+
}
|
|
45
|
+
: null;
|
|
46
|
+
|
|
47
|
+
const lintJob: CatladderJob | null = buildConfig.lint
|
|
48
|
+
? {
|
|
49
|
+
name: "๐ฎ lint",
|
|
50
|
+
|
|
51
|
+
...base,
|
|
52
|
+
image: buildConfig.lint?.jobImage ?? buildConfig.jobImage,
|
|
53
|
+
script: [...(ensureArray(buildConfig.lint?.command) ?? [])],
|
|
54
|
+
}
|
|
55
|
+
: null;
|
|
56
|
+
const testJob: CatladderJob | null = buildConfig.test
|
|
57
|
+
? {
|
|
58
|
+
name: "๐งช test",
|
|
59
|
+
|
|
60
|
+
...base,
|
|
61
|
+
image: buildConfig.test?.jobImage ?? buildConfig.jobImage,
|
|
62
|
+
script: [...(ensureArray(buildConfig.test?.command) ?? [])],
|
|
63
|
+
}
|
|
64
|
+
: null;
|
|
65
|
+
return [auditJob, lintJob, testJob].filter(notNil);
|
|
66
|
+
};
|
package/src/build/types.ts
CHANGED
|
@@ -111,7 +111,10 @@ export type BuildConfigCustomDocker = BuildConfigBase["docker"] &
|
|
|
111
111
|
}
|
|
112
112
|
);
|
|
113
113
|
|
|
114
|
-
export type BuildConfigCustom =
|
|
114
|
+
export type BuildConfigCustom = Omit<
|
|
115
|
+
BuildConfigBase,
|
|
116
|
+
"lint" | "test" | "audit"
|
|
117
|
+
> & {
|
|
115
118
|
type: "custom";
|
|
116
119
|
jobImage: string;
|
|
117
120
|
jobServices?: GitlabJobService[];
|
|
@@ -122,6 +125,30 @@ export type BuildConfigCustom = BuildConfigBase & {
|
|
|
122
125
|
* customize cache for the job
|
|
123
126
|
*/
|
|
124
127
|
jobCache?: CatladderJob["cache"];
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* custom lint, disabled when not set
|
|
131
|
+
*/
|
|
132
|
+
lint?: {
|
|
133
|
+
command?: string | string[];
|
|
134
|
+
jobImage?: GitlabJobImage;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* custom test, disabled when not set
|
|
139
|
+
*/
|
|
140
|
+
test?: {
|
|
141
|
+
command?: string | string[];
|
|
142
|
+
jobImage?: GitlabJobImage;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* custom audit, disabled when not set
|
|
147
|
+
*/
|
|
148
|
+
audit?: {
|
|
149
|
+
command?: string | string[];
|
|
150
|
+
jobImage?: GitlabJobImage;
|
|
151
|
+
};
|
|
125
152
|
};
|
|
126
153
|
|
|
127
154
|
export type BuildConfigRails = BuildConfigBase & {
|