trustci 0.3.0 → 0.4.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 (3) hide show
  1. package/README.md +46 -4
  2. package/dist/cli.js +62 -10
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -10,7 +10,7 @@ Setting up trusted publishing one package at a time is tedious in a monorepo.
10
10
 
11
11
  ## Requirements
12
12
 
13
- - **npm** 11.5.1 or later (for `npm trust`)
13
+ - **npm** 11.15.0 or later (for `npm trust` with `--allow-publish` / `--allow-stage-publish`)
14
14
  - **Node** 22.14.0 or later
15
15
 
16
16
  ## Usage
@@ -32,7 +32,7 @@ npx trustci list
32
32
  | ---------- | ---------------------------------------------------------------------------------------------- | --------------- |
33
33
  | `github` | `--repo <owner/repo>` `--file <workflow>` | `--env <name>` |
34
34
  | `gitlab` | `--project <group/project>` (or `--repo`) `--file <workflow>` | `--env <name>` |
35
- | `circleci` | Either all of `--org-id` `--project-id` `--pipeline-definition-id`, or a CircleCI token | `--vcs-origin <host/owner/repo>`, `--circle-token`, `--file`, `--context-id` (repeatable) |
35
+ | `circleci` | A CircleCI token, or all of `--org-id` `--project-id` `--pipeline-definition-id` | `--vcs-origin <host/owner/repo>` (inferred), `--circle-token`, `--file`, `--context-id` (repeatable) |
36
36
 
37
37
  At least one of `--allow-publish` / `--allow-stage-publish` is required.
38
38
 
@@ -40,7 +40,12 @@ At least one of `--allow-publish` / `--allow-stage-publish` is required.
40
40
  # GitLab
41
41
  npx trustci --provider gitlab --project me/repo --file .gitlab-ci.yml --allow-publish -y
42
42
 
43
- # CircleCI (vcs-origin is host/owner/repo; a leading https:// is stripped automatically)
43
+ # CircleCI — minimal form: UUIDs are resolved via the API and --vcs-origin
44
+ # is inferred, so a token (here via the environment) is all you need to add
45
+ CIRCLE_TOKEN=... npx trustci --provider circleci --allow-publish
46
+
47
+ # CircleCI — fully explicit form
48
+ # (vcs-origin is host/owner/repo; a leading https:// is stripped automatically)
44
49
  npx trustci --provider circleci \
45
50
  --org-id <uuid> --project-id <uuid> --pipeline-definition-id <uuid> \
46
51
  --vcs-origin github.com/me/repo \
@@ -73,11 +78,27 @@ prints which one it used (never the token itself):
73
78
  The OS keychain, where circleci CLI v1 and chunk store tokens by default, is not read.
74
79
  When all three UUIDs are given, no token is looked up.
75
80
 
81
+ #### CircleCI pipeline definitions and `--file`
82
+
83
+ A missing `--pipeline-definition-id` is resolved by listing the project's
84
+ pipeline definitions. When there is exactly one, it is used automatically.
85
+ When the project has several — e.g. a config sourced from another repository
86
+ alongside `.circleci/config.yml` — pass `--file` with either the definition's
87
+ config file path or its name; the error message lists the candidates:
88
+
89
+ ```bash
90
+ npx trustci --provider circleci --allow-publish \
91
+ --file workflows/publish/npm-polyrepo-bun-semantic-release.yaml
92
+ ```
93
+
94
+ `--file` is only used for this lookup — it is not passed to `npm trust`, and
95
+ it has no effect when `--pipeline-definition-id` is given explicitly.
96
+
76
97
  ### Common options
77
98
 
78
99
  | Flag | Description |
79
100
  | ------------------------ | --------------------------------------------------- |
80
- | `--dry-run` | Print the `npm trust` commands without executing. |
101
+ | `--dry-run` | Print the `npm trust` commands without executing, then the `trustci` command for the real run (the flags you passed, without `--dry-run`, plus `-y`). |
81
102
  | `--only <name-glob>` | Only include packages matching (repeatable). |
82
103
  | `--exclude <name-glob>` | Exclude packages matching (repeatable). |
83
104
  | `-y`, `--yes` | Skip the confirmation prompt (and npm's). |
@@ -95,6 +116,18 @@ Patterns are read from the first of:
95
116
  Packages marked `"private": true` are always excluded. On a real (non-dry) run,
96
117
  packages not yet published to the registry are skipped with a warning.
97
118
 
119
+ ## Agent skill
120
+
121
+ The repository ships an [Agent Skill](https://agentskills.io/) at
122
+ [`skills/trustci/SKILL.md`](https://github.com/hideokamoto/trustci/blob/main/skills/trustci/SKILL.md)
123
+ that teaches coding agents (Claude Code, Codex, Cursor, …) to run trustci safely:
124
+ dry-run first, then a real run only after you confirm. Install it with the
125
+ [`skills`](https://github.com/vercel-labs/skills) CLI:
126
+
127
+ ```bash
128
+ npx skills add hideokamoto/trustci
129
+ ```
130
+
98
131
  ## Development
99
132
 
100
133
  Built with [Bun](https://bun.sh), ships zero runtime dependencies, and the
@@ -107,6 +140,15 @@ bun run typecheck
107
140
  bun run build # -> dist/cli.js (npx entry point), via `bun build --target node`
108
141
  ```
109
142
 
143
+ The documentation site lives in `docs/` ([Astro Starlight](https://starlight.astro.build/)):
144
+
145
+ ```bash
146
+ cd docs
147
+ bun install
148
+ bun run dev # local preview
149
+ bun run build # -> docs/dist
150
+ ```
151
+
110
152
  `bun install` also enables a husky `commit-msg` hook that runs
111
153
  [commitlint](https://commitlint.js.org/) with `@commitlint/config-conventional`,
112
154
  so every commit must be a [Conventional Commit](https://www.conventionalcommits.org/).
package/dist/cli.js CHANGED
@@ -438,7 +438,7 @@ async function resolveCircleciOptions(parsed, deps = defaultResolveDeps) {
438
438
 
439
439
  // src/npm.ts
440
440
  var MIN_NODE = "22.14.0";
441
- var MIN_NPM = "11.5.1";
441
+ var MIN_NPM = "11.15.0";
442
442
  function cmpVersion(a, b) {
443
443
  const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
444
444
  const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
@@ -521,6 +521,28 @@ function shellQuote(s) {
521
521
  function displayCommand(args) {
522
522
  return ["npm", ...args].map(shellQuote).join(" ");
523
523
  }
524
+ function realRunCommand(argv, yes) {
525
+ const out = [];
526
+ let tokenOmitted = false;
527
+ for (let i = 0;i < argv.length; i++) {
528
+ const a = argv[i];
529
+ if (a === "--dry-run")
530
+ continue;
531
+ if (a === "--circle-token") {
532
+ tokenOmitted = true;
533
+ i++;
534
+ continue;
535
+ }
536
+ if (a.startsWith("--circle-token=")) {
537
+ tokenOmitted = true;
538
+ continue;
539
+ }
540
+ out.push(a);
541
+ }
542
+ if (!yes)
543
+ out.push("-y");
544
+ return { command: ["npx", "trustci", ...out].map(shellQuote).join(" "), tokenOmitted };
545
+ }
524
546
 
525
547
  // src/workspace.ts
526
548
  import { existsSync, readFileSync as readFileSync2 } from "node:fs";
@@ -723,6 +745,9 @@ function discoverPackages(root) {
723
745
  const dirs = expandPatterns(root, patterns);
724
746
  const all = [];
725
747
  const seen = new Set;
748
+ if (existsSync(path2.join(root, "pnpm-workspace.yaml"))) {
749
+ dirs.unshift(path2.resolve(root));
750
+ }
726
751
  for (const dir of dirs) {
727
752
  const pkg = readPkg(dir);
728
753
  if (pkg && !seen.has(pkg.name)) {
@@ -750,7 +775,7 @@ function filterPackages(all, only, exclude) {
750
775
  });
751
776
  }
752
777
  // package.json
753
- var version = "0.3.0";
778
+ var version = "0.4.0";
754
779
 
755
780
  // src/cli.ts
756
781
  var VERSION = version;
@@ -760,6 +785,11 @@ Usage:
760
785
  trustci [trust] --provider <github|gitlab|circleci> [provider flags] [options]
761
786
  trustci list [package] [--dry-run]
762
787
 
788
+ Commands:
789
+ trust register a trusted publisher for every public workspace package
790
+ (the default; "trust" may be omitted)
791
+ list run \`npm trust list\` for <package>, or for every public workspace package
792
+
763
793
  Providers:
764
794
  github --repo <owner/repo> --file <workflow> [--env <name>]
765
795
  gitlab --project <group/project> --file <workflow> [--env <name>]
@@ -769,34 +799,45 @@ Providers:
769
799
  [--context-id <uuid> ...]
770
800
  --vcs-origin defaults to the root package.json "repository", then
771
801
  \`git remote get-url origin\`.
772
- Missing UUIDs are resolved via CircleCI API v2 using a token from
773
- --circle-token, $CIRCLE_TOKEN, $CIRCLECI_TOKEN, $CIRCLE_CLI_TOKEN,
774
- $CIRCLECI_CLI_TOKEN, or ~/.circleci/cli.yml (in that order).
802
+ Missing UUIDs are resolved via CircleCI API v2 (also under --dry-run)
803
+ using a token from --circle-token, $CIRCLE_TOKEN, $CIRCLECI_TOKEN,
804
+ $CIRCLE_CLI_TOKEN, $CIRCLECI_CLI_TOKEN, or ~/.circleci/cli.yml (in that order).
775
805
  Explicit UUIDs override auto-resolution; with all three, no token is needed.
806
+ --file selects the pipeline definition by config path or name (needed
807
+ when the project has more than one); it is not passed to npm trust.
776
808
 
777
809
  Permissions (at least one required):
778
810
  --allow-publish allow npm publish
779
811
  --allow-stage-publish allow npm stage publish
780
812
 
781
813
  Options:
782
- --dry-run print the npm trust commands without executing them
814
+ --dry-run print the npm commands without executing them, then the
815
+ trustci command for the real run (trust only; your
816
+ flags, -y added)
783
817
  --only <name-glob> only include packages matching (repeatable)
784
818
  --exclude <name-glob> exclude packages matching (repeatable)
785
- -y, --yes skip the confirmation prompt (and npm's)
819
+ globs match the whole name; * also matches "/"
820
+ -y, --yes skip the confirmation prompt (and npm's);
821
+ required when stdin is not a terminal
786
822
  -h, --help show this help
787
823
  -v, --version show the trustci version
788
824
 
789
825
  Workspaces are detected from pnpm-workspace.yaml, package.json "workspaces",
790
826
  or lerna.json. If no workspace config is found, the root package.json is used
791
827
  as a single-package fallback. Private packages ("private": true) are always excluded.
828
+ On a real run, packages not yet published to the registry are skipped.
792
829
 
793
830
  Examples:
794
831
  trustci --dry-run --provider github --repo me/repo --file release.yml --allow-publish
795
832
  trustci --provider gitlab --project me/repo --file .gitlab-ci.yml --allow-publish -y
796
833
  CIRCLE_TOKEN=... trustci --provider circleci --allow-publish
834
+ trustci --provider circleci --file .circleci/config.yml --allow-publish
797
835
  trustci --provider circleci --org-id <uuid> --project-id <uuid> \\
798
836
  --pipeline-definition-id <uuid> --vcs-origin github.com/me/repo --allow-publish
799
837
  trustci list
838
+
839
+ Requires npm >= 11.15.0 and Node >= 22.14.0.
840
+ Documentation: https://trustci.hidetaka.dev
800
841
  `;
801
842
  async function confirm(question) {
802
843
  const rl = createInterface({ input: process2.stdin, output: process2.stderr });
@@ -834,7 +875,7 @@ $ ${displayCommand(args)}`);
834
875
  }
835
876
  return failures > 0 ? 1 : 0;
836
877
  }
837
- async function runTrust(parsed) {
878
+ async function runTrust(parsed, argv) {
838
879
  const root = process2.cwd();
839
880
  const { all, source } = discoverPackages(root);
840
881
  if (all.length === 0) {
@@ -844,6 +885,9 @@ async function runTrust(parsed) {
844
885
  const candidates = filterPackages(all, parsed.only, parsed.exclude);
845
886
  if (candidates.length === 0) {
846
887
  console.error(`No public packages matched (out of ${all.length} discovered via ${source}).`);
888
+ for (const pkg of all) {
889
+ console.error(` - ${pkg.name}${pkg.private ? " (private)" : ""}`);
890
+ }
847
891
  return 1;
848
892
  }
849
893
  console.error(`Detected ${all.length} package(s) via ${source}; ${candidates.length} public after filters.`);
@@ -857,6 +901,13 @@ async function runTrust(parsed) {
857
901
  }
858
902
  console.error(`
859
903
  (dry run — registry publish-state was not checked and nothing was executed)`);
904
+ const real = realRunCommand(argv, parsed.options.yes);
905
+ console.log(`
906
+ # To register, run (flags as given, without --dry-run):
907
+ ${real.command}`);
908
+ if (real.tokenOmitted) {
909
+ console.error("note: --circle-token is left out of that command; pass it again or set CIRCLE_TOKEN.");
910
+ }
860
911
  return 0;
861
912
  }
862
913
  const targets = [];
@@ -907,9 +958,10 @@ Done. ${targets.length - failures} succeeded, ${failures} failed.`);
907
958
  return failures > 0 ? 1 : 0;
908
959
  }
909
960
  async function main() {
961
+ const argv = process2.argv.slice(2);
910
962
  let parsed;
911
963
  try {
912
- parsed = parseCliArgs(process2.argv.slice(2));
964
+ parsed = parseCliArgs(argv);
913
965
  } catch (err) {
914
966
  if (err instanceof ArgError) {
915
967
  console.error(`error: ${err.message}
@@ -946,7 +998,7 @@ async function main() {
946
998
  console.error(`error: ${err.message}`);
947
999
  return 1;
948
1000
  }
949
- return runTrust(parsed);
1001
+ return runTrust(parsed, argv);
950
1002
  }
951
1003
  main().then((code) => {
952
1004
  process2.exitCode = code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trustci",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Bulk-register npm Trusted Publishers (npm trust) across all public packages in a monorepo. Supports GitHub, GitLab and CircleCI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,7 +11,7 @@
11
11
  ],
12
12
  "engines": {
13
13
  "node": ">=22.14.0",
14
- "npm": ">=11.5.1"
14
+ "npm": ">=11.15.0"
15
15
  },
16
16
  "scripts": {
17
17
  "build": "bun build src/cli.ts --target node --outfile dist/cli.js",