@catladder/cli 0.0.0-next-78d43d4a → 0.0.0-next-6916db3c

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 (65) hide show
  1. package/dist/apps/cli/src/catci.js +2 -2
  2. package/dist/apps/cli/src/catci.js.map +1 -1
  3. package/dist/apps/cli/src/commands/project/commandGitlabCi.js +2 -1
  4. package/dist/apps/cli/src/commands/project/commandGitlabCi.js.map +1 -1
  5. package/dist/apps/cli/src/commands/security/commandSecurityAuditCiJob.js +2 -2
  6. package/dist/apps/cli/src/commands/security/commandSecurityAuditCiJob.js.map +1 -1
  7. package/dist/apps/cli/src/commands/security/commandSecurityAuditCreate.js +2 -2
  8. package/dist/apps/cli/src/commands/security/commandSecurityAuditCreate.js.map +1 -1
  9. package/dist/apps/cli/src/publish/npmPublishJob.js +22 -5
  10. package/dist/apps/cli/src/publish/npmPublishJob.js.map +1 -1
  11. package/dist/apps/cli/src/utils/gitlabHost.d.ts +14 -0
  12. package/dist/apps/cli/src/utils/gitlabHost.js +27 -0
  13. package/dist/apps/cli/src/utils/gitlabHost.js.map +1 -0
  14. package/dist/bundles/catci/index.js +10 -4
  15. package/dist/bundles/catenv/index.js +137 -36
  16. package/dist/bundles/cli/index.js +177 -41
  17. package/dist/bundles/runner-images/kubernetes/helm-charts/the-panter-chart/templates/_helpers.tpl +0 -10
  18. package/dist/bundles/runner-images/kubernetes/helm-charts/the-panter-chart/templates/app.ingress.yaml +0 -5
  19. package/dist/bundles/runner-images/kubernetes/helm-charts/the-panter-chart/values.yaml +0 -1
  20. package/dist/bundles/runner-images/npm-publish/Dockerfile +12 -0
  21. package/dist/bundles/runner-images/semantic-release/scripts/semanticRelease +4 -3
  22. package/dist/bundles/skills/catladder-deploys/references/deploy-types.md +3 -2
  23. package/dist/packages/pipeline/src/backends/github/createGithubJobs.js +70 -24
  24. package/dist/packages/pipeline/src/backends/github/createGithubJobs.js.map +1 -1
  25. package/dist/packages/pipeline/src/backends/gitlab/GitlabBackend.js +11 -1
  26. package/dist/packages/pipeline/src/backends/gitlab/GitlabBackend.js.map +1 -1
  27. package/dist/packages/pipeline/src/backends/gitlab/createGitlabJobs.js +5 -1
  28. package/dist/packages/pipeline/src/backends/gitlab/createGitlabJobs.js.map +1 -1
  29. package/dist/packages/pipeline/src/backends/index.d.ts +6 -0
  30. package/dist/packages/pipeline/src/backends/index.js +9 -2
  31. package/dist/packages/pipeline/src/backends/index.js.map +1 -1
  32. package/dist/packages/pipeline/src/context/getEnvironmentVariables.d.ts +1 -1
  33. package/dist/packages/pipeline/src/customImages/shippedImages.js +1 -0
  34. package/dist/packages/pipeline/src/customImages/shippedImages.js.map +1 -1
  35. package/dist/packages/pipeline/src/deploy/base/deploy.js +1 -0
  36. package/dist/packages/pipeline/src/deploy/base/deploy.js.map +1 -1
  37. package/dist/packages/pipeline/src/deploy/npmPackage/deployJob.js +6 -1
  38. package/dist/packages/pipeline/src/deploy/npmPackage/deployJob.js.map +1 -1
  39. package/dist/packages/pipeline/src/deploy/pages/deployJob.js +16 -5
  40. package/dist/packages/pipeline/src/deploy/pages/deployJob.js.map +1 -1
  41. package/dist/packages/pipeline/src/pipeline/generatePipelineFiles.js +10 -0
  42. package/dist/packages/pipeline/src/pipeline/generatePipelineFiles.js.map +1 -1
  43. package/dist/packages/pipeline/src/runner/index.d.ts +1 -1
  44. package/dist/packages/pipeline/src/runner/index.js.map +1 -1
  45. package/dist/packages/pipeline/src/types/config.d.ts +3 -3
  46. package/dist/packages/pipeline/src/types/jobDefinition.d.ts +1 -1
  47. package/dist/packages/pipeline/src/types/jobs.d.ts +9 -0
  48. package/dist/packages/pipeline/src/types/jobs.js.map +1 -1
  49. package/dist/packages/pipeline/src/utils/writeFiles.d.ts +6 -0
  50. package/dist/packages/pipeline/src/utils/writeFiles.js +8 -2
  51. package/dist/packages/pipeline/src/utils/writeFiles.js.map +1 -1
  52. package/dist/runner-images/kubernetes/helm-charts/the-panter-chart/templates/_helpers.tpl +0 -10
  53. package/dist/runner-images/kubernetes/helm-charts/the-panter-chart/templates/app.ingress.yaml +0 -5
  54. package/dist/runner-images/kubernetes/helm-charts/the-panter-chart/values.yaml +0 -1
  55. package/dist/runner-images/npm-publish/Dockerfile +12 -0
  56. package/dist/runner-images/semantic-release/scripts/semanticRelease +4 -3
  57. package/dist/skills/catladder-deploys/references/deploy-types.md +3 -2
  58. package/dist/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +1 -1
  60. package/src/catci.ts +2 -3
  61. package/src/commands/project/commandGitlabCi.ts +2 -1
  62. package/src/commands/security/commandSecurityAuditCiJob.ts +2 -3
  63. package/src/commands/security/commandSecurityAuditCreate.ts +2 -3
  64. package/src/publish/npmPublishJob.ts +32 -6
  65. package/src/utils/gitlabHost.ts +23 -0
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "0.0.0-next-78d43d4a",
56
+ "version": "0.0.0-next-6916db3c",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
package/src/catci.ts CHANGED
@@ -29,8 +29,7 @@ import {
29
29
  githubQueuedGuardJob,
30
30
  } from "./release/githubQueuedRelease";
31
31
  import { npmPublishJob, parseNpmPublishArgs } from "./publish/npmPublishJob";
32
-
33
- const GITLAB_HOST = "https://git.panter.ch";
32
+ import { getGitlabHostUrl } from "./utils/gitlabHost";
34
33
 
35
34
  const USAGE = `catci — catladder CI companion
36
35
 
@@ -129,7 +128,7 @@ const securityAuditCiJob = async (
129
128
  console.log("could not evaluate security audit document");
130
129
  console.log("creating new merge request with security audit template...");
131
130
 
132
- const api = new Gitlab({ host: GITLAB_HOST, token });
131
+ const api = new Gitlab({ host: await getGitlabHostUrl(), token });
133
132
  const mr = await createSecurityAuditMergeRequest({
134
133
  api,
135
134
  mainBranch,
@@ -2,6 +2,7 @@ import { exec } from "child-process-promise";
2
2
  import { last } from "lodash-es";
3
3
  import open from "open";
4
4
  import { defineCommand } from "../../core/defineCommand";
5
+ import { getGitlabHostUrl } from "../../utils/gitlabHost";
5
6
  import {
6
7
  doGitlabRequest,
7
8
  getGitlabToken,
@@ -99,7 +100,7 @@ export const commandCiJobLog = defineCommand({
99
100
  const trace = await exec(
100
101
  `curl -s --header "PRIVATE-TOKEN: ${await getGitlabToken(
101
102
  ctx,
102
- )}" "https://git.panter.ch/api/v4/projects/${projectId}/jobs/${id}/trace"`,
103
+ )}" "${await getGitlabHostUrl()}/api/v4/projects/${projectId}/jobs/${id}/trace"`,
103
104
  );
104
105
 
105
106
  const job = await doGitlabRequest(
@@ -8,8 +8,7 @@ import {
8
8
  createSecurityAuditMergeRequest,
9
9
  SECURITY_AUDIT_FILE_NAME,
10
10
  } from "../../security/createSecurityAuditMergeRequest";
11
-
12
- const GITLAB_HOST = "https://git.panter.ch";
11
+ import { getGitlabHostUrl } from "../../utils/gitlabHost";
13
12
 
14
13
  export const commandSecurityAuditCiJob = defineCommand({
15
14
  name: "security audit ci-job",
@@ -52,7 +51,7 @@ export const commandSecurityAuditCiJob = defineCommand({
52
51
  const projectId = await ctx.get("projectId");
53
52
  const userId = await ctx.get("userId");
54
53
 
55
- const api = new Gitlab({ host: GITLAB_HOST, token });
54
+ const api = new Gitlab({ host: await getGitlabHostUrl(), token });
56
55
 
57
56
  const mr = await createSecurityAuditMergeRequest({
58
57
  api,
@@ -1,8 +1,7 @@
1
1
  import { defineCommand } from "../../core/defineCommand";
2
2
  import { Gitlab } from "@gitbeaker/rest";
3
3
  import { createSecurityAuditMergeRequest } from "../../security/createSecurityAuditMergeRequest";
4
-
5
- const GITLAB_HOST = "https://git.panter.ch";
4
+ import { getGitlabHostUrl } from "../../utils/gitlabHost";
6
5
 
7
6
  export const commandSecurityAuditCreate = defineCommand({
8
7
  name: "security audit create",
@@ -36,7 +35,7 @@ export const commandSecurityAuditCreate = defineCommand({
36
35
  const projectId = await ctx.get("projectId");
37
36
  const userId = await ctx.get("userId");
38
37
 
39
- const api = new Gitlab({ host: GITLAB_HOST, token });
38
+ const api = new Gitlab({ host: await getGitlabHostUrl(), token });
40
39
 
41
40
  const result = await createSecurityAuditMergeRequest({
42
41
  api,
@@ -74,12 +74,29 @@ const writeNpmrc = async (dir: string, registry: string) => {
74
74
  return npmrcPath;
75
75
  };
76
76
 
77
- const npmPublish = (dir: string, npmrcPath: string, args: string[]) =>
77
+ /**
78
+ * whether the CI job can mint an OIDC token for npm trusted publishing.
79
+ * github actions exposes these two only when the job declares
80
+ * `permissions: id-token: write` (catladder sets it via the job's
81
+ * `idToken` flag).
82
+ */
83
+ const hasOidcCredentials = () =>
84
+ !!process.env.ACTIONS_ID_TOKEN_REQUEST_URL &&
85
+ !!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
86
+
87
+ const npmPublish = (
88
+ dir: string,
89
+ npmrcPath: string | undefined,
90
+ args: string[],
91
+ ) =>
78
92
  new Promise<void>((resolvePromise, reject) => {
79
93
  const child = spawn("npm", ["publish", ...args], {
80
94
  cwd: dir,
81
95
  stdio: "inherit",
82
- env: { ...process.env, NPM_CONFIG_USERCONFIG: npmrcPath },
96
+ env: {
97
+ ...process.env,
98
+ ...(npmrcPath ? { NPM_CONFIG_USERCONFIG: npmrcPath } : {}),
99
+ },
83
100
  });
84
101
  child.on("error", reject);
85
102
  child.on("exit", (code) =>
@@ -90,9 +107,10 @@ const npmPublish = (dir: string, npmrcPath: string, args: string[]) =>
90
107
  });
91
108
 
92
109
  export const npmPublishJob = async (options: NpmPublishJobOptions) => {
93
- if (!process.env.NPM_TOKEN) {
110
+ const oidc = hasOidcCredentials();
111
+ if (!oidc && !process.env.NPM_TOKEN) {
94
112
  throw new Error(
95
- "NPM_TOKEN is not set — configure it as a catladder secret for this component",
113
+ "NPM_TOKEN is not set — configure it as a catladder secret for this component, or publish from a workflow registered as a trusted publisher on npm",
96
114
  );
97
115
  }
98
116
  const registry = options.registry ?? DEFAULT_NPM_REGISTRY;
@@ -103,10 +121,18 @@ export const npmPublishJob = async (options: NpmPublishJobOptions) => {
103
121
  });
104
122
 
105
123
  const name = await setPackageVersion(options.dir, plan.version);
106
- const npmrcPath = await writeNpmrc(options.dir, registry);
124
+ // with OIDC available npm mints its own short-lived credentials, and
125
+ // an .npmrc referencing an unset ${NPM_TOKEN} would only get in the
126
+ // way. A token, when present, still wins as the fallback.
127
+ const npmrcPath =
128
+ oidc && !process.env.NPM_TOKEN
129
+ ? undefined
130
+ : await writeNpmrc(options.dir, registry);
107
131
 
108
132
  console.log(
109
- `publishing ${name}@${plan.version} (dist-tag ${plan.distTag}) to ${registry}`,
133
+ `publishing ${name}@${plan.version} (dist-tag ${plan.distTag}) to ${registry}${
134
+ npmrcPath ? "" : " via trusted publishing (OIDC)"
135
+ }`,
110
136
  );
111
137
  await npmPublish(options.dir, npmrcPath, [
112
138
  "--tag",
@@ -0,0 +1,23 @@
1
+ import { getGitRemoteHostAndPath } from "../git/gitProjectInformation";
2
+
3
+ /**
4
+ * the base url of the gitlab instance this project lives on.
5
+ *
6
+ * Never hardcode an instance: catladder is used outside panter, and the
7
+ * host was baked in as https://git.panter.ch in several places, which
8
+ * silently broke every consumer on another gitlab.
9
+ *
10
+ * - in a gitlab CI job, `CI_SERVER_URL` is the authoritative value
11
+ * (predefined, already includes the scheme)
12
+ * - locally, derive it from the git remote
13
+ *
14
+ * @param remoteName the remote to derive from outside CI (default origin)
15
+ */
16
+ export const getGitlabHostUrl = async (remoteName = "origin") => {
17
+ const fromCi = process.env.CI_SERVER_URL;
18
+ if (fromCi) {
19
+ return fromCi.replace(/\/+$/, "");
20
+ }
21
+ const { gitRemoteHost } = await getGitRemoteHostAndPath(remoteName);
22
+ return `https://${gitRemoteHost}`;
23
+ };