@theholocron/cli 5.2.1 → 5.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.
- package/README.md +1 -1
- package/dist/cli.mjs +524 -243
- package/dist/cli.mjs.map +1 -1
- package/package.json +5 -5
package/dist/cli.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
15
15
|
import { appendFileSync, closeSync, copyFileSync, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
16
16
|
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
17
17
|
import { AuthError, DOTENV_FILE, copyToClipboard, createFeatureResolver as createFeatureResolver$1, createKeyring, createPrivateFile, deferCredentials, dotenvLine, findCredential, finishCredentialsFile, hasCredentials, isGitIgnored, readDotenvFile, resolveValue as resolveValue$1, resolveValue as resolveValue$2, setCredentials, writeCredentialsFile } from "@theholocron/kyber/secrets";
|
|
18
|
-
import { AGGREGATE_CHECK, AGGREGATE_CHECK_NAME, AGGREGATE_SHADOW_CHECK_NAME, DEFAULT_ORG, DOCUMENTATION_FLAG, DOT_GITHUB_REPO, HOLOCRON_REPO, KNOWN_TASKS, KNOWN_WORKFLOWS, LEGACY_NAMES, PNPM_BUILTIN_COMMANDS, PRERELEASE_CHANNEL, RELEASE_BRANCHES, RESERVED_SCRIPT_NAMES, SUITES, TASKS, aggregateChecks, aggregatePoster, checkPackageScripts, checkReleaseLines, codecovFlagNames, createAstromech, createCommitMsg, createDependabot, createDevmoji, createEditorconfig, createEditorconfigChecker, createHeader, createLabeler, createPreCommit, createPrePush, createPrepareCommitMsg, createYamlignore, createYamllint, defaultListDirs, defaultPaths, defaultReadJson, deployOnRelease, describeTasks, extractPreviewConfig, formatJson, frozenReusablePaths, hostedReusableWorkflows, isDeprecated, isTask, localize, mergeScripts, packageLocation, postAggregate, readWorkspacePackages, recordDeploys, requiredChecks, resolveTaskName, reusableTemplates, scriptName, stampDeprecated, wedgeFix, workflowFile, workflowKeys, workspacePackages as workspacePackages$1 } from "@theholocron/astromech";
|
|
18
|
+
import { AGGREGATE_CHECK, AGGREGATE_CHECK_NAME, AGGREGATE_SHADOW_CHECK_NAME, DEFAULT_ORG, DOCUMENTATION_FLAG, DOT_GITHUB_REPO, DOT_GITHUB_REPO as DOT_GITHUB_REPO$1, HOLOCRON_REPO, HOLOCRON_REPO as HOLOCRON_REPO$1, KNOWN_TASKS, KNOWN_WORKFLOWS, LEGACY_NAMES, PNPM_BUILTIN_COMMANDS, PRERELEASE_CHANNEL, RELEASE_BRANCHES, RESERVED_SCRIPT_NAMES, SUITES, TASKS, aggregateChecks, aggregatePoster, checkPackageScripts, checkReleaseLines, codecovFlagNames, createAstromech, createCommitMsg, createDependabot, createDevmoji, createEditorconfig, createEditorconfigChecker, createHeader, createLabeler, createPreCommit, createPrePush, createPrepareCommitMsg, createYamlignore, createYamllint, defaultListDirs, defaultPaths, defaultReadJson, deployOnRelease, describeTasks, extractPreviewConfig, formatJson, frozenReusablePaths, hostedReusableWorkflows, isDeprecated, isTask, localize, mergeScripts, packageLocation, postAggregate, readWorkspacePackages, recordDeploys, requiredChecks, resolveTaskName, reusableTemplates, scriptName, stampDeprecated, wedgeFix, workflowFile, workflowKeys, workspacePackages as workspacePackages$1 } from "@theholocron/astromech";
|
|
19
19
|
import { loadTasksConfig, releaseGroups } from "@theholocron/astromech/config";
|
|
20
20
|
import { createCliLogger, createCliTelemetry } from "@theholocron/kyber/observability";
|
|
21
21
|
import { resolveAxiomFromEnv } from "@theholocron/observability/logger";
|
|
@@ -508,12 +508,26 @@ const doctorCiEntry = {
|
|
|
508
508
|
name: "doctor ci",
|
|
509
509
|
description: "Check the repo against the flat task vocabulary: aliases, caller names, the ci aggregate, home (read-only)",
|
|
510
510
|
positionals: [],
|
|
511
|
-
options: [
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
511
|
+
options: [
|
|
512
|
+
{
|
|
513
|
+
key: "shadow",
|
|
514
|
+
flag: "--shadow",
|
|
515
|
+
type: "confirm",
|
|
516
|
+
message: "Also compare Sentinel's shadow aggregate with the Actions one?"
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
key: "remote",
|
|
520
|
+
flag: "--remote",
|
|
521
|
+
type: "confirm",
|
|
522
|
+
message: "Also check the hosted files over the network (the ci-v1 tag, what callers name at it, the frozen copies)?"
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
key: "scan",
|
|
526
|
+
flag: "--scan",
|
|
527
|
+
type: "confirm",
|
|
528
|
+
message: "Also list the org's repositories still calling the frozen .github files (clones every repo)?"
|
|
529
|
+
}
|
|
530
|
+
],
|
|
517
531
|
skipOptions: [
|
|
518
532
|
"all",
|
|
519
533
|
"repo",
|
|
@@ -14288,6 +14302,31 @@ function callersRow(callers) {
|
|
|
14288
14302
|
};
|
|
14289
14303
|
return problemRow(id, title, callerProblems(callers), `${callers.length} of ${callers.length} named for their id`);
|
|
14290
14304
|
}
|
|
14305
|
+
// src/commands/doctor-ci/fetch-text.ts
|
|
14306
|
+
const TIMEOUT_MS = 1e4;
|
|
14307
|
+
/** Reads a public URL with `fetch` and a timeout; a request that fails is status 0, never a throw. */
|
|
14308
|
+
const fetchText = async (url) => {
|
|
14309
|
+
/* v8 ignore start -- the real network; the rows are tested with an injected reader */
|
|
14310
|
+
try {
|
|
14311
|
+
const res = await fetch(url, {
|
|
14312
|
+
headers: {
|
|
14313
|
+
accept: "application/vnd.github+json",
|
|
14314
|
+
"user-agent": "holocron-doctor-ci"
|
|
14315
|
+
},
|
|
14316
|
+
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
14317
|
+
});
|
|
14318
|
+
return {
|
|
14319
|
+
status: res.status,
|
|
14320
|
+
text: await res.text()
|
|
14321
|
+
};
|
|
14322
|
+
} catch {
|
|
14323
|
+
return {
|
|
14324
|
+
status: 0,
|
|
14325
|
+
text: ""
|
|
14326
|
+
};
|
|
14327
|
+
}
|
|
14328
|
+
/* v8 ignore stop */
|
|
14329
|
+
};
|
|
14291
14330
|
// src/commands/doctor-ci/home-of.ts
|
|
14292
14331
|
/** Where a job's `uses:` value is hosted: the frozen copies in `theholocron/.github`, holocron at `ci-v1`, this repo, or elsewhere. */
|
|
14293
14332
|
function homeOf(uses) {
|
|
@@ -14420,6 +14459,449 @@ function realCiIo(repoRoot) {
|
|
|
14420
14459
|
} };
|
|
14421
14460
|
/* v8 ignore stop */
|
|
14422
14461
|
}
|
|
14462
|
+
// src/commands/doctor-ci/remote-constants.ts
|
|
14463
|
+
/** The tag generated callers pin the hosted files to (`CI_TARGET.ref` in astromech). */
|
|
14464
|
+
const CI_TAG = "ci-v1";
|
|
14465
|
+
/** The line a frozen copy carries in `theholocron/.github` (written by `holocron sync github` until it stopped). */
|
|
14466
|
+
const FROZEN_NOTICE = "DEPRECATED — frozen copy";
|
|
14467
|
+
const API = "https://api.github.com";
|
|
14468
|
+
const RAW = "https://raw.githubusercontent.com";
|
|
14469
|
+
// src/commands/doctor-ci/frozen-row.ts
|
|
14470
|
+
const ID$11 = "frozen";
|
|
14471
|
+
const TITLE$11 = `the workflows left in ${DOT_GITHUB_REPO} say they are frozen`;
|
|
14472
|
+
/**
|
|
14473
|
+
* The `frozen` row: every workflow still in `theholocron/.github` carries the deprecation notice, so nobody mistakes a
|
|
14474
|
+
* copy for the live reusable. A file without it is one callers may still use unmarked (a repo still calling
|
|
14475
|
+
* `security.yml@main` is why it is there), so it fails with the file names. A read that cannot be made is a skip.
|
|
14476
|
+
*/
|
|
14477
|
+
async function frozenRow(read) {
|
|
14478
|
+
const listing = await read(`${API}/repos/${DOT_GITHUB_REPO}/contents/.github/workflows`);
|
|
14479
|
+
if (listing.status !== 200) return {
|
|
14480
|
+
id: ID$11,
|
|
14481
|
+
title: TITLE$11,
|
|
14482
|
+
status: "skip",
|
|
14483
|
+
detail: `could not list them (HTTP ${listing.status || "no answer"})`,
|
|
14484
|
+
problems: []
|
|
14485
|
+
};
|
|
14486
|
+
let names;
|
|
14487
|
+
try {
|
|
14488
|
+
names = JSON.parse(listing.text).map((entry) => entry.name).filter((name) => typeof name === "string" && /\.ya?ml$/.test(name)).sort();
|
|
14489
|
+
} catch {
|
|
14490
|
+
return {
|
|
14491
|
+
id: ID$11,
|
|
14492
|
+
title: TITLE$11,
|
|
14493
|
+
status: "skip",
|
|
14494
|
+
detail: "the listing was not JSON",
|
|
14495
|
+
problems: []
|
|
14496
|
+
};
|
|
14497
|
+
}
|
|
14498
|
+
const files = await Promise.all(names.map(async (name) => ({
|
|
14499
|
+
name,
|
|
14500
|
+
res: await read(`${RAW}/${DOT_GITHUB_REPO}/main/.github/workflows/${name}`)
|
|
14501
|
+
})));
|
|
14502
|
+
const unread = files.find(({ res }) => res.status !== 200);
|
|
14503
|
+
if (unread) return {
|
|
14504
|
+
id: ID$11,
|
|
14505
|
+
title: TITLE$11,
|
|
14506
|
+
status: "skip",
|
|
14507
|
+
detail: `could not read ${unread.name} (HTTP ${unread.res.status || "no answer"})`,
|
|
14508
|
+
problems: []
|
|
14509
|
+
};
|
|
14510
|
+
const unmarked = files.filter(({ res }) => !res.text.split("\n", 15).some((line) => line.includes(FROZEN_NOTICE)));
|
|
14511
|
+
if (unmarked.length > 0) return {
|
|
14512
|
+
id: ID$11,
|
|
14513
|
+
title: TITLE$11,
|
|
14514
|
+
status: "fail",
|
|
14515
|
+
detail: `${unmarked.length} of ${files.length} carry no notice`,
|
|
14516
|
+
problems: unmarked.map(({ name }) => `${name}: no "${FROZEN_NOTICE}" notice`)
|
|
14517
|
+
};
|
|
14518
|
+
return {
|
|
14519
|
+
id: ID$11,
|
|
14520
|
+
title: TITLE$11,
|
|
14521
|
+
status: "ok",
|
|
14522
|
+
detail: `${files.length} of ${files.length} carry the notice`,
|
|
14523
|
+
problems: []
|
|
14524
|
+
};
|
|
14525
|
+
}
|
|
14526
|
+
// src/commands/doctor-ci/hosted-paths.ts
|
|
14527
|
+
const USES = new RegExp(`^\\s*(?:-\\s+)?uses:\\s*["']?${HOLOCRON_REPO}/([^@\\s"']+)@${CI_TAG}["']?\\s*(?:#.*)?$`, "gm");
|
|
14528
|
+
/**
|
|
14529
|
+
* Every `theholocron/holocron/<path>@ci-v1` a workflow calls, in a job (`uses:` of a reusable workflow) or a step (an
|
|
14530
|
+
* action), once each, with the files that name it.
|
|
14531
|
+
*/
|
|
14532
|
+
function hostedPaths(workflows) {
|
|
14533
|
+
const found = /* @__PURE__ */ new Map();
|
|
14534
|
+
for (const { file, text } of workflows) for (const match of text.matchAll(USES)) {
|
|
14535
|
+
const path = match[1];
|
|
14536
|
+
found.set(path, (found.get(path) ?? /* @__PURE__ */ new Set()).add(file));
|
|
14537
|
+
}
|
|
14538
|
+
return [...found].map(([path, files]) => ({
|
|
14539
|
+
path,
|
|
14540
|
+
files: [...files].sort()
|
|
14541
|
+
})).sort((a, b) => a.path.localeCompare(b.path));
|
|
14542
|
+
}
|
|
14543
|
+
// src/commands/doctor-ci/refs-row.ts
|
|
14544
|
+
const ID$10 = "refs";
|
|
14545
|
+
const TITLE$10 = `every ${CI_TAG} reference resolves`;
|
|
14546
|
+
/** A workflow file holds itself at its path; an action is a folder with an `action.yml` (or `.yaml`) in it. */
|
|
14547
|
+
async function resolves(read, path) {
|
|
14548
|
+
const url = (p) => `${RAW}/${HOLOCRON_REPO}/${CI_TAG}/${p}`;
|
|
14549
|
+
if (/\.ya?ml$/.test(path)) return (await read(url(path))).status;
|
|
14550
|
+
const yml = (await read(url(`${path}/action.yml`))).status;
|
|
14551
|
+
return yml === 200 ? 200 : yml === 404 ? (await read(url(`${path}/action.yaml`))).status : yml;
|
|
14552
|
+
}
|
|
14553
|
+
/**
|
|
14554
|
+
* The `refs` row: each workflow file and action the repository's workflows name at the tag exists at the tag. A path
|
|
14555
|
+
* that answers 404 fails with the files that name it; one that cannot be read at all (no answer, a rate limit) is a skip
|
|
14556
|
+
* for the whole row, so a network problem never reads as a broken reference.
|
|
14557
|
+
*/
|
|
14558
|
+
async function refsRow(workflows, read) {
|
|
14559
|
+
const paths = hostedPaths(workflows);
|
|
14560
|
+
if (paths.length === 0) return {
|
|
14561
|
+
id: ID$10,
|
|
14562
|
+
title: TITLE$10,
|
|
14563
|
+
status: "skip",
|
|
14564
|
+
detail: `no workflow names a file at ${CI_TAG}`,
|
|
14565
|
+
problems: []
|
|
14566
|
+
};
|
|
14567
|
+
const answers = await Promise.all(paths.map(async (hosted) => ({
|
|
14568
|
+
hosted,
|
|
14569
|
+
status: await resolves(read, hosted.path)
|
|
14570
|
+
})));
|
|
14571
|
+
const unread = answers.filter(({ status }) => status !== 200 && status !== 404);
|
|
14572
|
+
if (unread.length > 0) {
|
|
14573
|
+
const first = unread[0];
|
|
14574
|
+
return {
|
|
14575
|
+
id: ID$10,
|
|
14576
|
+
title: TITLE$10,
|
|
14577
|
+
status: "skip",
|
|
14578
|
+
detail: `could not read ${first.hosted.path} (HTTP ${first.status || "no answer"})`,
|
|
14579
|
+
problems: []
|
|
14580
|
+
};
|
|
14581
|
+
}
|
|
14582
|
+
const missing = answers.filter(({ status }) => status === 404);
|
|
14583
|
+
if (missing.length > 0) return {
|
|
14584
|
+
id: ID$10,
|
|
14585
|
+
title: TITLE$10,
|
|
14586
|
+
status: "fail",
|
|
14587
|
+
detail: `${missing.length} of ${paths.length} missing at ${CI_TAG}`,
|
|
14588
|
+
problems: missing.map(({ hosted }) => `${hosted.path}: not at ${CI_TAG} (named by ${hosted.files.join(", ")})`)
|
|
14589
|
+
};
|
|
14590
|
+
return {
|
|
14591
|
+
id: ID$10,
|
|
14592
|
+
title: TITLE$10,
|
|
14593
|
+
status: "ok",
|
|
14594
|
+
detail: `${paths.length} found at ${CI_TAG}`,
|
|
14595
|
+
problems: []
|
|
14596
|
+
};
|
|
14597
|
+
}
|
|
14598
|
+
// src/commands/doctor-ci/tag-row.ts
|
|
14599
|
+
const ID$9 = "tag";
|
|
14600
|
+
const TITLE$9 = `${CI_TAG} exists in ${HOLOCRON_REPO}`;
|
|
14601
|
+
/** The `tag` row: the tag every caller pins the hosted files to exists. A read that fails or is rate limited is a skip, not a fail. */
|
|
14602
|
+
async function tagRow(read) {
|
|
14603
|
+
const res = await read(`${API}/repos/${HOLOCRON_REPO}/git/ref/tags/${CI_TAG}`);
|
|
14604
|
+
if (res.status === 200) {
|
|
14605
|
+
const sha = /"sha"\s*:\s*"([0-9a-f]{7,40})"/.exec(res.text)?.[1];
|
|
14606
|
+
return {
|
|
14607
|
+
id: ID$9,
|
|
14608
|
+
title: TITLE$9,
|
|
14609
|
+
status: "ok",
|
|
14610
|
+
detail: sha ? `at ${sha.slice(0, 9)}` : "found",
|
|
14611
|
+
problems: []
|
|
14612
|
+
};
|
|
14613
|
+
}
|
|
14614
|
+
if (res.status === 404) return {
|
|
14615
|
+
id: ID$9,
|
|
14616
|
+
title: TITLE$9,
|
|
14617
|
+
status: "fail",
|
|
14618
|
+
detail: "no such tag",
|
|
14619
|
+
problems: [`${HOLOCRON_REPO} has no ${CI_TAG} tag, so every caller that pins it fails to resolve`]
|
|
14620
|
+
};
|
|
14621
|
+
return {
|
|
14622
|
+
id: ID$9,
|
|
14623
|
+
title: TITLE$9,
|
|
14624
|
+
status: "skip",
|
|
14625
|
+
detail: `could not read the tag (HTTP ${res.status || "no answer"})`,
|
|
14626
|
+
problems: []
|
|
14627
|
+
};
|
|
14628
|
+
}
|
|
14629
|
+
// src/commands/doctor-ci/remote-rows.ts
|
|
14630
|
+
/** The rows of `doctor ci --remote`: the tag, what the callers name at it, and the frozen copies. All read public URLs only. */
|
|
14631
|
+
async function remoteRows(workflows, read) {
|
|
14632
|
+
return [
|
|
14633
|
+
await tagRow(read),
|
|
14634
|
+
await refsRow(workflows, read),
|
|
14635
|
+
await frozenRow(read)
|
|
14636
|
+
];
|
|
14637
|
+
}
|
|
14638
|
+
// src/commands/probe/references/clone-org.ts
|
|
14639
|
+
const SKIP_DIRS$1 = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
14640
|
+
const MAX_FILE_BYTES = 5242880;
|
|
14641
|
+
/** How often, and how long apart, removing a clone is tried again when something is still writing into it. */
|
|
14642
|
+
const REMOVE_RETRIES = 10;
|
|
14643
|
+
const REMOVE_RETRY_DELAY_MS = 200;
|
|
14644
|
+
/**
|
|
14645
|
+
* The arguments of `gh repo clone` for `org/name` into `dest`: a shallow, quiet clone that runs none of the user's git
|
|
14646
|
+
* hooks. The probe only reads, and a global hook (`core.hooksPath`, `init.templateDir`) such as a `post-checkout` that
|
|
14647
|
+
* starts `ctags` in the background writes `.git/tags` after the clone has returned, which made removing the clone fail
|
|
14648
|
+
* with `ENOTEMPTY` (#2913). `-c` takes effect before the files are checked out.
|
|
14649
|
+
*/
|
|
14650
|
+
function cloneArgs(org, name, dest) {
|
|
14651
|
+
return [
|
|
14652
|
+
"repo",
|
|
14653
|
+
"clone",
|
|
14654
|
+
`${org}/${name}`,
|
|
14655
|
+
dest,
|
|
14656
|
+
"--",
|
|
14657
|
+
"--depth",
|
|
14658
|
+
"1",
|
|
14659
|
+
"--quiet",
|
|
14660
|
+
"-c",
|
|
14661
|
+
"core.hooksPath=/dev/null"
|
|
14662
|
+
];
|
|
14663
|
+
}
|
|
14664
|
+
/**
|
|
14665
|
+
* Removes a scratch directory, trying again when something still writes into it. A process the clone left running can
|
|
14666
|
+
* recreate a file while the directory is being deleted; `rmSync` retries `ENOTEMPTY` (and `EBUSY`, `EPERM`) itself.
|
|
14667
|
+
*/
|
|
14668
|
+
function removeScratch(path, remove = rmSync) {
|
|
14669
|
+
remove(path, {
|
|
14670
|
+
recursive: true,
|
|
14671
|
+
force: true,
|
|
14672
|
+
maxRetries: REMOVE_RETRIES,
|
|
14673
|
+
retryDelay: REMOVE_RETRY_DELAY_MS
|
|
14674
|
+
});
|
|
14675
|
+
}
|
|
14676
|
+
/** Every text file under `dir`: not in `.git` or `node_modules`, under 5 MiB, and without a NUL in its first KiB. */
|
|
14677
|
+
function* textFiles(dir, root = dir) {
|
|
14678
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
14679
|
+
if (SKIP_DIRS$1.has(entry.name)) continue;
|
|
14680
|
+
const path = join(dir, entry.name);
|
|
14681
|
+
if (entry.isDirectory()) yield* textFiles(path, root);
|
|
14682
|
+
else if (entry.isFile() && statSync(path).size < MAX_FILE_BYTES) {
|
|
14683
|
+
const buffer = readFileSync(path);
|
|
14684
|
+
if (!buffer.subarray(0, 1024).includes(0)) yield {
|
|
14685
|
+
path: relative(root, path),
|
|
14686
|
+
text: buffer.toString("utf8")
|
|
14687
|
+
};
|
|
14688
|
+
}
|
|
14689
|
+
}
|
|
14690
|
+
}
|
|
14691
|
+
/**
|
|
14692
|
+
* Shallow-clones the default branch of each active (not archived) repository of `org` with `gh`, one at a time, and
|
|
14693
|
+
* removes every clone when the scan ends. Cloning, rather than GitHub code search, because search skips repositories
|
|
14694
|
+
* that are not indexed and gives no guarantee of completeness.
|
|
14695
|
+
*/
|
|
14696
|
+
function cloneOrg(org) {
|
|
14697
|
+
return JSON.parse(execFileSync("gh", [
|
|
14698
|
+
"repo",
|
|
14699
|
+
"list",
|
|
14700
|
+
org,
|
|
14701
|
+
"--limit",
|
|
14702
|
+
"200",
|
|
14703
|
+
"--json",
|
|
14704
|
+
"name,isArchived,isTemplate"
|
|
14705
|
+
], { encoding: "utf8" })).filter((repo) => !repo.isArchived).sort((a, b) => a.name.localeCompare(b.name)).map((repo) => ({
|
|
14706
|
+
name: repo.name,
|
|
14707
|
+
isTemplate: repo.isTemplate,
|
|
14708
|
+
files() {
|
|
14709
|
+
const scratch = mkdtempSync(join(tmpdir(), "refs-"));
|
|
14710
|
+
const dest = join(scratch, repo.name);
|
|
14711
|
+
execFileSync("gh", cloneArgs(org, repo.name, dest), { stdio: "pipe" });
|
|
14712
|
+
try {
|
|
14713
|
+
return [...textFiles(dest)];
|
|
14714
|
+
} finally {
|
|
14715
|
+
removeScratch(scratch);
|
|
14716
|
+
}
|
|
14717
|
+
}
|
|
14718
|
+
}));
|
|
14719
|
+
/* v8 ignore stop */
|
|
14720
|
+
}
|
|
14721
|
+
// src/commands/probe/references/find-references.ts
|
|
14722
|
+
const CALL = /^-?\s*uses:\s/;
|
|
14723
|
+
/** The repository that hosts the files; its own references are the starters and shims, not callers. */
|
|
14724
|
+
const HOST_REPO = ".github";
|
|
14725
|
+
/** What a reference points at, from the text after the needle. */
|
|
14726
|
+
function kindOf$1(line, needle) {
|
|
14727
|
+
const rest = line.slice(line.indexOf(needle) + needle.length);
|
|
14728
|
+
if (rest.startsWith("workflows/")) return "workflow";
|
|
14729
|
+
if (rest.startsWith("actions/")) return "action";
|
|
14730
|
+
return "other";
|
|
14731
|
+
}
|
|
14732
|
+
/** Every line of every file of `repo` that contains `needle`. */
|
|
14733
|
+
function findReferences(repo, needle) {
|
|
14734
|
+
const found = [];
|
|
14735
|
+
for (const file of repo.files()) file.text.split("\n").forEach((line, index) => {
|
|
14736
|
+
if (!line.includes(needle)) return;
|
|
14737
|
+
found.push({
|
|
14738
|
+
repo: repo.name,
|
|
14739
|
+
file: file.path,
|
|
14740
|
+
line: index + 1,
|
|
14741
|
+
kind: kindOf$1(line, needle),
|
|
14742
|
+
text: line.trim()
|
|
14743
|
+
});
|
|
14744
|
+
});
|
|
14745
|
+
return found;
|
|
14746
|
+
}
|
|
14747
|
+
/**
|
|
14748
|
+
* Whether a reference is a live call: a `uses:` line in a YAML file, which is what GitHub reads. Tests, docs and specs
|
|
14749
|
+
* name the path on purpose (the legacy-path detection, a test that nothing spells it, a record of the move), so they are
|
|
14750
|
+
* references to list but not calls to wait on.
|
|
14751
|
+
*/
|
|
14752
|
+
function isCall(ref) {
|
|
14753
|
+
return /\.ya?ml$/.test(ref.file) && CALL.test(ref.text);
|
|
14754
|
+
}
|
|
14755
|
+
// src/commands/probe/references/references-probes.ts
|
|
14756
|
+
function scan(repos, needle) {
|
|
14757
|
+
return {
|
|
14758
|
+
repos,
|
|
14759
|
+
found: repos.flatMap((repo) => findReferences(repo, needle))
|
|
14760
|
+
};
|
|
14761
|
+
}
|
|
14762
|
+
function summarise$2(ctx, repos, found, needle, max) {
|
|
14763
|
+
ctx.say({
|
|
14764
|
+
status: "heading",
|
|
14765
|
+
label: `References to ${needle}`
|
|
14766
|
+
});
|
|
14767
|
+
for (const repo of repos) {
|
|
14768
|
+
const own = found.filter((ref) => ref.repo === repo.name);
|
|
14769
|
+
const files = new Set(own.map((ref) => ref.file)).size;
|
|
14770
|
+
const count = (kind) => own.filter((ref) => ref.kind === kind).length;
|
|
14771
|
+
ctx.say({
|
|
14772
|
+
status: "info",
|
|
14773
|
+
label: repo.name === ".github" ? `${repo.name} (host)` : repo.name,
|
|
14774
|
+
detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other; ${own.filter(isCall).length} live calls`
|
|
14775
|
+
});
|
|
14776
|
+
}
|
|
14777
|
+
const outside = found.filter((ref) => ref.repo !== HOST_REPO);
|
|
14778
|
+
const calls = outside.filter(isCall).length;
|
|
14779
|
+
const inside = found.length - outside.length;
|
|
14780
|
+
const detail = `${outside.length} references in all (tests, docs and specs may name the path on purpose), ${inside} more inside ${HOST_REPO}`;
|
|
14781
|
+
if (calls > max) ctx.say({
|
|
14782
|
+
status: "fail",
|
|
14783
|
+
label: `${calls} live calls outside ${HOST_REPO}`,
|
|
14784
|
+
detail: `more than the ${max} allowed; ${detail}`
|
|
14785
|
+
});
|
|
14786
|
+
else ctx.say({
|
|
14787
|
+
status: "ok",
|
|
14788
|
+
label: `${calls} live calls outside ${HOST_REPO}`,
|
|
14789
|
+
detail
|
|
14790
|
+
});
|
|
14791
|
+
}
|
|
14792
|
+
/**
|
|
14793
|
+
* `ci refs` counts the references to the reusable workflows and composite actions hosted in `<org>/.github` across
|
|
14794
|
+
* every active repository of the org. It is the exit test for removing the forwarding shims there: they can go when
|
|
14795
|
+
* no live call outside `.github` is left (a `uses:` line in a YAML file; see {@link isCall}). It fails above `<max>`,
|
|
14796
|
+
* which defaults to 0, so the exit code is the test (#2915). `ci ref-list` prints each reference with its file and line.
|
|
14797
|
+
*/
|
|
14798
|
+
function ciProbes(org, clone = cloneOrg) {
|
|
14799
|
+
const needle = (name) => `${name}/.github/.github/`;
|
|
14800
|
+
const read = (ctx) => {
|
|
14801
|
+
if (!org) {
|
|
14802
|
+
ctx.say({
|
|
14803
|
+
status: "fail",
|
|
14804
|
+
label: "no org",
|
|
14805
|
+
detail: "the config has no org to scan"
|
|
14806
|
+
});
|
|
14807
|
+
return null;
|
|
14808
|
+
}
|
|
14809
|
+
return {
|
|
14810
|
+
org,
|
|
14811
|
+
...scan(clone(org), needle(org))
|
|
14812
|
+
};
|
|
14813
|
+
};
|
|
14814
|
+
return {
|
|
14815
|
+
refs: {
|
|
14816
|
+
summary: "Count references to the reusable workflows and actions hosted in the org's .github repo; fails on a live call outside it (arg: max, default 0).",
|
|
14817
|
+
writes: false,
|
|
14818
|
+
async run(ctx) {
|
|
14819
|
+
const result = read(ctx);
|
|
14820
|
+
if (!result) return;
|
|
14821
|
+
const max = ctx.args?.[0] === void 0 ? 0 : Number(ctx.args[0]);
|
|
14822
|
+
if (!Number.isInteger(max) || max < 0) {
|
|
14823
|
+
ctx.say({
|
|
14824
|
+
status: "fail",
|
|
14825
|
+
label: `\`${ctx.args[0]}\` is not a number`,
|
|
14826
|
+
detail: "usage: ci refs [max]"
|
|
14827
|
+
});
|
|
14828
|
+
return;
|
|
14829
|
+
}
|
|
14830
|
+
summarise$2(ctx, result.repos, result.found, needle(result.org), max);
|
|
14831
|
+
}
|
|
14832
|
+
},
|
|
14833
|
+
"ref-list": {
|
|
14834
|
+
summary: "List every reference to the org's .github workflows and actions, with file and line.",
|
|
14835
|
+
writes: false,
|
|
14836
|
+
async run(ctx) {
|
|
14837
|
+
const result = read(ctx);
|
|
14838
|
+
if (!result) return;
|
|
14839
|
+
for (const ref of result.found) ctx.say({
|
|
14840
|
+
status: "info",
|
|
14841
|
+
label: `${ref.repo}:${ref.file}:${ref.line}`,
|
|
14842
|
+
detail: `${ref.kind}: ${ref.text}`
|
|
14843
|
+
});
|
|
14844
|
+
ctx.say({
|
|
14845
|
+
status: "ok",
|
|
14846
|
+
label: `${result.found.length} references`
|
|
14847
|
+
});
|
|
14848
|
+
}
|
|
14849
|
+
}
|
|
14850
|
+
};
|
|
14851
|
+
}
|
|
14852
|
+
// src/commands/doctor-ci/repos-row.ts
|
|
14853
|
+
const ID$8 = "repos";
|
|
14854
|
+
/**
|
|
14855
|
+
* The `repos` row (`doctor ci --scan`): which repositories of the org still call the frozen workflows and actions in
|
|
14856
|
+
* `<org>/.github` (a live `uses:` line, the same count `holocron probe ci refs` makes). Each is named with how many
|
|
14857
|
+
* calls it has. It clones every active repository, so it is never part of `doctor --all`. With no org, or a scan that
|
|
14858
|
+
* cannot run (no `gh`, no network), the row is a skip, never a failure.
|
|
14859
|
+
*/
|
|
14860
|
+
function reposRow(org, clone = cloneOrg) {
|
|
14861
|
+
const title = `no repository of ${org ?? "the org"} still calls the frozen ${HOST_REPO} files`;
|
|
14862
|
+
if (!org) return {
|
|
14863
|
+
id: ID$8,
|
|
14864
|
+
title,
|
|
14865
|
+
status: "skip",
|
|
14866
|
+
detail: "the config has no org to scan",
|
|
14867
|
+
problems: []
|
|
14868
|
+
};
|
|
14869
|
+
let repos;
|
|
14870
|
+
let calls;
|
|
14871
|
+
try {
|
|
14872
|
+
repos = clone(org);
|
|
14873
|
+
const needle = `${org}/${HOST_REPO}/.github/`;
|
|
14874
|
+
calls = /* @__PURE__ */ new Map();
|
|
14875
|
+
for (const repo of repos) {
|
|
14876
|
+
if (repo.name === ".github") continue;
|
|
14877
|
+
const live = findReferences(repo, needle).filter(isCall).length;
|
|
14878
|
+
if (live > 0) calls.set(repo.name, live);
|
|
14879
|
+
}
|
|
14880
|
+
} catch (err) {
|
|
14881
|
+
const reason = err instanceof Error ? err.message.split("\n")[0] : "unknown error";
|
|
14882
|
+
return {
|
|
14883
|
+
id: ID$8,
|
|
14884
|
+
title,
|
|
14885
|
+
status: "skip",
|
|
14886
|
+
detail: `could not scan the org (${reason})`,
|
|
14887
|
+
problems: []
|
|
14888
|
+
};
|
|
14889
|
+
}
|
|
14890
|
+
if (calls.size === 0) return {
|
|
14891
|
+
id: ID$8,
|
|
14892
|
+
title,
|
|
14893
|
+
status: "ok",
|
|
14894
|
+
detail: `${repos.length} repositories scanned`,
|
|
14895
|
+
problems: []
|
|
14896
|
+
};
|
|
14897
|
+
return {
|
|
14898
|
+
id: ID$8,
|
|
14899
|
+
title,
|
|
14900
|
+
status: "fail",
|
|
14901
|
+
detail: `${calls.size} of ${repos.length} repositories`,
|
|
14902
|
+
problems: [...calls].map(([name, count]) => `${name}: ${count} live call${count === 1 ? "" : "s"}`)
|
|
14903
|
+
};
|
|
14904
|
+
}
|
|
14423
14905
|
// src/commands/doctor-ci/shadow-verdict.ts
|
|
14424
14906
|
/**
|
|
14425
14907
|
* The verdict of the newest run named `name` among a commit's check runs: still running is `pending`, a completed
|
|
@@ -14580,6 +15062,8 @@ async function runDoctorCi(input) {
|
|
|
14580
15062
|
callersRow(callers),
|
|
14581
15063
|
aggregateRow(callers, aggregateChecks(tasksConfig).expected, aggregatePoster(tasksConfig)),
|
|
14582
15064
|
homeRow(callers),
|
|
15065
|
+
...input.remote ? await remoteRows(io.workflows(), input.fetchText ?? fetchText) : [],
|
|
15066
|
+
...input.scan ? [reposRow(input.context.org ?? config.org, input.scanRepos)] : [],
|
|
14583
15067
|
...input.shadow ? await shadowRows(input) : []
|
|
14584
15068
|
];
|
|
14585
15069
|
printCheckRows(rows, print);
|
|
@@ -14603,6 +15087,12 @@ const doctorCiCommand = {
|
|
|
14603
15087
|
builder: (y) => y.option("shadow", {
|
|
14604
15088
|
type: "boolean",
|
|
14605
15089
|
describe: "Also compare Sentinel's shadow aggregate (ci / Required checks (sentinel)) with the Actions one on the newest pull requests (reads through `source`)"
|
|
15090
|
+
}).option("remote", {
|
|
15091
|
+
type: "boolean",
|
|
15092
|
+
describe: "Also check the hosted files over the network: the ci-v1 tag, every file and action the workflows name at it, and the frozen copies in theholocron/.github (public URLs, no token)"
|
|
15093
|
+
}).option("scan", {
|
|
15094
|
+
type: "boolean",
|
|
15095
|
+
describe: "Also list the org's repositories that still call the frozen theholocron/.github files (clones every repository with gh; not part of doctor --all)"
|
|
14606
15096
|
}).option("limit", {
|
|
14607
15097
|
type: "number",
|
|
14608
15098
|
describe: "With --shadow: how many of the newest pull requests to read (default 40)"
|
|
@@ -14617,9 +15107,11 @@ const doctorCiCommand = {
|
|
|
14617
15107
|
context: {
|
|
14618
15108
|
repoRoot: argv.cwd,
|
|
14619
15109
|
...tokens,
|
|
14620
|
-
...argv.shadow ? { org: resolveOrg(argv, loaded.resolved) } : {}
|
|
15110
|
+
...argv.shadow || argv.scan ? { org: resolveOrg(argv, loaded.resolved) } : {}
|
|
14621
15111
|
},
|
|
14622
15112
|
...argv.shadow ? { shadow: true } : {},
|
|
15113
|
+
...argv.remote ? { remote: true } : {},
|
|
15114
|
+
...argv.scan ? { scan: true } : {},
|
|
14623
15115
|
...argv.limit !== void 0 ? { shadowLimit: Number(argv.limit) } : {}
|
|
14624
15116
|
})).status === "fail") process.exitCode = 1;
|
|
14625
15117
|
}
|
|
@@ -23850,7 +24342,10 @@ const DEEP_CHECKS = [
|
|
|
23850
24342
|
capability: "source",
|
|
23851
24343
|
command: doctorCiCommand,
|
|
23852
24344
|
async run(input) {
|
|
23853
|
-
const report = await runDoctorCi(
|
|
24345
|
+
const report = await runDoctorCi({
|
|
24346
|
+
...input,
|
|
24347
|
+
remote: true
|
|
24348
|
+
});
|
|
23854
24349
|
return {
|
|
23855
24350
|
status: report.status,
|
|
23856
24351
|
summary: report.summary
|
|
@@ -30191,7 +30686,7 @@ async function runSecretsSync(input) {
|
|
|
30191
30686
|
environment: input.environmentId,
|
|
30192
30687
|
reason: logReason(err)
|
|
30193
30688
|
}, "sync secrets: vault read failed");
|
|
30194
|
-
return summarise$
|
|
30689
|
+
return summarise$1([{
|
|
30195
30690
|
destination: `vault:${vault.providerName}`,
|
|
30196
30691
|
scope: `environment=${input.environmentId}`,
|
|
30197
30692
|
key: "(all)",
|
|
@@ -30308,7 +30803,7 @@ async function runSecretsSync(input) {
|
|
|
30308
30803
|
}
|
|
30309
30804
|
}
|
|
30310
30805
|
}
|
|
30311
|
-
return summarise$
|
|
30806
|
+
return summarise$1(rows, logger, print, dryRun);
|
|
30312
30807
|
}
|
|
30313
30808
|
/**
|
|
30314
30809
|
* Record the vault keys a deployment or Worker filter left out: one skipped row each (names only; the value is never
|
|
@@ -30346,7 +30841,7 @@ async function readAccess(secrets, scope, print) {
|
|
|
30346
30841
|
}
|
|
30347
30842
|
}
|
|
30348
30843
|
/** Log every row, then print and log the summary. Shared by a finished run and one that stopped at the vault. */
|
|
30349
|
-
function summarise$
|
|
30844
|
+
function summarise$1(rows, logger, print, dryRun) {
|
|
30350
30845
|
for (const r of rows) logger[r.status === "fail" ? "warn" : "info"]({
|
|
30351
30846
|
destination: r.destination,
|
|
30352
30847
|
scope: r.scope,
|
|
@@ -34073,13 +34568,13 @@ function generateHolocronConfig(opts) {
|
|
|
34073
34568
|
lines.push(``);
|
|
34074
34569
|
return lines.join("\n");
|
|
34075
34570
|
}
|
|
34076
|
-
const SKIP_DIRS
|
|
34571
|
+
const SKIP_DIRS = [
|
|
34077
34572
|
".git",
|
|
34078
34573
|
"node_modules",
|
|
34079
34574
|
"dist",
|
|
34080
34575
|
".turbo"
|
|
34081
34576
|
];
|
|
34082
|
-
const defaultWalkFiles = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS
|
|
34577
|
+
const defaultWalkFiles = (dir) => walkFilesSync(dir, { skip: SKIP_DIRS });
|
|
34083
34578
|
function isBinary(content) {
|
|
34084
34579
|
for (let i = 0; i < Math.min(content.length, 8e3); i++) if (content.charCodeAt(i) === 0) return true;
|
|
34085
34580
|
return false;
|
|
@@ -35581,13 +36076,13 @@ function planDeps(root) {
|
|
|
35581
36076
|
};
|
|
35582
36077
|
}
|
|
35583
36078
|
// src/commands/probe/deps/report-deps.ts
|
|
35584
|
-
const kindOf
|
|
36079
|
+
const kindOf = (section) => section === "peerDependencies" ? "peer" : section === "devDependencies" ? "dev" : "prod";
|
|
35585
36080
|
/** Every package that uses a dependency, with how. */
|
|
35586
36081
|
function usersOf(row) {
|
|
35587
36082
|
const byPkg = /* @__PURE__ */ new Map();
|
|
35588
36083
|
for (const e of row.edges) {
|
|
35589
36084
|
const kinds = byPkg.get(e.pkg) ?? /* @__PURE__ */ new Set();
|
|
35590
|
-
kinds.add(kindOf
|
|
36085
|
+
kinds.add(kindOf(e.section));
|
|
35591
36086
|
byPkg.set(e.pkg, kinds);
|
|
35592
36087
|
}
|
|
35593
36088
|
return [...byPkg.entries()].map(([pkg, kinds]) => ({
|
|
@@ -35608,7 +36103,7 @@ function detail(p, filter) {
|
|
|
35608
36103
|
for (const e of r.edges) {
|
|
35609
36104
|
const entry = byGroup.get(e.group) ?? /* @__PURE__ */ new Map();
|
|
35610
36105
|
const kinds = entry.get(e.pkg) ?? /* @__PURE__ */ new Set();
|
|
35611
|
-
kinds.add(kindOf
|
|
36106
|
+
kinds.add(kindOf(e.section));
|
|
35612
36107
|
entry.set(e.pkg, kinds);
|
|
35613
36108
|
byGroup.set(e.group, entry);
|
|
35614
36109
|
}
|
|
@@ -36402,7 +36897,7 @@ function writeLcov(ctx, repoRoot, packages) {
|
|
|
36402
36897
|
function percent(documented, total) {
|
|
36403
36898
|
return `${total === 0 ? 100 : Math.round(100 * documented / total)}%`;
|
|
36404
36899
|
}
|
|
36405
|
-
function summarise
|
|
36900
|
+
function summarise(ctx, packages) {
|
|
36406
36901
|
let total = 0;
|
|
36407
36902
|
let documented = 0;
|
|
36408
36903
|
ctx.say({
|
|
@@ -36454,7 +36949,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
|
|
|
36454
36949
|
async run(ctx) {
|
|
36455
36950
|
const packages = measure();
|
|
36456
36951
|
writeLcov(ctx, repoRoot, packages);
|
|
36457
|
-
summarise
|
|
36952
|
+
summarise(ctx, packages);
|
|
36458
36953
|
}
|
|
36459
36954
|
},
|
|
36460
36955
|
patch: {
|
|
@@ -36521,7 +37016,7 @@ function docsCoverageProbes(repoRoot, typedoc = runTypedoc(repoRoot), diff = rea
|
|
|
36521
37016
|
mkdirSync(dirname(file), { recursive: true });
|
|
36522
37017
|
writeFileSync(file, toLcov(packages));
|
|
36523
37018
|
});
|
|
36524
|
-
summarise
|
|
37019
|
+
summarise(ctx, packages);
|
|
36525
37020
|
}
|
|
36526
37021
|
}
|
|
36527
37022
|
};
|
|
@@ -36791,220 +37286,6 @@ function listProbes(groups) {
|
|
|
36791
37286
|
}
|
|
36792
37287
|
return lines;
|
|
36793
37288
|
}
|
|
36794
|
-
// src/commands/probe/references/clone-org.ts
|
|
36795
|
-
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
36796
|
-
const MAX_FILE_BYTES = 5242880;
|
|
36797
|
-
/** How often, and how long apart, removing a clone is tried again when something is still writing into it. */
|
|
36798
|
-
const REMOVE_RETRIES = 10;
|
|
36799
|
-
const REMOVE_RETRY_DELAY_MS = 200;
|
|
36800
|
-
/**
|
|
36801
|
-
* The arguments of `gh repo clone` for `org/name` into `dest`: a shallow, quiet clone that runs none of the user's git
|
|
36802
|
-
* hooks. The probe only reads, and a global hook (`core.hooksPath`, `init.templateDir`) such as a `post-checkout` that
|
|
36803
|
-
* starts `ctags` in the background writes `.git/tags` after the clone has returned, which made removing the clone fail
|
|
36804
|
-
* with `ENOTEMPTY` (#2913). `-c` takes effect before the files are checked out.
|
|
36805
|
-
*/
|
|
36806
|
-
function cloneArgs(org, name, dest) {
|
|
36807
|
-
return [
|
|
36808
|
-
"repo",
|
|
36809
|
-
"clone",
|
|
36810
|
-
`${org}/${name}`,
|
|
36811
|
-
dest,
|
|
36812
|
-
"--",
|
|
36813
|
-
"--depth",
|
|
36814
|
-
"1",
|
|
36815
|
-
"--quiet",
|
|
36816
|
-
"-c",
|
|
36817
|
-
"core.hooksPath=/dev/null"
|
|
36818
|
-
];
|
|
36819
|
-
}
|
|
36820
|
-
/**
|
|
36821
|
-
* Removes a scratch directory, trying again when something still writes into it. A process the clone left running can
|
|
36822
|
-
* recreate a file while the directory is being deleted; `rmSync` retries `ENOTEMPTY` (and `EBUSY`, `EPERM`) itself.
|
|
36823
|
-
*/
|
|
36824
|
-
function removeScratch(path, remove = rmSync) {
|
|
36825
|
-
remove(path, {
|
|
36826
|
-
recursive: true,
|
|
36827
|
-
force: true,
|
|
36828
|
-
maxRetries: REMOVE_RETRIES,
|
|
36829
|
-
retryDelay: REMOVE_RETRY_DELAY_MS
|
|
36830
|
-
});
|
|
36831
|
-
}
|
|
36832
|
-
/** Every text file under `dir`: not in `.git` or `node_modules`, under 5 MiB, and without a NUL in its first KiB. */
|
|
36833
|
-
function* textFiles(dir, root = dir) {
|
|
36834
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
36835
|
-
if (SKIP_DIRS.has(entry.name)) continue;
|
|
36836
|
-
const path = join(dir, entry.name);
|
|
36837
|
-
if (entry.isDirectory()) yield* textFiles(path, root);
|
|
36838
|
-
else if (entry.isFile() && statSync(path).size < MAX_FILE_BYTES) {
|
|
36839
|
-
const buffer = readFileSync(path);
|
|
36840
|
-
if (!buffer.subarray(0, 1024).includes(0)) yield {
|
|
36841
|
-
path: relative(root, path),
|
|
36842
|
-
text: buffer.toString("utf8")
|
|
36843
|
-
};
|
|
36844
|
-
}
|
|
36845
|
-
}
|
|
36846
|
-
}
|
|
36847
|
-
/**
|
|
36848
|
-
* Shallow-clones the default branch of each active (not archived) repository of `org` with `gh`, one at a time, and
|
|
36849
|
-
* removes every clone when the scan ends. Cloning, rather than GitHub code search, because search skips repositories
|
|
36850
|
-
* that are not indexed and gives no guarantee of completeness.
|
|
36851
|
-
*/
|
|
36852
|
-
function cloneOrg(org) {
|
|
36853
|
-
return JSON.parse(execFileSync("gh", [
|
|
36854
|
-
"repo",
|
|
36855
|
-
"list",
|
|
36856
|
-
org,
|
|
36857
|
-
"--limit",
|
|
36858
|
-
"200",
|
|
36859
|
-
"--json",
|
|
36860
|
-
"name,isArchived,isTemplate"
|
|
36861
|
-
], { encoding: "utf8" })).filter((repo) => !repo.isArchived).sort((a, b) => a.name.localeCompare(b.name)).map((repo) => ({
|
|
36862
|
-
name: repo.name,
|
|
36863
|
-
isTemplate: repo.isTemplate,
|
|
36864
|
-
files() {
|
|
36865
|
-
const scratch = mkdtempSync(join(tmpdir(), "refs-"));
|
|
36866
|
-
const dest = join(scratch, repo.name);
|
|
36867
|
-
execFileSync("gh", cloneArgs(org, repo.name, dest), { stdio: "pipe" });
|
|
36868
|
-
try {
|
|
36869
|
-
return [...textFiles(dest)];
|
|
36870
|
-
} finally {
|
|
36871
|
-
removeScratch(scratch);
|
|
36872
|
-
}
|
|
36873
|
-
}
|
|
36874
|
-
}));
|
|
36875
|
-
/* v8 ignore stop */
|
|
36876
|
-
}
|
|
36877
|
-
// src/commands/probe/references/find-references.ts
|
|
36878
|
-
const CALL = /^-?\s*uses:\s/;
|
|
36879
|
-
/** The repository that hosts the files; its own references are the starters and shims, not callers. */
|
|
36880
|
-
const HOST_REPO = ".github";
|
|
36881
|
-
/** What a reference points at, from the text after the needle. */
|
|
36882
|
-
function kindOf(line, needle) {
|
|
36883
|
-
const rest = line.slice(line.indexOf(needle) + needle.length);
|
|
36884
|
-
if (rest.startsWith("workflows/")) return "workflow";
|
|
36885
|
-
if (rest.startsWith("actions/")) return "action";
|
|
36886
|
-
return "other";
|
|
36887
|
-
}
|
|
36888
|
-
/** Every line of every file of `repo` that contains `needle`. */
|
|
36889
|
-
function findReferences(repo, needle) {
|
|
36890
|
-
const found = [];
|
|
36891
|
-
for (const file of repo.files()) file.text.split("\n").forEach((line, index) => {
|
|
36892
|
-
if (!line.includes(needle)) return;
|
|
36893
|
-
found.push({
|
|
36894
|
-
repo: repo.name,
|
|
36895
|
-
file: file.path,
|
|
36896
|
-
line: index + 1,
|
|
36897
|
-
kind: kindOf(line, needle),
|
|
36898
|
-
text: line.trim()
|
|
36899
|
-
});
|
|
36900
|
-
});
|
|
36901
|
-
return found;
|
|
36902
|
-
}
|
|
36903
|
-
/**
|
|
36904
|
-
* Whether a reference is a live call: a `uses:` line in a YAML file, which is what GitHub reads. Tests, docs and specs
|
|
36905
|
-
* name the path on purpose (the legacy-path detection, a test that nothing spells it, a record of the move), so they are
|
|
36906
|
-
* references to list but not calls to wait on.
|
|
36907
|
-
*/
|
|
36908
|
-
function isCall(ref) {
|
|
36909
|
-
return /\.ya?ml$/.test(ref.file) && CALL.test(ref.text);
|
|
36910
|
-
}
|
|
36911
|
-
// src/commands/probe/references/references-probes.ts
|
|
36912
|
-
function scan(repos, needle) {
|
|
36913
|
-
return {
|
|
36914
|
-
repos,
|
|
36915
|
-
found: repos.flatMap((repo) => findReferences(repo, needle))
|
|
36916
|
-
};
|
|
36917
|
-
}
|
|
36918
|
-
function summarise(ctx, repos, found, needle, max) {
|
|
36919
|
-
ctx.say({
|
|
36920
|
-
status: "heading",
|
|
36921
|
-
label: `References to ${needle}`
|
|
36922
|
-
});
|
|
36923
|
-
for (const repo of repos) {
|
|
36924
|
-
const own = found.filter((ref) => ref.repo === repo.name);
|
|
36925
|
-
const files = new Set(own.map((ref) => ref.file)).size;
|
|
36926
|
-
const count = (kind) => own.filter((ref) => ref.kind === kind).length;
|
|
36927
|
-
ctx.say({
|
|
36928
|
-
status: "info",
|
|
36929
|
-
label: repo.name === ".github" ? `${repo.name} (host)` : repo.name,
|
|
36930
|
-
detail: `${files} files: ${count("workflow")} workflow, ${count("action")} action, ${count("other")} other; ${own.filter(isCall).length} live calls`
|
|
36931
|
-
});
|
|
36932
|
-
}
|
|
36933
|
-
const outside = found.filter((ref) => ref.repo !== HOST_REPO);
|
|
36934
|
-
const calls = outside.filter(isCall).length;
|
|
36935
|
-
const inside = found.length - outside.length;
|
|
36936
|
-
const detail = `${outside.length} references in all (tests, docs and specs may name the path on purpose), ${inside} more inside ${HOST_REPO}`;
|
|
36937
|
-
if (calls > max) ctx.say({
|
|
36938
|
-
status: "fail",
|
|
36939
|
-
label: `${calls} live calls outside ${HOST_REPO}`,
|
|
36940
|
-
detail: `more than the ${max} allowed; ${detail}`
|
|
36941
|
-
});
|
|
36942
|
-
else ctx.say({
|
|
36943
|
-
status: "ok",
|
|
36944
|
-
label: `${calls} live calls outside ${HOST_REPO}`,
|
|
36945
|
-
detail
|
|
36946
|
-
});
|
|
36947
|
-
}
|
|
36948
|
-
/**
|
|
36949
|
-
* `ci refs` counts the references to the reusable workflows and composite actions hosted in `<org>/.github` across
|
|
36950
|
-
* every active repository of the org. It is the exit test for removing the forwarding shims there: they can go when
|
|
36951
|
-
* no live call outside `.github` is left (a `uses:` line in a YAML file; see {@link isCall}). It fails above `<max>`,
|
|
36952
|
-
* which defaults to 0, so the exit code is the test (#2915). `ci ref-list` prints each reference with its file and line.
|
|
36953
|
-
*/
|
|
36954
|
-
function ciProbes(org, clone = cloneOrg) {
|
|
36955
|
-
const needle = (name) => `${name}/.github/.github/`;
|
|
36956
|
-
const read = (ctx) => {
|
|
36957
|
-
if (!org) {
|
|
36958
|
-
ctx.say({
|
|
36959
|
-
status: "fail",
|
|
36960
|
-
label: "no org",
|
|
36961
|
-
detail: "the config has no org to scan"
|
|
36962
|
-
});
|
|
36963
|
-
return null;
|
|
36964
|
-
}
|
|
36965
|
-
return {
|
|
36966
|
-
org,
|
|
36967
|
-
...scan(clone(org), needle(org))
|
|
36968
|
-
};
|
|
36969
|
-
};
|
|
36970
|
-
return {
|
|
36971
|
-
refs: {
|
|
36972
|
-
summary: "Count references to the reusable workflows and actions hosted in the org's .github repo; fails on a live call outside it (arg: max, default 0).",
|
|
36973
|
-
writes: false,
|
|
36974
|
-
async run(ctx) {
|
|
36975
|
-
const result = read(ctx);
|
|
36976
|
-
if (!result) return;
|
|
36977
|
-
const max = ctx.args?.[0] === void 0 ? 0 : Number(ctx.args[0]);
|
|
36978
|
-
if (!Number.isInteger(max) || max < 0) {
|
|
36979
|
-
ctx.say({
|
|
36980
|
-
status: "fail",
|
|
36981
|
-
label: `\`${ctx.args[0]}\` is not a number`,
|
|
36982
|
-
detail: "usage: ci refs [max]"
|
|
36983
|
-
});
|
|
36984
|
-
return;
|
|
36985
|
-
}
|
|
36986
|
-
summarise(ctx, result.repos, result.found, needle(result.org), max);
|
|
36987
|
-
}
|
|
36988
|
-
},
|
|
36989
|
-
"ref-list": {
|
|
36990
|
-
summary: "List every reference to the org's .github workflows and actions, with file and line.",
|
|
36991
|
-
writes: false,
|
|
36992
|
-
async run(ctx) {
|
|
36993
|
-
const result = read(ctx);
|
|
36994
|
-
if (!result) return;
|
|
36995
|
-
for (const ref of result.found) ctx.say({
|
|
36996
|
-
status: "info",
|
|
36997
|
-
label: `${ref.repo}:${ref.file}:${ref.line}`,
|
|
36998
|
-
detail: `${ref.kind}: ${ref.text}`
|
|
36999
|
-
});
|
|
37000
|
-
ctx.say({
|
|
37001
|
-
status: "ok",
|
|
37002
|
-
label: `${result.found.length} references`
|
|
37003
|
-
});
|
|
37004
|
-
}
|
|
37005
|
-
}
|
|
37006
|
-
};
|
|
37007
|
-
}
|
|
37008
37289
|
// src/commands/probe/specs/real-specs-io.ts
|
|
37009
37290
|
/** The `specs check` probe's inputs from the real filesystem under `repoRoot`. */
|
|
37010
37291
|
function realSpecsIo(repoRoot) {
|
|
@@ -39125,7 +39406,7 @@ async function runSyncTrust(input) {
|
|
|
39125
39406
|
const print = input.print ?? ((line) => console.log(line));
|
|
39126
39407
|
const logger = input.logger ?? getLogger();
|
|
39127
39408
|
const cwd = input.cwd ?? process.cwd();
|
|
39128
|
-
const repo = input.repo ?? HOLOCRON_REPO;
|
|
39409
|
+
const repo = input.repo ?? HOLOCRON_REPO$1;
|
|
39129
39410
|
const dryRun = input.dryRun ?? false;
|
|
39130
39411
|
const force = input.force ?? false;
|
|
39131
39412
|
const exec = input.exec ?? defaultExec;
|
|
@@ -39286,7 +39567,7 @@ const publishArgs = (y) => y.option("initial", {
|
|
|
39286
39567
|
describe: "--sync-trust only: revoke and recreate every package's Trusted Publisher entry even when its file and repository already match. npm expires an entry that is not used for a publish soon after it is made but still lists it as matching, so a plain run skips it."
|
|
39287
39568
|
}).option("repo", {
|
|
39288
39569
|
type: "string",
|
|
39289
|
-
describe: `owner/repo for Trusted Publisher config (--sync-trust). Defaults to ${HOLOCRON_REPO}.`
|
|
39570
|
+
describe: `owner/repo for Trusted Publisher config (--sync-trust). Defaults to ${HOLOCRON_REPO$1}.`
|
|
39290
39571
|
}).option("group", {
|
|
39291
39572
|
type: "string",
|
|
39292
39573
|
describe: "Only this version group's packages: a folder of the repo (clients, observability). Omitted, every public package in the workspace."
|
|
@@ -41691,7 +41972,7 @@ const specsSyncCommand = {
|
|
|
41691
41972
|
* like `...tasks` from `nodeDocs()` — see issue #464).
|
|
41692
41973
|
*/
|
|
41693
41974
|
function buildBatch(repo) {
|
|
41694
|
-
if (repo !== DOT_GITHUB_REPO) return [];
|
|
41975
|
+
if (repo !== DOT_GITHUB_REPO$1) return [];
|
|
41695
41976
|
const frozen = new Set(frozenReusablePaths());
|
|
41696
41977
|
return [...reusableTemplates()].filter(([path]) => !frozen.has(path)).map(([path, content]) => ({
|
|
41697
41978
|
path,
|
|
@@ -41706,9 +41987,9 @@ function gitBlobSha(content) {
|
|
|
41706
41987
|
async function runSyncGithub(input) {
|
|
41707
41988
|
const print = input.print ?? ((line) => console.log(line));
|
|
41708
41989
|
const logger = input.logger ?? getLogger();
|
|
41709
|
-
const repo = input.repo ?? DOT_GITHUB_REPO;
|
|
41990
|
+
const repo = input.repo ?? DOT_GITHUB_REPO$1;
|
|
41710
41991
|
const { token, dryRun = false, branch, createPr = false } = input;
|
|
41711
|
-
const message = input.message ?? `chore: sync from ${HOLOCRON_REPO}`;
|
|
41992
|
+
const message = input.message ?? `chore: sync from ${HOLOCRON_REPO$1}`;
|
|
41712
41993
|
const client = createGitHubClient({
|
|
41713
41994
|
token,
|
|
41714
41995
|
fetch: input.fetch
|
|
@@ -41798,7 +42079,7 @@ async function runSyncGithub(input) {
|
|
|
41798
42079
|
const batch = buildBatch(repo);
|
|
41799
42080
|
const stamps = [];
|
|
41800
42081
|
let frozen = 0;
|
|
41801
|
-
if (repo === DOT_GITHUB_REPO) for (const path of frozenReusablePaths()) {
|
|
42082
|
+
if (repo === DOT_GITHUB_REPO$1) for (const path of frozenReusablePaths()) {
|
|
41802
42083
|
if (!existingBlobs.has(path)) continue;
|
|
41803
42084
|
let current;
|
|
41804
42085
|
try {
|
|
@@ -41958,8 +42239,8 @@ async function runSyncGithub(input) {
|
|
|
41958
42239
|
// src/commands/sync-github/sync-github.args.ts
|
|
41959
42240
|
const syncGithubArgs = (y) => y.option("repo", {
|
|
41960
42241
|
type: "string",
|
|
41961
|
-
default: DOT_GITHUB_REPO,
|
|
41962
|
-
describe: `Target org/repo (default: ${DOT_GITHUB_REPO})`
|
|
42242
|
+
default: DOT_GITHUB_REPO$1,
|
|
42243
|
+
describe: `Target org/repo (default: ${DOT_GITHUB_REPO$1})`
|
|
41963
42244
|
}).option("branch", {
|
|
41964
42245
|
type: "string",
|
|
41965
42246
|
describe: "Push to this branch instead of the default branch (enables PR-based workflow for protected repos)"
|
|
@@ -41969,7 +42250,7 @@ const syncGithubArgs = (y) => y.option("repo", {
|
|
|
41969
42250
|
describe: "Open a PR after pushing to --branch (no-op without --branch)"
|
|
41970
42251
|
}).option("message", {
|
|
41971
42252
|
type: "string",
|
|
41972
|
-
describe: `Commit message (default: chore: sync from ${HOLOCRON_REPO})`
|
|
42253
|
+
describe: `Commit message (default: chore: sync from ${HOLOCRON_REPO$1})`
|
|
41973
42254
|
}).option("output-dir", {
|
|
41974
42255
|
type: "string",
|
|
41975
42256
|
describe: "Write generated files to this local directory instead of pushing (for validation)"
|