@biffo/cli 0.166.0 → 0.166.1

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/index.js +74 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1629,6 +1629,34 @@ var GitHubAdapter = class {
1629
1629
  throw err;
1630
1630
  }
1631
1631
  }
1632
+ /**
1633
+ * How many self-hosted runners this repo can actually see (#803, biffo-runners#2).
1634
+ *
1635
+ * Setting `RUNNER_LABEL` points a repo's jobs at a self-hosted fleet. It does
1636
+ * not grant the fleet's GitHub App access to that repo — and until someone
1637
+ * does, the repo sees **zero** runners and every job queues for ever with no
1638
+ * error at all. Measured on a freshly created plugin repo: 0 runners, while an
1639
+ * established one in the same fleet saw 3.
1640
+ *
1641
+ * Queuing for ever and failing at the billing wall look completely different
1642
+ * in the UI and are the same outcome under branch protection: nothing can
1643
+ * merge. Callers use this to say so at create time rather than leaving it to
1644
+ * be discovered on the first PR.
1645
+ *
1646
+ * Returns `null` when the count cannot be read (permissions, API error) —
1647
+ * distinct from `0`, which is a real and actionable answer.
1648
+ */
1649
+ async repoRunnerCount(org, repo) {
1650
+ try {
1651
+ const { data } = await this.octokit.actions.listSelfHostedRunnersForRepo({
1652
+ owner: org,
1653
+ repo
1654
+ });
1655
+ return data.total_count;
1656
+ } catch {
1657
+ return null;
1658
+ }
1659
+ }
1632
1660
  async setRepoVariable(org, repo, name, value) {
1633
1661
  log.info(`Setting variable: ${name}`);
1634
1662
  try {
@@ -6839,6 +6867,9 @@ var pluginCreateCommand = new Command13("create").description("Scaffold a new pl
6839
6867
  ).option(
6840
6868
  "--org <org>",
6841
6869
  "With --standalone, also create the GitHub repo under this org (or user), push, and protect dev"
6870
+ ).option(
6871
+ "--runner-label <label>",
6872
+ "With --org, the RUNNER_LABEL the new repo\u2019s CI should run on (defaults to mirroring this checkout\u2019s)"
6842
6873
  ).option(
6843
6874
  "--skeleton <path>",
6844
6875
  "Path to the plugin skeleton (defaults to _skeletons/plugin-template)"
@@ -6852,6 +6883,7 @@ var pluginCreateCommand = new Command13("create").description("Scaffold a new pl
6852
6883
  firstParty: options.firstParty ?? false,
6853
6884
  standalone: options.standalone ?? false,
6854
6885
  ...options.org ? { org: options.org } : {},
6886
+ ...options.runnerLabel ? { runnerLabel: options.runnerLabel } : {},
6855
6887
  ...options.skeleton ? { skeletonRoot: resolve11(options.skeleton) } : {},
6856
6888
  dryRun: options.dryRun ?? false,
6857
6889
  commit: options.commit !== false,
@@ -6980,18 +7012,19 @@ async function runStandaloneCreate(names, options, deps) {
6980
7012
  "--org needs a commit to push. Drop --no-commit, or create the repo yourself using the steps printed by a --no-commit run."
6981
7013
  );
6982
7014
  }
6983
- await createAndPushStandaloneRepo(options.org, names, destDir, deps);
7015
+ await createAndPushStandaloneRepo(options.org, names, destDir, options, deps);
6984
7016
  return;
6985
7017
  }
6986
7018
  printStandaloneNextSteps(names, minorOf(manifest.version));
6987
7019
  }
6988
- async function createAndPushStandaloneRepo(org, names, destDir, deps) {
7020
+ async function createAndPushStandaloneRepo(org, names, destDir, options, deps) {
6989
7021
  if (deps.makeGitHub === void 0 || deps.resolveToken === void 0) {
6990
7022
  throw new Error("No GitHub adapter available \u2014 cannot create a repository.");
6991
7023
  }
6992
7024
  const token = await deps.resolveToken();
6993
7025
  const github = deps.makeGitHub(token);
6994
7026
  const cloneUrl = await github.createEmptyRepo(org, names.dist, `${names.slug} \u2014 a Biffo plugin`);
7027
+ await propagateRunnerLabel(org, names.dist, options, deps, github);
6995
7028
  await deps.git.addRemote(destDir, "origin", cloneUrl);
6996
7029
  await deps.git.push(destDir, "dev", { token });
6997
7030
  log.success(`Pushed dev to ${org}/${names.dist}`);
@@ -7007,6 +7040,45 @@ async function createAndPushStandaloneRepo(org, names, destDir, deps) {
7007
7040
  }
7008
7041
  printStandaloneRemoteNextSteps(names, org);
7009
7042
  }
7043
+ async function propagateRunnerLabel(org, repo, options, deps, github) {
7044
+ try {
7045
+ let label = options.runnerLabel?.trim();
7046
+ if (!label) {
7047
+ const source = await currentRepoSlug(options.cwd, deps);
7048
+ if (source) {
7049
+ label = (await github.getRepoVariable(source.org, source.repo, "RUNNER_LABEL"))?.trim();
7050
+ }
7051
+ }
7052
+ if (!label) {
7053
+ log.warn(
7054
+ `No RUNNER_LABEL set on ${org}/${repo} \u2014 its CI will use GitHub-hosted runners. If this account routes CI to a self-hosted fleet, every job will fail before it starts, and the branch protection just configured will block every PR on checks that never report. Fix with: gh variable set RUNNER_LABEL --repo ${org}/${repo}`
7055
+ );
7056
+ return;
7057
+ }
7058
+ await github.setRepoVariable(org, repo, "RUNNER_LABEL", label);
7059
+ log.success(`RUNNER_LABEL=${label} set on ${org}/${repo}`);
7060
+ const runners = await github.repoRunnerCount(org, repo);
7061
+ if (runners === 0) {
7062
+ log.warn(
7063
+ `${org}/${repo} points at the '${label}' runner fleet but can see 0 runners. Jobs will queue indefinitely with no error until the fleet's GitHub App is granted access to this repo (biffo-runners#2) \u2014 and the branch protection just applied will block every PR until then.`
7064
+ );
7065
+ }
7066
+ } catch (err) {
7067
+ log.warn(
7068
+ `Could not set RUNNER_LABEL on ${org}/${repo}: ${err.message}. Set it manually if this account uses self-hosted runners.`
7069
+ );
7070
+ }
7071
+ }
7072
+ async function currentRepoSlug(cwd, deps) {
7073
+ try {
7074
+ const url = await deps.git.getRemoteUrl(cwd, "origin");
7075
+ const match = /[:/]([^/:]+)\/([^/]+?)(?:\.git)?$/.exec(url.trim());
7076
+ if (match?.[1] === void 0 || match[2] === void 0) return null;
7077
+ return { org: match[1], repo: match[2] };
7078
+ } catch {
7079
+ return null;
7080
+ }
7081
+ }
7010
7082
  function printStandaloneRemoteNextSteps(names, org) {
7011
7083
  console.log(chalk13.bold("\n Standalone plugin repo created!\n"));
7012
7084
  console.log(` https://github.com/${org}/${names.dist} (dev, protected)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.166.0",
3
+ "version": "0.166.1",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",