@catladder/pipeline 1.12.0 → 1.15.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.
Files changed (57) hide show
  1. package/dist/build/base/createBuildJob.d.ts +3 -2
  2. package/dist/build/base/createBuildJob.js +11 -17
  3. package/dist/build/docker.d.ts +25 -3
  4. package/dist/build/docker.js +46 -32
  5. package/dist/build/index.d.ts +2 -2
  6. package/dist/build/node/buildJob.d.ts +2 -2
  7. package/dist/build/node/buildJob.js +1 -1
  8. package/dist/build/node/index.d.ts +4 -4
  9. package/dist/build/node/meteor.d.ts +2 -2
  10. package/dist/build/node/meteor.js +1 -1
  11. package/dist/build/node/testJob.d.ts +2 -2
  12. package/dist/build/node/testJob.js +20 -29
  13. package/dist/build/tests/storybook.test.js +10 -23
  14. package/dist/catladder-gitlab.js +33 -2
  15. package/dist/constants.js +1 -1
  16. package/dist/deploy/base.d.ts +3 -4
  17. package/dist/deploy/base.js +27 -33
  18. package/dist/deploy/index.d.ts +2 -2
  19. package/dist/deploy/kubernetes/deployJob.d.ts +2 -2
  20. package/dist/deploy/kubernetes/deployJob.js +32 -38
  21. package/dist/pipeline/createChildPipeline.d.ts +2 -11
  22. package/dist/pipeline/createChildPipeline.js +24 -18
  23. package/dist/pipeline/createChildPipeline.test.js +3 -14
  24. package/dist/pipeline/createJobs.d.ts +2 -2
  25. package/dist/pipeline/createJobs.js +24 -18
  26. package/dist/pipeline/gitlab/makeGitlabJob.d.ts +8 -0
  27. package/dist/pipeline/gitlab/makeGitlabJob.js +45 -0
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/dist/types/gitlab-types.d.ts +10 -22
  30. package/dist/types/gitlab-types.js +1 -3
  31. package/dist/types/index.d.ts +2 -1
  32. package/dist/types/index.js +3 -1
  33. package/dist/types/jobs.d.ts +75 -0
  34. package/dist/types/jobs.js +5 -0
  35. package/dist/types/pipeline.d.ts +4 -0
  36. package/dist/types/pipeline.js +3 -0
  37. package/package.json +1 -1
  38. package/src/build/base/createBuildJob.ts +28 -32
  39. package/src/build/docker.ts +66 -52
  40. package/src/build/index.ts +3 -2
  41. package/src/build/node/buildJob.ts +5 -5
  42. package/src/build/node/index.ts +4 -4
  43. package/src/build/node/meteor.ts +7 -9
  44. package/src/build/node/testJob.ts +31 -40
  45. package/src/build/tests/storybook.test.ts +4 -2
  46. package/src/catladder-gitlab.ts +9 -5
  47. package/src/deploy/base.ts +40 -45
  48. package/src/deploy/index.ts +2 -2
  49. package/src/deploy/kubernetes/deployJob.ts +43 -48
  50. package/src/pipeline/createChildPipeline.test.ts +2 -1
  51. package/src/pipeline/createChildPipeline.ts +23 -21
  52. package/src/pipeline/createJobs.ts +47 -38
  53. package/src/pipeline/gitlab/makeGitlabJob.ts +16 -0
  54. package/src/types/gitlab-types.ts +10 -30
  55. package/src/types/index.ts +1 -0
  56. package/src/types/jobs.ts +88 -0
  57. package/src/types/pipeline.ts +11 -0
@@ -1,5 +1,6 @@
1
1
  import { Context } from "../types/context";
2
- import { GitlabJobs } from "../types/gitlab-types";
2
+
3
+ import { CatladderJob } from "../types/jobs";
3
4
  import { createNodeJobs, createStorybookJobs, createMeteorJobs } from "./node";
4
5
 
5
6
  import { BuildConfig } from "./types";
@@ -8,7 +9,7 @@ export * from "./node";
8
9
 
9
10
  export type BuildTypes = {
10
11
  [type in BuildConfig["type"]]: {
11
- jobs: (context: Context) => GitlabJobs;
12
+ jobs: (context: Context) => CatladderJob[];
12
13
  defaults: () => Partial<Extract<BuildConfig, { type: type }>>;
13
14
  };
14
15
  };
@@ -1,16 +1,16 @@
1
1
  import { Context } from "../../types/context";
2
- import { GitlabJob, GitlabJobs } from "../../types/gitlab-types";
3
2
  import { ensureArray } from "../../utils";
4
3
  import { APP_BUILD_JOB_NAME } from "../base/constants";
5
4
  import { createBuildJob } from "../base/createBuildJob";
6
- import { createDockerBuildJob } from "../docker";
5
+ import { createDockerBuildJobDefault } from "../docker";
7
6
  import { join } from "path";
8
7
  import { isOfBuildType } from "../types";
9
8
  import { getNextCache, getNodeCache, getYarnCache } from "./cache";
10
9
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
11
10
  import { getYarnInstall, getYarnInstallCommand } from "./yarn";
11
+ import { CatladderJob } from "../../types/jobs";
12
12
 
13
- export const createNodeBuildJobs = (context: Context): GitlabJobs => {
13
+ export const createNodeBuildJobs = (context: Context): CatladderJob[] => {
14
14
  const buildConfig = context.componentConfig.build;
15
15
 
16
16
  if (!isOfBuildType(buildConfig, "node", "node-static", "storybook")) {
@@ -18,7 +18,7 @@ export const createNodeBuildJobs = (context: Context): GitlabJobs => {
18
18
  }
19
19
 
20
20
  const yarnInstall = getYarnInstall(context);
21
- const appBuildJob: GitlabJob | null =
21
+ const appBuildJob: CatladderJob | null =
22
22
  buildConfig.buildCommand !== null
23
23
  ? createBuildJob(context, {
24
24
  variables: {
@@ -43,7 +43,7 @@ export const createNodeBuildJobs = (context: Context): GitlabJobs => {
43
43
  : null;
44
44
  return [
45
45
  ...(appBuildJob ? [appBuildJob] : []),
46
- createDockerBuildJob(context, {
46
+ createDockerBuildJobDefault(context, {
47
47
  script: [
48
48
  buildConfig.type === "node-static" || buildConfig.type === "storybook"
49
49
  ? "ensureNginxDockerfile"
@@ -1,17 +1,17 @@
1
1
  import type { Context } from "../../types/context";
2
- import type { GitlabJobs } from "../../types/gitlab-types";
2
+ import { CatladderJob } from "../../types/jobs";
3
3
  import { createNodeBuildJobs } from "./buildJob";
4
4
  import { createMeteorBuildJobs } from "./meteor";
5
5
  import { createNodeTestJobs } from "./testJob";
6
6
 
7
- export const createNodeJobs = (context: Context): GitlabJobs => {
7
+ export const createNodeJobs = (context: Context): CatladderJob[] => {
8
8
  return [...createNodeTestJobs(context), ...createNodeBuildJobs(context)];
9
9
  };
10
10
 
11
- export const createStorybookJobs = (context: Context): GitlabJobs => {
11
+ export const createStorybookJobs = (context: Context): CatladderJob[] => {
12
12
  return [...createNodeBuildJobs(context)];
13
13
  };
14
14
 
15
- export const createMeteorJobs = (context: Context): GitlabJobs => {
15
+ export const createMeteorJobs = (context: Context): CatladderJob[] => {
16
16
  return [...createNodeTestJobs(context), ...createMeteorBuildJobs(context)];
17
17
  };
@@ -1,15 +1,13 @@
1
1
  import { join } from "path";
2
2
  import { getRunnerImage } from "../../runner";
3
+ import { GitlabJobCache } from "../../types";
3
4
  import type { Context } from "../../types/context";
4
- import type {
5
- GitlabJob,
6
- GitlabJobCache,
7
- GitlabJobs,
8
- } from "../../types/gitlab-types";
5
+
6
+ import { CatladderJob } from "../../types/jobs";
9
7
 
10
8
  import { APP_BUILD_JOB_NAME } from "../base/constants";
11
9
  import { createBuildJob } from "../base/createBuildJob";
12
- import { createDockerBuildJob } from "../docker";
10
+ import { createDockerBuildJobDefault } from "../docker";
13
11
  import { isOfBuildType } from "../types";
14
12
  import { getNodeCache } from "./cache";
15
13
  import { getYarnInstall } from "./yarn";
@@ -29,7 +27,7 @@ const getMeteorCache = (context: Context): GitlabJobCache[] => [
29
27
  ],
30
28
  },
31
29
  ];
32
- export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
30
+ export const createMeteorBuildJobs = (context: Context): CatladderJob[] => {
33
31
  const buildConfig = context.componentConfig.build;
34
32
 
35
33
  if (!isOfBuildType(buildConfig, "meteor")) {
@@ -37,7 +35,7 @@ export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
37
35
  }
38
36
 
39
37
  const yarnInstall = getYarnInstall(context);
40
- const appBuildJob: GitlabJob | null =
38
+ const appBuildJob: CatladderJob | null =
41
39
  buildConfig.buildCommand !== null
42
40
  ? createBuildJob(context, {
43
41
  cache: [...getNodeCache(context), ...getMeteorCache(context)],
@@ -63,7 +61,7 @@ export const createMeteorBuildJobs = (context: Context): GitlabJobs => {
63
61
  : null;
64
62
  return [
65
63
  ...(appBuildJob ? [appBuildJob] : []),
66
- createDockerBuildJob(context, {
64
+ createDockerBuildJobDefault(context, {
67
65
  script: ["ensureMeteorDockerfile"],
68
66
  needs: appBuildJob ? [APP_BUILD_JOB_NAME] : [],
69
67
  }),
@@ -1,12 +1,11 @@
1
- import { BASE_RETRY } from "../../defaults";
2
1
  import { Context } from "../../types/context";
3
- import { GitlabJob, GitlabJobDef, GitlabJobs } from "../../types/gitlab-types";
2
+ import { CatladderJob } from "../../types/jobs";
4
3
  import { ensureArray, notNil } from "../../utils";
5
4
  import { getNodeCache } from "./cache";
6
5
  import { NODE_RUNNER_BUILD_VARIABLES } from "./constants";
7
6
  import { getYarnInstall } from "./yarn";
8
7
 
9
- export const createNodeTestJobs = (context: Context): GitlabJobs => {
8
+ export const createNodeTestJobs = (context: Context): CatladderJob[] => {
10
9
  // don't run tests after release
11
10
  if (context.commitInfo?.trigger === "taggedRelease") {
12
11
  return [];
@@ -14,66 +13,58 @@ export const createNodeTestJobs = (context: Context): GitlabJobs => {
14
13
 
15
14
  const buildConfig = context.componentConfig.build;
16
15
 
17
- const base: Omit<GitlabJobDef, "script"> = {
16
+ const base: Omit<CatladderJob, "script" | "name"> = {
18
17
  variables: {
19
18
  APP_PATH: context.componentConfig.dir,
20
19
  ...NODE_RUNNER_BUILD_VARIABLES,
21
20
  ...(buildConfig.extraVars ?? {}),
22
21
  },
23
-
24
22
  stage: "test",
25
- interruptible: true,
26
23
  needs: [],
27
- retry: BASE_RETRY,
24
+ envMode: "none",
28
25
  };
29
26
  const yarnInstall = getYarnInstall(context);
30
- const auditJob: GitlabJob | null =
27
+ const auditJob: CatladderJob | null =
31
28
  buildConfig.audit !== false
32
29
  ? {
33
30
  name: "🛡 audit",
34
- envMode: "none",
35
- job: {
36
- ...base,
37
- cache: undefined, // audit does not need yarn install and no cache
38
- script: [
39
- `cd ${context.componentConfig.dir}`,
40
- ...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
41
- ],
42
- allow_failure: true,
43
- },
31
+
32
+ ...base,
33
+ cache: undefined, // audit does not need yarn install and no cache
34
+ script: [
35
+ `cd ${context.componentConfig.dir}`,
36
+ ...(ensureArray(buildConfig.audit?.command) ?? ["yarn audit"]),
37
+ ],
38
+ allow_failure: true,
44
39
  }
45
40
  : null;
46
41
 
47
- const lintJob: GitlabJob | null =
42
+ const lintJob: CatladderJob | null =
48
43
  buildConfig.lint !== false
49
44
  ? {
50
45
  name: "👮 lint",
51
- envMode: "none",
52
- job: {
53
- ...base,
54
- cache: getNodeCache(context),
55
- script: [
56
- `cd ${context.componentConfig.dir}`,
57
- ...yarnInstall,
58
- ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
59
- ],
60
- },
46
+
47
+ ...base,
48
+ cache: getNodeCache(context),
49
+ script: [
50
+ `cd ${context.componentConfig.dir}`,
51
+ ...yarnInstall,
52
+ ...(ensureArray(buildConfig.lint?.command) ?? ["yarn lint"]),
53
+ ],
61
54
  }
62
55
  : null;
63
- const testJob: GitlabJob | null =
56
+ const testJob: CatladderJob | null =
64
57
  buildConfig.test !== false
65
58
  ? {
66
59
  name: "🧪 test",
67
- envMode: "none",
68
- job: {
69
- ...base,
70
- cache: getNodeCache(context),
71
- script: [
72
- `cd ${context.componentConfig.dir}`,
73
- ...yarnInstall,
74
- ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
75
- ],
76
- },
60
+
61
+ ...base,
62
+ cache: getNodeCache(context),
63
+ script: [
64
+ `cd ${context.componentConfig.dir}`,
65
+ ...yarnInstall,
66
+ ...(ensureArray(buildConfig.test?.command) ?? ["yarn test"]),
67
+ ],
77
68
  }
78
69
  : null;
79
70
  return [auditJob, lintJob, testJob].filter(notNil);
@@ -26,7 +26,8 @@ describe("storybook build", () => {
26
26
  };
27
27
 
28
28
  it("creates a pipeline for storybook that does not contain test stages", async () => {
29
- const { image, stages, workflow, ...jobs } = await createChildPipeline(
29
+ const { jobs } = await createChildPipeline(
30
+ "gitlab",
30
31
  "mainBranch",
31
32
  config
32
33
  );
@@ -40,7 +41,8 @@ describe("storybook build", () => {
40
41
  });
41
42
 
42
43
  it("runs build and renames folder", async () => {
43
- const { image, stages, workflow, ...jobs } = await createChildPipeline(
44
+ const { jobs } = await createChildPipeline(
45
+ "gitlab",
44
46
  "mainBranch",
45
47
  config
46
48
  );
@@ -1,4 +1,5 @@
1
1
  import { writeFileSync } from "fs";
2
+ import { dump } from "js-yaml";
2
3
  import { readConfigSync } from "./config";
3
4
  import { PIPELINE_IMAGE_TAG } from "./constants";
4
5
  import { createChildPipeline } from "./pipeline";
@@ -32,11 +33,14 @@ if (trigger) {
32
33
  if (!config) {
33
34
  throw new Error("no catladder config found");
34
35
  }
35
- createChildPipeline(trigger, config).then((mainPipeline) => {
36
- writeFileSync(`__pipeline.yml`, JSON.stringify(mainPipeline, null, 2), {
37
- encoding: "utf-8",
38
- });
39
- });
36
+ createChildPipeline("gitlab", trigger, config).then(
37
+ ({ jobs, ...mainPipeline }) => {
38
+ // need to spread out the jobs
39
+ writeFileSync(`__pipeline.yml`, dump({ ...jobs, ...mainPipeline }), {
40
+ encoding: "utf-8",
41
+ });
42
+ }
43
+ );
40
44
  } else {
41
45
  throw new Error(
42
46
  "no matching trigger: " +
@@ -1,4 +1,5 @@
1
- import { GitlabJob, Context, GitlabJobDef } from "../types";
1
+ import { Context } from "../types";
2
+ import { CatladderJob } from "../types/jobs";
2
3
 
3
4
  export const DEPLOY_JOB_NAME = "🚀 Deploy";
4
5
  export const STOP_JOB_NAME = "🛑 Stop ⚠️";
@@ -9,9 +10,7 @@ const DEPLOY_RUNNER_VARIABLES = {
9
10
  KUBERNETES_MEMORY_REQUEST: "200Mi",
10
11
  KUBERNETES_MEMORY_LIMIT: "500Mi",
11
12
  };
12
- type JobWithoutScript = Omit<GitlabJob, "job"> & {
13
- job: Omit<GitlabJobDef, "script">;
14
- };
13
+ type JobWithoutScript = Omit<CatladderJob, "script">;
15
14
  export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
16
15
  const environment = {
17
16
  name: context.environment.fullName,
@@ -45,26 +44,24 @@ export const getBaseDeploymentJob = (context: Context): JobWithoutScript => {
45
44
  artifacts: false,
46
45
  },
47
46
  ], // workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220758
48
- job: {
49
- rules: [
50
- autoDeploy
51
- ? {
52
- when: "on_success",
53
- }
54
- : {
55
- when: "manual",
56
- },
57
- ],
58
- stage: "deploy",
59
- dependencies: [],
60
- variables: {
61
- ...DEPLOY_RUNNER_VARIABLES,
62
- },
63
- environment: {
64
- ...environment,
65
- on_stop: STOP_JOB_NAME,
66
- auto_stop_in: autoStop,
67
- },
47
+
48
+ rules: [
49
+ autoDeploy
50
+ ? {
51
+ when: "on_success",
52
+ }
53
+ : {
54
+ when: "manual",
55
+ },
56
+ ],
57
+ stage: "deploy",
58
+ variables: {
59
+ ...DEPLOY_RUNNER_VARIABLES,
60
+ },
61
+ environment: {
62
+ ...environment,
63
+ on_stop: STOP_JOB_NAME,
64
+ auto_stop_in: autoStop,
68
65
  },
69
66
  };
70
67
  };
@@ -79,29 +76,27 @@ export const getBaseDeploymentStopJob = (
79
76
  return {
80
77
  name: STOP_JOB_NAME,
81
78
  envMode: "stagePerEnv", // makes it easier to run manual tasks er env
82
- job: {
83
- needs: [DEPLOY_JOB_NAME],
84
- rules: [
85
- {
86
- if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
87
- when: "on_success",
88
- allow_failure: true,
89
- },
90
- {
91
- when: "manual",
92
- allow_failure: true,
93
- },
94
- ],
95
- variables: {
96
- ...DEPLOY_RUNNER_VARIABLES,
97
- GIT_STRATEGY: "none",
79
+
80
+ needs: [DEPLOY_JOB_NAME],
81
+ rules: [
82
+ {
83
+ if: "$CI_COMMIT_BRANCH =~ /^[0-9]+\\.([0-9]+|x)\\.x$/", // automatic on hotfix branches
84
+ when: "on_success",
85
+ allow_failure: true,
98
86
  },
99
- stage: "stop",
100
- dependencies: [],
101
- environment: {
102
- ...environment,
103
- action: "stop",
87
+ {
88
+ when: "manual",
89
+ allow_failure: true,
104
90
  },
91
+ ],
92
+ variables: {
93
+ ...DEPLOY_RUNNER_VARIABLES,
94
+ GIT_STRATEGY: "none",
95
+ },
96
+ stage: "stop",
97
+ environment: {
98
+ ...environment,
99
+ action: "stop",
105
100
  },
106
101
  };
107
102
  };
@@ -1,5 +1,5 @@
1
- import { GitlabJobs } from "../types/gitlab-types";
2
1
  import { Context } from "../types/context";
2
+ import { CatladderJob } from "../types/jobs";
3
3
  import { createKubernetesDeployJobs } from "./kubernetes";
4
4
  import { DeployConfig } from "./types";
5
5
  export * from "./kubernetes";
@@ -7,7 +7,7 @@ export * from "./types";
7
7
  export * from "./utils";
8
8
  export type DeployTypes = {
9
9
  [type in DeployConfig["type"]]: {
10
- jobs: (context: Context) => GitlabJobs;
10
+ jobs: (context: Context) => CatladderJob[];
11
11
  defaults: () => Partial<Extract<DeployConfig, { type: type }>>;
12
12
  };
13
13
  };
@@ -1,18 +1,19 @@
1
- import { GitlabJobs } from "../../types/gitlab-types";
2
- import { Context } from "../../types/context";
3
- import { isOfDeployType } from "../types";
4
- import { getRunnerImage } from "../../runner";
5
- import { getBaseDeploymentJob, getBaseDeploymentStopJob } from "../base";
6
- import { merge } from "lodash";
7
1
  import { dump } from "js-yaml";
8
- import { createMongodbBaseConfig } from "./mongodb";
9
- import { createCloudsqlBaseConfig } from "./cloudsql";
2
+ import { merge } from "lodash";
3
+ import { DeployConfigKubernetesValues } from "..";
10
4
  import { getSecretVarNameForContext } from "../..";
5
+ import { getRunnerImage } from "../../runner";
6
+ import { Context } from "../../types/context";
7
+ import { CatladderJob } from "../../types/jobs";
11
8
  import { mergeWithMergingArrays } from "../../utils";
12
- import { DeployConfigKubernetesValues } from "..";
13
- import { PartialDeep } from "type-fest";
9
+ import { getBaseDeploymentJob, getBaseDeploymentStopJob } from "../base";
10
+ import { isOfDeployType } from "../types";
11
+ import { createCloudsqlBaseConfig } from "./cloudsql";
12
+ import { createMongodbBaseConfig } from "./mongodb";
14
13
 
15
- export const createKubernetesDeployJobs = (context: Context): GitlabJobs => {
14
+ export const createKubernetesDeployJobs = (
15
+ context: Context
16
+ ): CatladderJob[] => {
16
17
  const deployConfig = context.componentConfig.deploy;
17
18
  if (deployConfig === false) {
18
19
  return [];
@@ -91,28 +92,26 @@ export const createKubernetesDeployJobs = (context: Context): GitlabJobs => {
91
92
  namespace: context.environment.envVars.KUBE_NAMESPACE,
92
93
  };
93
94
  const shared = {
94
- job: {
95
- image: getRunnerImage("kubernetes"),
96
- variables: {
97
- ...context.environment.envVars,
98
- HELM_EXPERIMENTAL_OCI: "1",
99
- IMAGE_PULL_SECRET: `gitlab-registry-${context.componentName}`,
100
- KUBE_VALUES: dump(kubeValues, {
101
- lineWidth: -1,
102
- quotingType: "'",
103
- forceQuotes: true,
104
- }),
105
- HELM_GITLAB_CHART_NAME: "the-panter-chart",
106
- HELM_ARGS: [
107
- ...(deployConfig.debug ? ["--debug"] : []),
108
- ...(deployConfig.additionalHelmArgs ?? []),
109
- ].join(" "),
110
- COMPONENT_NAME: context.componentName,
111
- BUILD_ID: context.commitInfo?.buildId,
112
- // TODO: unify with docker build stage
113
- IMAGE_NAME: context.environment.shortName + "/" + context.componentName,
114
- IMAGE_TAG: "$CI_COMMIT_SHA",
115
- },
95
+ image: getRunnerImage("kubernetes"),
96
+ variables: {
97
+ ...context.environment.envVars,
98
+ HELM_EXPERIMENTAL_OCI: "1",
99
+ IMAGE_PULL_SECRET: `gitlab-registry-${context.componentName}`,
100
+ KUBE_VALUES: dump(kubeValues, {
101
+ lineWidth: -1,
102
+ quotingType: "'",
103
+ forceQuotes: true,
104
+ }),
105
+ HELM_GITLAB_CHART_NAME: "the-panter-chart",
106
+ HELM_ARGS: [
107
+ ...(deployConfig.debug ? ["--debug"] : []),
108
+ ...(deployConfig.additionalHelmArgs ?? []),
109
+ ].join(" "),
110
+ COMPONENT_NAME: context.componentName,
111
+ BUILD_ID: context.commitInfo?.buildId,
112
+ // TODO: unify with docker build stage
113
+ IMAGE_NAME: context.environment.shortName + "/" + context.componentName,
114
+ IMAGE_TAG: "$CI_COMMIT_SHA",
116
115
  },
117
116
  };
118
117
 
@@ -136,24 +135,20 @@ export const createKubernetesDeployJobs = (context: Context): GitlabJobs => {
136
135
  ];
137
136
  return [
138
137
  merge({}, baseDeploymentJob, shared, {
139
- job: {
140
- script: [
141
- ...connectContext,
142
- "kubernetesCreateSecret",
143
- "kubernetesDeploy",
144
- "echo deployment successful 😻",
145
- ],
146
- environment: {
147
- kubernetes: kubernetesEnvironment,
148
- },
138
+ script: [
139
+ ...connectContext,
140
+ "kubernetesCreateSecret",
141
+ "kubernetesDeploy",
142
+ "echo deployment successful 😻",
143
+ ],
144
+ environment: {
145
+ kubernetes: kubernetesEnvironment,
149
146
  },
150
147
  }),
151
148
  merge({}, baseStopJob, shared, {
152
- job: {
153
- script: [...connectContext, "kubernetesDelete"],
154
- environment: {
155
- kubernetes: kubernetesEnvironment,
156
- },
149
+ script: [...connectContext, "kubernetesDelete"],
150
+ environment: {
151
+ kubernetes: kubernetesEnvironment,
157
152
  },
158
153
  }),
159
154
  ];
@@ -26,7 +26,8 @@ describe("createChildPipeline", () => {
26
26
  };
27
27
 
28
28
  it("creates a pipeline for a single app on the main branch", async () => {
29
- const { image, stages, workflow, ...jobs } = await createChildPipeline(
29
+ const { image, jobs } = await createChildPipeline(
30
+ "gitlab",
30
31
  "mainBranch",
31
32
  config
32
33
  );
@@ -1,24 +1,25 @@
1
1
  import { getAllEnvsByTrigger, getAllEnvsInAllComponents } from "../config";
2
- import { createJobs } from "./createJobs";
3
2
  import { RULES_ALWAYS } from "../rules";
4
3
  import { getRunnerImage } from "../runner";
4
+ import { GitlabPipeline, Pipeline, PipelineJob, PipelineType } from "../types";
5
5
  import { Config, PipelineTrigger } from "../types/config";
6
- import { GitlabJobDef } from "../types/gitlab-types";
6
+ import { createJobs } from "./createJobs";
7
+
7
8
  const baseStages = ["setup", "test", "build", "deploy", "verify", "stop"];
8
- export const createChildPipeline = async (
9
+ export const createChildPipeline = async <T extends PipelineType>(
10
+ type: T,
9
11
  trigger: PipelineTrigger,
10
12
  config: Config
11
- ) => {
13
+ ): Promise<Pipeline<T>> => {
12
14
  const components = Object.keys(config.components);
13
15
 
14
16
  // 2. write the triggering pipeline
15
-
16
- const jobs = await components.reduce<Promise<Record<string, GitlabJobDef>>>(
17
+ const jobs = await components.reduce<Promise<Record<string, PipelineJob<T>>>>(
17
18
  async (acc, componentName) => {
18
19
  const envs = getAllEnvsByTrigger(config, componentName, trigger);
19
20
  return {
20
21
  ...(await acc),
21
- ...(await createJobs(envs, config, componentName, trigger)),
22
+ ...(await createJobs(type, envs, config, componentName, trigger)),
22
23
  };
23
24
  },
24
25
  Promise.resolve({})
@@ -37,18 +38,19 @@ export const createChildPipeline = async (
37
38
  ],
38
39
  []
39
40
  );
40
-
41
- const childPipeline = {
42
- image: getRunnerImage("jobs-default"), // default image
43
- variables: {
44
- FF_USE_FASTZIP: "true",
45
- },
46
- workflow: {
47
- rules: RULES_ALWAYS,
48
- },
49
- stages,
50
- ...jobs,
51
- };
52
-
53
- return childPipeline as typeof childPipeline & Record<string, GitlabJobDef>;
41
+ if (type === "gitlab") {
42
+ const pipeline: GitlabPipeline = {
43
+ image: getRunnerImage("jobs-default"), // default image
44
+ variables: {
45
+ FF_USE_FASTZIP: "true",
46
+ },
47
+ workflow: {
48
+ rules: RULES_ALWAYS,
49
+ },
50
+ stages,
51
+ jobs,
52
+ };
53
+ return pipeline as Pipeline<T>;
54
+ }
55
+ throw new Error(`${type} is not supported`);
54
56
  };