@catladder/cli 5.2.0 → 5.3.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 (88) hide show
  1. package/dist/apps/cli/src/commands/project/commandPortForward.js +1 -1
  2. package/dist/apps/cli/src/commands/project/commandPortForward.js.map +1 -1
  3. package/dist/apps/cli/src/commands/project/secrets/scope.js +25 -2
  4. package/dist/apps/cli/src/commands/project/secrets/scope.js.map +1 -1
  5. package/dist/apps/cli/src/config/getProjectConfig.js +4 -1
  6. package/dist/apps/cli/src/config/getProjectConfig.js.map +1 -1
  7. package/dist/apps/cli/src/secrets/github.js +4 -2
  8. package/dist/apps/cli/src/secrets/github.js.map +1 -1
  9. package/dist/bundles/catenv/index.js +390 -106
  10. package/dist/bundles/cli/index.js +420 -111
  11. package/dist/bundles/skills/catladder-config/SKILL.md +34 -2
  12. package/dist/bundles/skills/catladder-deploys/SKILL.md +5 -0
  13. package/dist/bundles/skills/catladder-pipelines/SKILL.md +10 -1
  14. package/dist/bundles/skills/catladder-secrets/SKILL.md +6 -0
  15. package/dist/packages/pipeline/src/backends/github/GithubBackend.js +23 -3
  16. package/dist/packages/pipeline/src/backends/github/GithubBackend.js.map +1 -1
  17. package/dist/packages/pipeline/src/backends/github/createGithubJobs.js +2 -2
  18. package/dist/packages/pipeline/src/backends/github/createGithubJobs.js.map +1 -1
  19. package/dist/packages/pipeline/src/backends/gitlab/GitlabBackend.js +18 -2
  20. package/dist/packages/pipeline/src/backends/gitlab/GitlabBackend.js.map +1 -1
  21. package/dist/packages/pipeline/src/backends/gitlab/createGitlabJobs.js +2 -2
  22. package/dist/packages/pipeline/src/backends/gitlab/createGitlabJobs.js.map +1 -1
  23. package/dist/packages/pipeline/src/backends/gitlab/createGitlabPipeline.d.ts +6 -1
  24. package/dist/packages/pipeline/src/backends/gitlab/createGitlabPipeline.js +8 -1
  25. package/dist/packages/pipeline/src/backends/gitlab/createGitlabPipeline.js.map +1 -1
  26. package/dist/packages/pipeline/src/config/configruedEnvs.d.ts +9 -2
  27. package/dist/packages/pipeline/src/config/configruedEnvs.js +54 -5
  28. package/dist/packages/pipeline/src/config/configruedEnvs.js.map +1 -1
  29. package/dist/packages/pipeline/src/context/createAllComponentsContext.d.ts +2 -2
  30. package/dist/packages/pipeline/src/context/createComponentContext.d.ts +2 -2
  31. package/dist/packages/pipeline/src/context/createWorkspaceContext.d.ts +2 -2
  32. package/dist/packages/pipeline/src/context/getEnvConfig.js +35 -19
  33. package/dist/packages/pipeline/src/context/getEnvConfig.js.map +1 -1
  34. package/dist/packages/pipeline/src/context/getEnvInherit.d.ts +20 -0
  35. package/dist/packages/pipeline/src/context/getEnvInherit.js +72 -0
  36. package/dist/packages/pipeline/src/context/getEnvInherit.js.map +1 -0
  37. package/dist/packages/pipeline/src/context/getEnvInstance.d.ts +4 -0
  38. package/dist/packages/pipeline/src/context/{getReviewSlug.js → getEnvInstance.js} +13 -9
  39. package/dist/packages/pipeline/src/context/getEnvInstance.js.map +1 -0
  40. package/dist/packages/pipeline/src/context/getEnvOn.d.ts +13 -0
  41. package/dist/packages/pipeline/src/context/getEnvOn.js +28 -0
  42. package/dist/packages/pipeline/src/context/getEnvOn.js.map +1 -0
  43. package/dist/packages/pipeline/src/context/getEnvType.d.ts +8 -2
  44. package/dist/packages/pipeline/src/context/getEnvType.js +27 -5
  45. package/dist/packages/pipeline/src/context/getEnvType.js.map +1 -1
  46. package/dist/packages/pipeline/src/context/getEnvironment.js +3 -0
  47. package/dist/packages/pipeline/src/context/getEnvironment.js.map +1 -1
  48. package/dist/packages/pipeline/src/context/getEnvironmentContext.js +18 -8
  49. package/dist/packages/pipeline/src/context/getEnvironmentContext.js.map +1 -1
  50. package/dist/packages/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
  51. package/dist/packages/pipeline/src/context/getEnvironmentVariables.js +4 -4
  52. package/dist/packages/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
  53. package/dist/packages/pipeline/src/context/index.d.ts +1 -0
  54. package/dist/packages/pipeline/src/context/index.js +1 -0
  55. package/dist/packages/pipeline/src/context/index.js.map +1 -1
  56. package/dist/packages/pipeline/src/deploy/base/deploy.js +11 -1
  57. package/dist/packages/pipeline/src/deploy/base/deploy.js.map +1 -1
  58. package/dist/packages/pipeline/src/deploy/cloudRun/artifactsRegistry.js +5 -4
  59. package/dist/packages/pipeline/src/deploy/cloudRun/artifactsRegistry.js.map +1 -1
  60. package/dist/packages/pipeline/src/deploy/cloudRun/cleanup.js +8 -2
  61. package/dist/packages/pipeline/src/deploy/cloudRun/cleanup.js.map +1 -1
  62. package/dist/packages/pipeline/src/deploy/cloudRun/index.js +2 -2
  63. package/dist/packages/pipeline/src/deploy/cloudRun/index.js.map +1 -1
  64. package/dist/packages/pipeline/src/deploy/cloudRun/utils/getServiceName.js +2 -2
  65. package/dist/packages/pipeline/src/deploy/cloudRun/utils/getServiceName.js.map +1 -1
  66. package/dist/packages/pipeline/src/deploy/kubernetes/index.js +3 -3
  67. package/dist/packages/pipeline/src/deploy/kubernetes/index.js.map +1 -1
  68. package/dist/packages/pipeline/src/deploy/pages/deployJob.js +3 -2
  69. package/dist/packages/pipeline/src/deploy/pages/deployJob.js.map +1 -1
  70. package/dist/packages/pipeline/src/deploy/types/googleCloudRun.d.ts +9 -0
  71. package/dist/packages/pipeline/src/types/config.d.ts +126 -9
  72. package/dist/packages/pipeline/src/types/config.js +11 -10
  73. package/dist/packages/pipeline/src/types/config.js.map +1 -1
  74. package/dist/packages/pipeline/src/types/context.d.ts +22 -3
  75. package/dist/packages/pipeline/src/types/context.js.map +1 -1
  76. package/dist/packages/pipeline/src/types/environmentContext.d.ts +29 -0
  77. package/dist/skills/catladder-config/SKILL.md +34 -2
  78. package/dist/skills/catladder-deploys/SKILL.md +5 -0
  79. package/dist/skills/catladder-pipelines/SKILL.md +10 -1
  80. package/dist/skills/catladder-secrets/SKILL.md +6 -0
  81. package/dist/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +1 -1
  83. package/src/commands/project/commandPortForward.ts +1 -1
  84. package/src/commands/project/secrets/scope.ts +38 -2
  85. package/src/config/getProjectConfig.ts +9 -1
  86. package/src/secrets/github.ts +8 -5
  87. package/dist/packages/pipeline/src/context/getReviewSlug.d.ts +0 -4
  88. package/dist/packages/pipeline/src/context/getReviewSlug.js.map +0 -1
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "5.2.0",
56
+ "version": "5.3.0",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -59,7 +59,7 @@ export const commandPortForward = defineCommand({
59
59
 
60
60
  const { fullName } = context.environment;
61
61
  let serviceName: string = fullName.toString();
62
- if (context.environment.envType === "review") {
62
+ if (context.environment.instance.type === "review") {
63
63
  const mr = await ctx.get("mr");
64
64
  serviceName = serviceName
65
65
  .toString()
@@ -1,6 +1,8 @@
1
+ import { getSecretsEnv } from "@catladder/pipeline";
1
2
  import {
2
3
  getAllComponentsWithAllEnvsHierarchical,
3
4
  getEnvironment,
5
+ getProjectConfig,
4
6
  } from "../../../config/getProjectConfig";
5
7
 
6
8
  /** which envs of which components a secrets command operates on */
@@ -8,6 +10,26 @@ export type SecretsScope = {
8
10
  [componentName: string]: string[];
9
11
  };
10
12
 
13
+ /**
14
+ * envs that share another env's secrets (`environments.<name>.inherit`)
15
+ * have no secret store of their own — the secrets commands operate on
16
+ * the source env instead
17
+ */
18
+ const withoutSharedSecretEnvs = async (
19
+ all: SecretsScope,
20
+ ): Promise<SecretsScope> => {
21
+ const config = await getProjectConfig();
22
+ const environments = config?.environments;
23
+ return Object.fromEntries(
24
+ Object.entries(all)
25
+ .map(([componentName, envs]): [string, string[]] => [
26
+ componentName,
27
+ envs.filter((env) => getSecretsEnv(environments, env) === env),
28
+ ])
29
+ .filter(([, envs]) => envs.length > 0),
30
+ );
31
+ };
32
+
11
33
  /**
12
34
  * resolves a scope expression to component → envs:
13
35
  * - (empty): all components, all envs
@@ -18,7 +40,9 @@ export type SecretsScope = {
18
40
  export const resolveSecretsScope = async (
19
41
  scope?: string,
20
42
  ): Promise<SecretsScope> => {
21
- const all = await getAllComponentsWithAllEnvsHierarchical();
43
+ const all = await withoutSharedSecretEnvs(
44
+ await getAllComponentsWithAllEnvsHierarchical(),
45
+ );
22
46
  if (Object.keys(all).length === 0) {
23
47
  throw new Error("no catladder config found");
24
48
  }
@@ -28,6 +52,16 @@ export const resolveSecretsScope = async (
28
52
 
29
53
  const [env, componentName] = scope.split(":").map((x) => x || null);
30
54
 
55
+ if (env) {
56
+ const config = await getProjectConfig();
57
+ const secretsEnv = getSecretsEnv(config?.environments, env);
58
+ if (secretsEnv !== env) {
59
+ throw new Error(
60
+ `environment "${env}" shares its secrets with "${secretsEnv}" (environments.${env}.inherit) — manage them via "${secretsEnv}"`,
61
+ );
62
+ }
63
+ }
64
+
31
65
  if (componentName && !(componentName in all)) {
32
66
  throw new Error(
33
67
  `unknown component "${componentName}" — components: ${Object.keys(all).join(", ")}`,
@@ -59,7 +93,9 @@ export const resolveSecretsScope = async (
59
93
  * (one component, all envs) forms
60
94
  */
61
95
  export const secretsScopeChoices = async (): Promise<string[]> => {
62
- const all = await getAllComponentsWithAllEnvsHierarchical();
96
+ const all = await withoutSharedSecretEnvs(
97
+ await getAllComponentsWithAllEnvsHierarchical(),
98
+ );
63
99
  const pairs = Object.entries(all).flatMap(([componentName, envs]) =>
64
100
  envs.map((env) => `${env}:${componentName}`),
65
101
  );
@@ -8,6 +8,7 @@ import {
8
8
  getAllEnvs,
9
9
  getEnvironment as _getEnvironment,
10
10
  createComponentContext,
11
+ getSecretsEnv,
11
12
  getSecretVarName,
12
13
  } from "@catladder/pipeline";
13
14
 
@@ -125,7 +126,14 @@ export const getGitlabVar = async (
125
126
  componentName: string,
126
127
  variableName: string,
127
128
  ) => {
128
- const rawVariableName = getSecretVarName(env, componentName, variableName);
129
+ const config = await getProjectConfig();
130
+ // an env sharing another env's secrets (inherit) reads that env's variables
131
+ const secretsEnv = getSecretsEnv(config?.environments, env);
132
+ const rawVariableName = getSecretVarName(
133
+ secretsEnv,
134
+ componentName,
135
+ variableName,
136
+ );
129
137
  return await getVariableValueByRawName(io, rawVariableName);
130
138
  };
131
139
 
@@ -30,17 +30,20 @@ export const collectSecretsFromVault = async (io: IO, envFilter?: string[]) => {
30
30
  if (envFilter && !envFilter.includes(env)) {
31
31
  continue;
32
32
  }
33
- const { secretEnvVarKeys, jobOnlyVars } = await getEnvironment(
34
- env,
35
- componentName,
36
- );
33
+ const { secretEnvVarKeys, jobOnlyVars, secretsEnv } =
34
+ await getEnvironment(env, componentName);
37
35
  const keys = [
38
36
  ...secretEnvVarKeys,
39
37
  ...jobOnlyVars.build.secretEnvVarKeys,
40
38
  ...jobOnlyVars.deploy.secretEnvVarKeys,
41
39
  ];
40
+ // secretsEnv: an env sharing another env's secrets (inherit)
41
+ // references that env's variable names
42
42
  keys.forEach(({ key, kind }) =>
43
- kinds.set(getSecretVarName(env, componentName, key), kind ?? "secret"),
43
+ kinds.set(
44
+ getSecretVarName(secretsEnv ?? env, componentName, key),
45
+ kind ?? "secret",
46
+ ),
44
47
  );
45
48
  }
46
49
  }
@@ -1,4 +0,0 @@
1
- import { type StringOrBashExpression } from "../../../bash/src/index.js";
2
- import type { PipelineType } from "../types";
3
- import type { EnvConfigWithComponent } from "../types/config";
4
- export declare const getReviewSlug: (envConfig: EnvConfigWithComponent, env: string, pipelineType?: PipelineType) => StringOrBashExpression | null;
@@ -1 +0,0 @@
1
- {"version":3,"file":"getReviewSlug.js","sourceRoot":"","sources":["../../../../../../../packages/pipeline/src/context/getReviewSlug.ts"],"names":[],"mappings":";;;AAAA,0CAA8E;AAE9E,yFAAyF;AAGzF,6CAA0C;AAC1C,MAAM,WAAW,GAAkC;IACjD,OAAO,EAAE,qBAAqB;IAC9B,MAAM,EAAE,IAAI,qBAAc,CACxB,0JAA0J,CAC3J;IACD,uEAAuE;IACvE,MAAM,EAAE,IAAI,qBAAc,CACxB,uEAAuE,CACxE;CACF,CAAC;AAEK,MAAM,aAAa,GAAG,CAC3B,SAAiC,EACjC,GAAW,EACX,YAA2B,EACI,EAAE;IACjC,MAAM,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QACzB,OAAO,IAAA,gEAAgC,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,oBAAoB;AACnC,CAAC,CAAC;AAVW,QAAA,aAAa,iBAUxB"}