@bensandee/tooling 0.21.0 → 0.22.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 (2) hide show
  1. package/dist/bin.mjs +52 -131
  2. package/package.json +1 -1
package/dist/bin.mjs CHANGED
@@ -740,34 +740,6 @@ function ensureWorkflowConcurrency(existing, concurrency) {
740
740
  };
741
741
  }
742
742
  }
743
- function addWorkflowJob(existing, jobName, jobConfig) {
744
- if (isToolingIgnored(existing)) return {
745
- content: existing,
746
- changed: false
747
- };
748
- try {
749
- const doc = parseDocument(existing);
750
- const jobs = doc.getIn(["jobs"]);
751
- if (!isMap(jobs)) return {
752
- content: existing,
753
- changed: false
754
- };
755
- if (jobs.has(jobName)) return {
756
- content: existing,
757
- changed: false
758
- };
759
- jobs.set(jobName, doc.createNode(jobConfig));
760
- return {
761
- content: doc.toString(),
762
- changed: true
763
- };
764
- } catch {
765
- return {
766
- content: existing,
767
- changed: false
768
- };
769
- }
770
- }
771
743
  //#endregion
772
744
  //#region src/generators/deploy-ci.ts
773
745
  /** Build a GitHub Actions expression like `${{ expr }}` without triggering no-template-curly-in-string. */
@@ -1011,7 +983,7 @@ function getAddedDevDepNames(config) {
1011
983
  const deps = { ...ROOT_DEV_DEPS };
1012
984
  if (config.structure !== "monorepo") Object.assign(deps, PER_PACKAGE_DEV_DEPS);
1013
985
  deps["@bensandee/config"] = "0.8.2";
1014
- deps["@bensandee/tooling"] = "0.21.0";
986
+ deps["@bensandee/tooling"] = "0.22.0";
1015
987
  if (config.formatter === "oxfmt") deps["oxfmt"] = "0.35.0";
1016
988
  if (config.formatter === "prettier") deps["prettier"] = "3.8.1";
1017
989
  addReleaseDeps(deps, config);
@@ -1036,7 +1008,7 @@ async function generatePackageJson(ctx) {
1036
1008
  const devDeps = { ...ROOT_DEV_DEPS };
1037
1009
  if (!isMonorepo) Object.assign(devDeps, PER_PACKAGE_DEV_DEPS);
1038
1010
  devDeps["@bensandee/config"] = isWorkspacePackage(ctx, "@bensandee/config") ? "workspace:*" : "0.8.2";
1039
- devDeps["@bensandee/tooling"] = isWorkspacePackage(ctx, "@bensandee/tooling") ? "workspace:*" : "0.21.0";
1011
+ devDeps["@bensandee/tooling"] = isWorkspacePackage(ctx, "@bensandee/tooling") ? "workspace:*" : "0.22.0";
1040
1012
  if (ctx.config.useEslintPlugin) devDeps["@bensandee/eslint-plugin"] = isWorkspacePackage(ctx, "@bensandee/eslint-plugin") ? "workspace:*" : "0.9.2";
1041
1013
  if (ctx.config.formatter === "oxfmt") devDeps["oxfmt"] = "0.35.0";
1042
1014
  if (ctx.config.formatter === "prettier") devDeps["prettier"] = "3.8.1";
@@ -1597,7 +1569,7 @@ async function generateCi(ctx) {
1597
1569
  };
1598
1570
  const isGitHub = ctx.config.ci === "github";
1599
1571
  const nodeVersionYaml = hasEnginesNode$1(ctx) ? "node-version-file: package.json" : "node-version: \"24\"";
1600
- const filePath = isGitHub ? ".github/workflows/check.yml" : ".forgejo/workflows/check.yml";
1572
+ const filePath = isGitHub ? ".github/workflows/ci.yml" : ".forgejo/workflows/ci.yml";
1601
1573
  const content = ciWorkflow(nodeVersionYaml, !isGitHub);
1602
1574
  if (ctx.exists(filePath)) {
1603
1575
  const existing = ctx.read(filePath);
@@ -2147,89 +2119,36 @@ jobs:
2147
2119
  ${commonSteps(nodeVersionYaml, publishesNpm)}${gitConfigStep}${releaseStep}
2148
2120
  `;
2149
2121
  }
2150
- function changesetsReleaseJobConfig(ci, nodeVersionYaml, publishesNpm) {
2151
- const isGitHub = ci === "github";
2152
- const nodeWith = {
2153
- ...nodeVersionYaml.startsWith("node-version-file") ? { "node-version-file": "package.json" } : { "node-version": "24" },
2154
- cache: "pnpm",
2155
- ...publishesNpm && { "registry-url": "https://registry.npmjs.org" }
2156
- };
2157
- if (isGitHub) {
2158
- const changesetsEnv = {
2159
- GITHUB_TOKEN: actionsExpr("github.token"),
2160
- ...publishesNpm && { NPM_TOKEN: actionsExpr("secrets.NPM_TOKEN") }
2161
- };
2162
- return {
2163
- needs: "check",
2122
+ /** Build the required release step for the check job (changesets). */
2123
+ function changesetsReleaseStep(ci, publishesNpm) {
2124
+ if (ci === "github") return {
2125
+ match: { uses: "changesets/action" },
2126
+ step: {
2127
+ uses: "changesets/action@v1",
2164
2128
  if: "github.ref == 'refs/heads/main'",
2165
- concurrency: {
2166
- group: "release",
2167
- "cancel-in-progress": false
2168
- },
2169
- "runs-on": "ubuntu-latest",
2170
- permissions: {
2171
- contents: "write",
2172
- "pull-requests": "write"
2129
+ with: {
2130
+ publish: "pnpm changeset publish",
2131
+ version: "pnpm changeset version"
2173
2132
  },
2174
- steps: [
2175
- {
2176
- uses: "actions/checkout@v4",
2177
- with: { "fetch-depth": 0 }
2178
- },
2179
- { uses: "pnpm/action-setup@v4" },
2180
- {
2181
- uses: "actions/setup-node@v4",
2182
- with: nodeWith
2183
- },
2184
- { run: "pnpm install --frozen-lockfile" },
2185
- { run: "pnpm build" },
2186
- {
2187
- uses: "changesets/action@v1",
2188
- with: {
2189
- publish: "pnpm changeset publish",
2190
- version: "pnpm changeset version"
2191
- },
2192
- env: changesetsEnv
2193
- }
2194
- ]
2195
- };
2196
- }
2197
- const releaseEnv = {
2198
- FORGEJO_SERVER_URL: actionsExpr("github.server_url"),
2199
- FORGEJO_REPOSITORY: actionsExpr("github.repository"),
2200
- FORGEJO_TOKEN: actionsExpr("secrets.FORGEJO_TOKEN"),
2201
- ...publishesNpm && { NODE_AUTH_TOKEN: actionsExpr("secrets.NPM_TOKEN") }
2133
+ env: {
2134
+ GITHUB_TOKEN: actionsExpr("github.token"),
2135
+ ...publishesNpm && { NPM_TOKEN: actionsExpr("secrets.NPM_TOKEN") }
2136
+ }
2137
+ }
2202
2138
  };
2203
2139
  return {
2204
- needs: "check",
2205
- if: "github.ref == 'refs/heads/main'",
2206
- concurrency: {
2207
- group: "release",
2208
- "cancel-in-progress": false
2209
- },
2210
- "runs-on": "ubuntu-latest",
2211
- steps: [
2212
- {
2213
- uses: "actions/checkout@v4",
2214
- with: { "fetch-depth": 0 }
2215
- },
2216
- { uses: "pnpm/action-setup@v4" },
2217
- {
2218
- uses: "actions/setup-node@v4",
2219
- with: nodeWith
2220
- },
2221
- { run: "pnpm install --frozen-lockfile" },
2222
- { run: "pnpm build" },
2223
- {
2224
- name: "Configure git",
2225
- run: "git config user.name \"forgejo-actions[bot]\"\ngit config user.email \"forgejo-actions[bot]@noreply.localhost\"\n"
2140
+ match: { run: "release:changesets" },
2141
+ step: {
2142
+ name: "Release",
2143
+ if: "github.ref == 'refs/heads/main'",
2144
+ env: {
2145
+ FORGEJO_SERVER_URL: actionsExpr("github.server_url"),
2146
+ FORGEJO_REPOSITORY: actionsExpr("github.repository"),
2147
+ FORGEJO_TOKEN: actionsExpr("secrets.FORGEJO_TOKEN"),
2148
+ ...publishesNpm && { NODE_AUTH_TOKEN: actionsExpr("secrets.NPM_TOKEN") }
2226
2149
  },
2227
- {
2228
- name: "Release",
2229
- env: releaseEnv,
2230
- run: "pnpm exec tooling release:changesets"
2231
- }
2232
- ]
2150
+ run: "pnpm exec tooling release:changesets"
2151
+ }
2233
2152
  };
2234
2153
  }
2235
2154
  function requiredReleaseSteps(strategy, nodeVersionYaml, publishesNpm) {
@@ -2296,36 +2215,25 @@ function buildWorkflow(strategy, ci, nodeVersionYaml, publishesNpm) {
2296
2215
  }
2297
2216
  }
2298
2217
  function generateChangesetsReleaseCi(ctx, publishesNpm) {
2299
- const checkPath = ctx.config.ci === "github" ? ".github/workflows/check.yml" : ".forgejo/workflows/check.yml";
2300
- const nodeVersionYaml = hasEnginesNode(ctx) ? "node-version-file: package.json" : "node-version: \"24\"";
2301
- const existing = ctx.read(checkPath);
2218
+ const ciPath = ctx.config.ci === "github" ? ".github/workflows/ci.yml" : ".forgejo/workflows/ci.yml";
2219
+ const existing = ctx.read(ciPath);
2302
2220
  if (!existing) return {
2303
- filePath: checkPath,
2221
+ filePath: ciPath,
2304
2222
  action: "skipped",
2305
2223
  description: "CI workflow not found — run check generator first"
2306
2224
  };
2307
- const addResult = addWorkflowJob(existing, "release", changesetsReleaseJobConfig(ctx.config.ci, nodeVersionYaml, publishesNpm));
2308
- if (addResult.changed) {
2309
- const withComment = ensureSchemaComment(addResult.content, ctx.config.ci);
2310
- ctx.write(checkPath, withComment);
2311
- return {
2312
- filePath: checkPath,
2313
- action: "updated",
2314
- description: "Added release job to CI workflow"
2315
- };
2316
- }
2317
- const merged = mergeWorkflowSteps(existing, "release", requiredReleaseSteps("changesets", nodeVersionYaml, publishesNpm));
2225
+ const merged = mergeWorkflowSteps(existing, "check", [changesetsReleaseStep(ctx.config.ci, publishesNpm)]);
2318
2226
  if (!merged.changed) return {
2319
- filePath: checkPath,
2227
+ filePath: ciPath,
2320
2228
  action: "skipped",
2321
- description: "Release job in CI workflow already up to date"
2229
+ description: "Release step in CI workflow already up to date"
2322
2230
  };
2323
2231
  const withComment = ensureSchemaComment(merged.content, ctx.config.ci);
2324
- ctx.write(checkPath, withComment);
2232
+ ctx.write(ciPath, withComment);
2325
2233
  return {
2326
- filePath: checkPath,
2234
+ filePath: ciPath,
2327
2235
  action: "updated",
2328
- description: "Added missing steps to release job in CI workflow"
2236
+ description: "Added release step to CI workflow"
2329
2237
  };
2330
2238
  }
2331
2239
  async function generateReleaseCi(ctx) {
@@ -3614,8 +3522,21 @@ function buildReleaseConfig(flags) {
3614
3522
  verbose: flags.verbose ?? false
3615
3523
  };
3616
3524
  }
3525
+ /** Resolve the current branch from CI env vars or git. */
3526
+ function getCurrentBranch(executor, cwd) {
3527
+ const ref = process.env["GITHUB_REF"];
3528
+ if (ref?.startsWith("refs/heads/")) return ref.slice(11);
3529
+ return executor.exec("git rev-parse --abbrev-ref HEAD", { cwd }).stdout.trim();
3530
+ }
3617
3531
  /** Core release logic — testable with a mock executor. */
3618
3532
  async function runRelease(config, executor) {
3533
+ const branch = getCurrentBranch(executor, config.cwd);
3534
+ if (branch !== "main") {
3535
+ debug$1(config, `Skipping release on non-main branch: ${branch}`);
3536
+ return { mode: "none" };
3537
+ }
3538
+ executor.exec("git config user.name \"forgejo-actions[bot]\"", { cwd: config.cwd });
3539
+ executor.exec("git config user.email \"forgejo-actions[bot]@noreply.localhost\"", { cwd: config.cwd });
3619
3540
  const changesetFiles = executor.listChangesetFiles(config.cwd);
3620
3541
  debug$1(config, `Changeset files found: ${changesetFiles.length > 0 ? changesetFiles.join(", ") : "(none)"}`);
3621
3542
  if (changesetFiles.length > 0) {
@@ -4656,7 +4577,7 @@ const dockerCheckCommand = defineCommand({
4656
4577
  const main = defineCommand({
4657
4578
  meta: {
4658
4579
  name: "tooling",
4659
- version: "0.21.0",
4580
+ version: "0.22.0",
4660
4581
  description: "Bootstrap and maintain standardized TypeScript project tooling"
4661
4582
  },
4662
4583
  subCommands: {
@@ -4672,7 +4593,7 @@ const main = defineCommand({
4672
4593
  "docker:check": dockerCheckCommand
4673
4594
  }
4674
4595
  });
4675
- console.log(`@bensandee/tooling v0.21.0`);
4596
+ console.log(`@bensandee/tooling v0.22.0`);
4676
4597
  runMain(main);
4677
4598
  //#endregion
4678
4599
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bensandee/tooling",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "CLI tool to bootstrap and maintain standardized TypeScript project tooling",
5
5
  "bin": {
6
6
  "tooling": "./dist/bin.mjs"