@catladder/pipeline 1.150.2 → 1.151.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.
@@ -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
- componentName: string;
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[componentName]?.[env]?.find(
42
- (j) => j.name === referencedJobName,
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
- componentName: string,
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
- context,
64
+
69
65
  variables,
70
66
  runnerVariables,
71
67
  when,
72
68
  ...job
73
- }: CatladderJobWithContext<string>,
69
+ }: CatladderJob<string>,
74
70
  allJobs: AllCatladderJobs,
75
71
  baseRules?: GitlabRule[],
76
72
  ): [fullName: string, job: GitlabJobDef] => {
77
- const stage = envMode === "stagePerEnv" ? `${job.stage} ${env}` : job.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[referencedComponentName]?.[env]
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(n, componentName, env, allJobs),
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 Object.keys(allJobs).flatMap((componentName) => {
259
- const componentJobs = allJobs[componentName];
260
- return Object.keys(componentJobs).flatMap((env) => {
261
- const jobs = componentJobs[env];
262
-
263
- return jobs.flatMap((job) => {
264
- const [fullJobName, gitlabJob] = makeGitlabJob(
265
- componentName,
266
- env,
267
- job,
268
- allJobs,
269
- baseRules,
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
  };
@@ -1,18 +1,23 @@
1
1
  import { RULES_MANUAL_RELEASE, RULES_RELEASE } from "../../rules";
2
2
  import { getRunnerImage } from "../../runner";
3
3
 
4
+ const EXPIRED_TOKEN_HELP =
5
+ "echo '👉 The project access token might be invald - run `project-renew-token` in catladder CLI to fix.'";
6
+
4
7
  export const getGitlabReleaseJobs = () => {
5
8
  return {
6
9
  ["create release"]: {
7
10
  stage: "release",
8
11
  image: getRunnerImage("semantic-release"),
9
12
  script: ["semanticRelease"],
13
+ after_script: [EXPIRED_TOKEN_HELP],
10
14
  rules: RULES_RELEASE,
11
15
  },
12
16
  ["⚠️ force create release"]: {
13
17
  stage: "release",
14
18
  image: getRunnerImage("semantic-release"),
15
19
  script: ["semanticRelease"],
20
+ after_script: [EXPIRED_TOKEN_HELP],
16
21
  needs: [],
17
22
  rules: RULES_MANUAL_RELEASE,
18
23
  },
@@ -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
- };