@runeditrun/rer 0.2.30 → 0.2.31
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 +16 -0
- package/cli/README.md +17 -0
- package/cli/business/command.mjs +27 -0
- package/cli/business/detector.mjs +42 -0
- package/cli/business/parsers-config.mjs +91 -0
- package/cli/business/parsers-infrastructure.mjs +68 -0
- package/cli/business/parsers-packages.mjs +84 -0
- package/cli/business/parsers-pulumi.mjs +64 -0
- package/cli/business/parsers-syntax.mjs +113 -0
- package/cli/business/parsers-terraform.mjs +53 -0
- package/cli/business/parsers.mjs +62 -0
- package/cli/business/policy.mjs +46 -0
- package/cli/business/scan.mjs +67 -0
- package/cli/contract.mjs +1 -1
- package/cli/main.mjs +1 -0
- package/cli/release.mjs +5 -2
- package/global/CHANGELOG.md +17 -0
- package/global/README.md +16 -0
- package/global/main.mjs +3 -0
- package/modules/owner-claim/verify.d.mts +5 -0
- package/modules/release/README.md +11 -1
- package/modules/release/github-verify.mjs +30 -26
- package/modules/release/produce.mjs +2 -2
- package/modules/release/source-verification.mjs +2 -2
- package/modules/release/verify-workflow.mjs +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -296,3 +296,19 @@ No global package manager installation or sudo is needed. Independent projects
|
|
|
296
296
|
continue to run their declared commands with their own tools. Server and job
|
|
297
297
|
state default to `$HOME/.rer/servers` and `$HOME/.rer/jobs`; supplied
|
|
298
298
|
`RER_SERVERS_DIR` and `RER_JOBS_DIR` take precedence and are passed to older pins.
|
|
299
|
+
|
|
300
|
+
## Inspect local business signals
|
|
301
|
+
|
|
302
|
+
`rer business scan [DIR...] [--json]` scans the current directory or the named
|
|
303
|
+
local directories without installing dependencies, executing project code or
|
|
304
|
+
using the network. It works outside RER checkouts. Both forms print one JSON
|
|
305
|
+
document: `{schema: "rer-business-signals/1", source: "local", signals: [...],
|
|
306
|
+
withheld: N}`. Signals identify package, environment, CI, infrastructure and
|
|
307
|
+
configuration names with a relative `locator`, repository basename `repo`,
|
|
308
|
+
`class` (`live-use` or `trace`) and `observedAt`.
|
|
309
|
+
|
|
310
|
+
Only names leave the scanner. Secret files are never opened and contribute
|
|
311
|
+
`secret-file` metadata (filename, path, size and modification time).
|
|
312
|
+
Sensitive-looking outbound names are dropped and counted in `withheld`.
|
|
313
|
+
Symlinks, generated outputs and dependency trees are skipped; unsupported
|
|
314
|
+
formats and syntax may yield no signals.
|
package/cli/README.md
CHANGED
|
@@ -336,3 +336,20 @@ or deploy hook. Failure reports distinguish deployment, owner claim and token
|
|
|
336
336
|
retirement and preserve the environment, checkout and env-file in recovery
|
|
337
337
|
commands. Retirement can be finished with `rer deploy --unset-secret SETUP_TOKEN`
|
|
338
338
|
plus the same `--environment`, `--env-file` and `--cwd` arguments.
|
|
339
|
+
|
|
340
|
+
## Local business signals
|
|
341
|
+
|
|
342
|
+
`rer business scan [DIR...] [--json]` reads local source and configuration names;
|
|
343
|
+
with no directories it scans the current directory. It needs no RER project
|
|
344
|
+
declaration, dependency installation, network access or command execution.
|
|
345
|
+
Both forms write one JSON document with schema `rer-business-signals/1`,
|
|
346
|
+
`source: "local"`, a `signals` array and a numeric `withheld` count. Each signal
|
|
347
|
+
has `kind`, `value` (a name), relative `locator`, repository basename `repo`,
|
|
348
|
+
`class` (`live-use` or `trace` for examples/comments), and `observedAt`.
|
|
349
|
+
|
|
350
|
+
This is names-only discovery: configuration values and file contents are not
|
|
351
|
+
emitted. Denied secret files are never opened; their `secret-file` observations
|
|
352
|
+
contain only the filename, path, size and modification time. Sensitive-looking
|
|
353
|
+
outbound names are dropped entirely and counted in `withheld`. Symlinks, build
|
|
354
|
+
outputs and dependency trees are skipped. Unsupported syntax yields no signal;
|
|
355
|
+
an empty result is not proof that a repository has no business dependencies.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { scan } from './scan.mjs';
|
|
2
|
+
|
|
3
|
+
const usage = 'Usage: rer business scan [DIR...] [--json]\nNames-only local discovery; returns rer-business-signals/1 JSON. No network calls.\n';
|
|
4
|
+
|
|
5
|
+
export async function businessCommand(argv) {
|
|
6
|
+
if (!argv.length || argv.length === 1 && ['--help', '-h'].includes(argv[0]) || argv[0] === 'scan' && argv.slice(1).some(arg => ['--help', '-h'].includes(arg))) {
|
|
7
|
+
process.stdout.write(usage); return 0;
|
|
8
|
+
}
|
|
9
|
+
if (argv[0] !== 'scan') { process.stderr.write(usage); return 2; }
|
|
10
|
+
const directories = [];
|
|
11
|
+
let positional = false, json = false;
|
|
12
|
+
for (const arg of argv.slice(1)) {
|
|
13
|
+
if (!positional && arg === '--') { positional = true; continue; }
|
|
14
|
+
if (!positional && arg === '--json' && !json) { json = true; continue; }
|
|
15
|
+
if (!positional && arg.startsWith('-') || !arg.trim()) { process.stderr.write(usage); return 2; }
|
|
16
|
+
directories.push(arg);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const result = await scan(directories.length ? directories : [process.cwd()]);
|
|
20
|
+
process.stdout.write(JSON.stringify(result) + '\n');
|
|
21
|
+
return 0;
|
|
22
|
+
} catch {
|
|
23
|
+
// Node/format errors can contain input paths, keys or source excerpts.
|
|
24
|
+
process.stderr.write('Business scan could not read a local input. No scan document was emitted.\n');
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Inspect every outbound string, including locators and repository names. There
|
|
2
|
+
// is no diagnostic containing a match, and no value-masking stage.
|
|
3
|
+
const shapes = [
|
|
4
|
+
/-----\s*BEGIN\b/i,
|
|
5
|
+
/(?:sk_live_|rk_live_|AKIA|ghp_|gho_|github_pat_|xox[abpr]-)/,
|
|
6
|
+
/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/,
|
|
7
|
+
/\b(?:ssh-(?:rsa|ed25519)|ecdsa-sha2-[\w-]+)\s+[A-Za-z0-9+/=]+/,
|
|
8
|
+
/\bMII[A-Za-z0-9+/]{40,}={0,2}/,
|
|
9
|
+
/(?:^|[^a-z])(?:TunnelSecret|TunnelID|AccountTag)(?:$|[^a-z])/i,
|
|
10
|
+
/[\u0000-\u001f\u007f]/,
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function entropy(value) {
|
|
14
|
+
const counts = new Map();
|
|
15
|
+
for (const char of value) counts.set(char, (counts.get(char) ?? 0) + 1);
|
|
16
|
+
let bits = 0;
|
|
17
|
+
for (const count of counts.values()) { const p = count / value.length; bits -= p * Math.log2(p); }
|
|
18
|
+
return bits;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function highEntropy(text, tokens) {
|
|
22
|
+
for (const match of text.matchAll(tokens)) {
|
|
23
|
+
const value = match[0];
|
|
24
|
+
if (/^[a-f\d]{32,}$/i.test(value) && entropy(value.toLowerCase()) >= 3.5) return true;
|
|
25
|
+
if (entropy(value) >= 4.2) return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function sensitive(text) {
|
|
31
|
+
return shapes.some(pattern => pattern.test(text)) || highEntropy(text, /[A-Za-z0-9_+\/=\-]{24,}/g);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function sensitivePath(path) {
|
|
35
|
+
// Keep shape checks across the full path, but never combine ordinary path
|
|
36
|
+
// segments into an apparent high-entropy credential.
|
|
37
|
+
return shapes.some(pattern => pattern.test(path)) ||
|
|
38
|
+
path.split('/').some(part => highEntropy(part, /[A-Za-z0-9_+=\-]{24,}/g));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const blockedSignal = signal => Object.entries(signal).some(([key, value]) =>
|
|
42
|
+
typeof value === 'string' && (key === 'locator' || key === 'repo' ? sensitivePath(value) : sensitive(value)));
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { flowEntries, keyParts, literal, splitOutside } from './parsers-syntax.mjs';
|
|
2
|
+
|
|
3
|
+
export function yamlEntries(source) {
|
|
4
|
+
const entries = [], stack = [];
|
|
5
|
+
let blockIndent, multilineQuote = '';
|
|
6
|
+
for (const line of source.split(/\r?\n/)) {
|
|
7
|
+
if (multilineQuote) { multilineQuote = remainingQuote(line, multilineQuote); continue; }
|
|
8
|
+
if (!line.trim() || /^\s*(?:---|\.\.\.)\s*$/.test(line)) continue;
|
|
9
|
+
const indent = /^ */.exec(line)[0].length;
|
|
10
|
+
if (blockIndent !== undefined) { if (indent > blockIndent) continue; blockIndent = undefined; }
|
|
11
|
+
while (stack.length && indent <= stack.at(-1).indent) stack.pop();
|
|
12
|
+
let raw = line.trim(), path = stack.at(-1)?.path ?? [], keyIndent = indent;
|
|
13
|
+
if (raw.startsWith('- ')) {
|
|
14
|
+
path = [...path, '[]']; raw = raw.slice(2).trim(); keyIndent += 2;
|
|
15
|
+
stack.push({ indent, path });
|
|
16
|
+
}
|
|
17
|
+
if (raw.startsWith('{') || raw.startsWith('[')) { flowEntries(raw, path, ':', entries); continue; }
|
|
18
|
+
const parts = splitOutside(raw, ':');
|
|
19
|
+
if (parts.length < 2 || !/^\s/.test(parts[1]) && parts[1] !== '') {
|
|
20
|
+
if (path.at(-1) === '[]') entries.push({ path, value: literal(raw) });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const keys = keyParts(parts.shift()); if (!keys) continue;
|
|
24
|
+
const child = [...path, ...keys], value = parts.join(':').trim();
|
|
25
|
+
entries.push({ path: child, value: literal(value) });
|
|
26
|
+
if (/^["']/.test(value)) { multilineQuote = remainingQuote(value); if (multilineQuote) continue; }
|
|
27
|
+
if (/^[|>][+-]?[0-9]?$|^[|>][0-9][+-]?$/.test(value)) { blockIndent = keyIndent; continue; }
|
|
28
|
+
if (!value || /^(?:&[A-Za-z0-9_-]+|![^ ]+)\s*$/.test(value)) stack.push({ indent: keyIndent, path: child });
|
|
29
|
+
else flowEntries(value, child, ':', entries);
|
|
30
|
+
}
|
|
31
|
+
return entries;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function remainingQuote(source, initial = '') {
|
|
35
|
+
let quote = initial;
|
|
36
|
+
for (let i = 0; i < source.length; i++) {
|
|
37
|
+
const char = source[i];
|
|
38
|
+
if (quote) {
|
|
39
|
+
if (char === '\\' && quote === '"') i++;
|
|
40
|
+
else if (char === quote) {
|
|
41
|
+
if (quote === "'" && source[i + 1] === "'") i++;
|
|
42
|
+
else quote = '';
|
|
43
|
+
}
|
|
44
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
45
|
+
}
|
|
46
|
+
return quote;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function statements(source) {
|
|
50
|
+
const result = []; let current = '', quote = '', depth = 0, triple = false;
|
|
51
|
+
for (let i = 0; i < source.length; i++) {
|
|
52
|
+
const char = source[i]; current += char;
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (char === '\\' && quote === '"') { current += source[++i] ?? ''; }
|
|
55
|
+
else if (triple && source.slice(i, i + 3) === quote.repeat(3)) { current += source.slice(i + 1, i + 3); i += 2; quote = ''; triple = false; }
|
|
56
|
+
else if (!triple && char === quote) quote = '';
|
|
57
|
+
} else if (char === '"' || char === "'") {
|
|
58
|
+
quote = char;
|
|
59
|
+
if (source.slice(i, i + 3) === char.repeat(3)) { triple = true; current += source.slice(i + 1, i + 3); i += 2; }
|
|
60
|
+
} else if (char === '[' || char === '{') depth++;
|
|
61
|
+
else if (char === ']' || char === '}') depth--;
|
|
62
|
+
else if (char === '\n' && depth === 0) { result.push(current.trim()); current = ''; }
|
|
63
|
+
}
|
|
64
|
+
if (current.trim()) result.push(current.trim()); return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function tomlEntries(source) {
|
|
68
|
+
const entries = []; let table = [];
|
|
69
|
+
for (const statement of statements(source)) {
|
|
70
|
+
const header = /^(\[\[?)([\s\S]*?)(\]\]?)$/.exec(statement);
|
|
71
|
+
if (header && header[1].length === header[3].length) {
|
|
72
|
+
table = keyParts(header[2], true) ?? [];
|
|
73
|
+
if (table.length) {
|
|
74
|
+
entries.push({ path: table, value: undefined });
|
|
75
|
+
if (header[1] === '[[') table = [...table, '[]'];
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const parts = splitOutside(statement, '='); if (parts.length < 2) continue;
|
|
80
|
+
const keys = keyParts(parts.shift(), true); if (!keys) continue;
|
|
81
|
+
const path = [...table, ...keys], raw = parts.join('=').trim();
|
|
82
|
+
entries.push({ path, value: literal(raw) }); flowEntries(raw, path, '=', entries);
|
|
83
|
+
}
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function configNames(entries, add) {
|
|
88
|
+
for (const { path } of entries) {
|
|
89
|
+
if (path.at(-1) !== '[]') add('config-key', path.join('.'));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { identifier } from './parsers-syntax.mjs';
|
|
2
|
+
import { terraformNames } from './parsers-terraform.mjs';
|
|
3
|
+
|
|
4
|
+
function registryHost(image) {
|
|
5
|
+
if (typeof image !== 'string' || /[\s?#\\]|:\/\//.test(image)) return undefined;
|
|
6
|
+
const slash = image.indexOf('/'); if (slash < 1) return undefined;
|
|
7
|
+
const first = image.slice(0, slash); if (first.includes('@')) return undefined;
|
|
8
|
+
// Docker interprets a dotted first component, localhost or a host:port as
|
|
9
|
+
// an explicit registry. An unqualified image does not identify a registry.
|
|
10
|
+
if (!first.includes('.') && first !== 'localhost' && !first.includes(':')) return undefined;
|
|
11
|
+
const host = first.replace(/:[0-9]{1,5}$/, '');
|
|
12
|
+
if (first !== host && !/^\d{1,5}$/.test(first.slice(host.length + 1))) return undefined;
|
|
13
|
+
if (host === 'localhost' || (host.length <= 253 && host.split('.').every(label => /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(label)))) return host.toLowerCase();
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function ciNames(source, entries, add) {
|
|
18
|
+
for (const match of source.matchAll(/\b(?:secrets|vars)\s*(?:\.\s*([A-Za-z_][A-Za-z0-9_]*)|\[\s*(["'])([A-Za-z_][A-Za-z0-9_]*)\2\s*\])/g)) add('ci-secret', match[1] ?? match[3]);
|
|
19
|
+
for (const { path, value } of entries) {
|
|
20
|
+
const parent = path.at(-2), key = path.at(-1);
|
|
21
|
+
if (['env', 'environment', 'variables', 'secrets'].includes(parent) && identifier.test(key)) add('ci-secret', key);
|
|
22
|
+
if (parent === '[]' && ['env', 'variables'].includes(path.at(-3))) {
|
|
23
|
+
if (key === 'name' && typeof value === 'string' && identifier.test(value)) add('ci-secret', value);
|
|
24
|
+
}
|
|
25
|
+
if (key === '[]' && path.some(part => ['env', 'environment', 'variables'].includes(part)) && typeof value === 'string') {
|
|
26
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(value); if (match) add('ci-secret', match[1]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function infrastructureDocument(pathname, entries) {
|
|
32
|
+
return /\.(?:tf|hcl|tf\.json)$/i.test(pathname)
|
|
33
|
+
|| /(?:^|\/)(?:charts?|helm)\//i.test(pathname)
|
|
34
|
+
|| /(?:^|\/)Pulumi[^/]*\.(?:ya?ml|json)$/i.test(pathname)
|
|
35
|
+
|| entries.some(({ path }) => path.length === 1 && path[0] === 'Resources')
|
|
36
|
+
|| entries.some(({ path }) => path.at(-1) === 'apiVersion') && entries.some(({ path }) => path.at(-1) === 'kind');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function infrastructureNames(pathname, source, entries, ci, add) {
|
|
40
|
+
if (ci) ciNames(source, entries, add);
|
|
41
|
+
if (/\.(?:tf|hcl)$/i.test(pathname)) terraformNames(source, add);
|
|
42
|
+
const kubernetes = new Set(entries.filter(entry => entry.path.at(-1) === 'apiVersion').map(entry => entry.path.slice(0, -1).join('\0')));
|
|
43
|
+
const images = ci || infrastructureDocument(pathname, entries);
|
|
44
|
+
for (const { path, value } of entries) {
|
|
45
|
+
if (/\.tf\.json$/i.test(pathname)) {
|
|
46
|
+
if (path[0] === 'provider' && path.length === 2) add('iac-provider', path[1]);
|
|
47
|
+
if (['resource', 'data'].includes(path[0]) && path.length === 2) add('iac-resource', path[1]);
|
|
48
|
+
if (path.includes('required_providers') && path.at(-1) === 'source' && typeof value === 'string'
|
|
49
|
+
&& /^[A-Za-z0-9][A-Za-z0-9_.-]*(?:\/[A-Za-z0-9][A-Za-z0-9_.-]*){1,2}$/.test(value)) add('iac-provider', value);
|
|
50
|
+
}
|
|
51
|
+
if (typeof value !== 'string') continue;
|
|
52
|
+
const key = path.at(-1);
|
|
53
|
+
if (key === 'kind' && kubernetes.has(path.slice(0, -1).join('\0')) && /^[A-Za-z][A-Za-z0-9]*$/.test(value)) add('iac-resource', value);
|
|
54
|
+
if (/^(?:Type|type)$/.test(key)) {
|
|
55
|
+
if (path[0] === 'Resources' && path.length === 3 && /^[A-Za-z][A-Za-z0-9]*::[A-Za-z][A-Za-z0-9]*::[A-Za-z][A-Za-z0-9]*$/.test(value)) add('iac-resource', value);
|
|
56
|
+
if (path[0] === 'resources' && path.length === 3 && /(?:^|\/)Pulumi[^/]*\.(?:ya?ml|json)$/i.test(pathname) && /^[A-Za-z][A-Za-z0-9_-]*:[A-Za-z0-9_./-]*:[A-Za-z][A-Za-z0-9_]*$/.test(value)) {
|
|
57
|
+
const provider = /^pulumi:providers:([A-Za-z][A-Za-z0-9_-]*)$/.exec(value);
|
|
58
|
+
add(provider ? 'iac-provider' : 'iac-resource', provider?.[1] ?? value);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (images && (key === 'image' || (key === 'repository' && path.includes('image')))) {
|
|
62
|
+
const host = registryHost(value); if (host) add('iac-provider', host);
|
|
63
|
+
}
|
|
64
|
+
if (images && key === 'registry' && path.includes('image')) {
|
|
65
|
+
const host = registryHost(`${value}/_`); if (host) add('iac-provider', host);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { identifier, literal, packageName, splitOutside } from './parsers-syntax.mjs';
|
|
2
|
+
|
|
3
|
+
function requirement(value) {
|
|
4
|
+
// In a direct reference, only the package before @ is a name. Bare URLs,
|
|
5
|
+
// editable paths, index options and includes are deliberately not followed.
|
|
6
|
+
const match = /^([A-Za-z0-9][A-Za-z0-9._-]*)(?=\s*(?:\[|[<>=!~;@]|\(|$))/.exec(value.trim());
|
|
7
|
+
return match?.[1];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function jsonDependencies(source, sections, add) {
|
|
11
|
+
let manifest;
|
|
12
|
+
try { manifest = JSON.parse(source); } catch { return; }
|
|
13
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return;
|
|
14
|
+
for (const section of sections) {
|
|
15
|
+
const dependencies = manifest[section];
|
|
16
|
+
if (!dependencies || typeof dependencies !== 'object' || Array.isArray(dependencies)) continue;
|
|
17
|
+
for (const name of Object.keys(dependencies)) if (packageName.test(name)) add('package', name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function cargoDependencies(source, add) {
|
|
22
|
+
let dependencyTable = false;
|
|
23
|
+
for (const line of source.split(/\r?\n/)) {
|
|
24
|
+
const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
|
|
25
|
+
if (header) {
|
|
26
|
+
const table = header[1].trim();
|
|
27
|
+
dependencyTable = /(?:^|\.)(?:dependencies|dev-dependencies|build-dependencies)$/.test(table);
|
|
28
|
+
const detail = /(?:^|\.)(?:dependencies|dev-dependencies|build-dependencies)\.([A-Za-z0-9_-]+)$/.exec(table);
|
|
29
|
+
if (detail) add('package', detail[1]);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (!dependencyTable) continue;
|
|
33
|
+
const parts = splitOutside(line, '='); if (parts.length < 2) continue;
|
|
34
|
+
const name = literal(parts.shift()); if (!name || !packageName.test(name)) continue;
|
|
35
|
+
// Cargo renames name a different package explicitly inside an inline table.
|
|
36
|
+
const renamed = /(?:^|[,\s{])package\s*=\s*(["'])([A-Za-z0-9_-]+)\1/.exec(parts.join('='));
|
|
37
|
+
add('package', renamed?.[2] ?? name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function goDependencies(source, add) {
|
|
42
|
+
let group = false;
|
|
43
|
+
const name = '[A-Za-z0-9][A-Za-z0-9._~-]*(?:/[A-Za-z0-9][A-Za-z0-9._~-]*)+';
|
|
44
|
+
for (const line of source.split(/\r?\n/)) {
|
|
45
|
+
if (/^\s*require\s*\(\s*$/.test(line)) { group = true; continue; }
|
|
46
|
+
if (group && /^\s*\)\s*$/.test(line)) { group = false; continue; }
|
|
47
|
+
const match = new RegExp(group ? `^\\s*(${name})\\s+v[^\\s]+\\s*$` : `^\\s*require\\s+(${name})\\s+v[^\\s]+\\s*$`).exec(line);
|
|
48
|
+
if (match) add('package', match[1]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function packageNames(filename, source, entries, add) {
|
|
53
|
+
if (filename === 'package.json') {
|
|
54
|
+
jsonDependencies(source, ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'], add);
|
|
55
|
+
} else if (filename === 'composer.json') {
|
|
56
|
+
jsonDependencies(source, ['require', 'require-dev'], add);
|
|
57
|
+
} else if (/^requirements[^/]*\.txt$/.test(filename)) {
|
|
58
|
+
for (const line of source.split(/\r?\n/)) { const name = requirement(line); if (name) add('package', name); }
|
|
59
|
+
} else if (filename === 'pyproject.toml') {
|
|
60
|
+
for (const { path, value } of entries) {
|
|
61
|
+
if (typeof value === 'string' && ((path[0] === 'project' && path[1] === 'dependencies' && path[2] === '[]')
|
|
62
|
+
|| (path[0] === 'project' && path[1] === 'optional-dependencies' && path[3] === '[]'))) {
|
|
63
|
+
const name = requirement(value); if (name) add('package', name);
|
|
64
|
+
}
|
|
65
|
+
const poetry = path[0] === 'tool' && path[1] === 'poetry';
|
|
66
|
+
const dependencyIndex = poetry && (path[2] === 'dependencies' || path[2] === 'dev-dependencies') ? 3
|
|
67
|
+
: poetry && path[2] === 'group' && path[4] === 'dependencies' ? 5 : -1;
|
|
68
|
+
if (dependencyIndex !== -1 && path.length === dependencyIndex + 1 && path[dependencyIndex] !== 'python' && packageName.test(path[dependencyIndex])) add('package', path[dependencyIndex]);
|
|
69
|
+
}
|
|
70
|
+
} else if (filename === 'gemfile') {
|
|
71
|
+
for (const line of source.split(/\r?\n/)) {
|
|
72
|
+
const match = /^\s*gem\s*(?:\(\s*)?(["'])([A-Za-z0-9][A-Za-z0-9_.-]*)\1(?=\s*[,)]|\s*$)/.exec(line);
|
|
73
|
+
if (match) add('package', match[2]);
|
|
74
|
+
}
|
|
75
|
+
} else if (filename === 'go.mod') goDependencies(source, add);
|
|
76
|
+
else if (filename === 'cargo.toml') cargoDependencies(source, add);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function environmentNames(source, add) {
|
|
80
|
+
for (const line of source.split(/\r?\n/)) {
|
|
81
|
+
const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line);
|
|
82
|
+
if (match && identifier.test(match[1])) add('env-key', match[1]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Source support is deliberately limited to literal provider imports and calls
|
|
2
|
+
// through those imports. Nothing is imported, instantiated or executed.
|
|
3
|
+
export function pulumiNames(pathname, source, add) {
|
|
4
|
+
const aliases = new Map(), executable = maskStrings(source), maskedLines = executable.split(/\r?\n/), lines = source.split(/\r?\n/);
|
|
5
|
+
const register = (alias, provider) => {
|
|
6
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(alias) || !/^[a-z][a-z0-9_-]*$/.test(provider)) return;
|
|
7
|
+
if (provider === 'pulumi') return;
|
|
8
|
+
aliases.set(alias, provider); add('iac-provider', provider);
|
|
9
|
+
};
|
|
10
|
+
if (/\.[cm]?[jt]sx?$/i.test(pathname)) {
|
|
11
|
+
for (let index = 0; index < lines.length; index++) {
|
|
12
|
+
const line = lines[index]; if (!/^\s*(?:import|const|let|var)\b/.test(maskedLines[index])) continue;
|
|
13
|
+
const imported = /^\s*import\s+(?:\*\s+as\s+)?([A-Za-z_][A-Za-z0-9_]*)\s+from\s+(["'])@pulumi\/([a-z][a-z0-9_-]*)\2(?=\s*(?:;|$))/.exec(line);
|
|
14
|
+
if (imported) register(imported[1], imported[3]);
|
|
15
|
+
const required = /^\s*(?:const|let|var)\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*require\(\s*(["'])@pulumi\/([a-z][a-z0-9_-]*)\2\s*\)(?=\s*(?:;|$))/.exec(line);
|
|
16
|
+
if (required) register(required[1], required[3]);
|
|
17
|
+
}
|
|
18
|
+
} else if (/\.py$/i.test(pathname)) {
|
|
19
|
+
for (let index = 0; index < lines.length; index++) {
|
|
20
|
+
const line = lines[index]; if (!/^\s*(?:import|from)\b/.test(maskedLines[index])) continue;
|
|
21
|
+
const imported = /^\s*import\s+pulumi_([a-z][a-z0-9_]*)(?:\s+as\s+([A-Za-z_][A-Za-z0-9_]*))?\s*$/.exec(line);
|
|
22
|
+
if (imported) register(imported[2] ?? `pulumi_${imported[1]}`, imported[1]);
|
|
23
|
+
const from = /^\s*from\s+pulumi_([a-z][a-z0-9_]*)\s+import\s+([a-z][a-z0-9_]*)(?:\s+as\s+([A-Za-z_][A-Za-z0-9_]*))?\s*$/.exec(line);
|
|
24
|
+
if (from) register(from[3] ?? from[2], from[1]);
|
|
25
|
+
}
|
|
26
|
+
} else if (/\.go$/i.test(pathname)) {
|
|
27
|
+
let imports = false;
|
|
28
|
+
for (const line of source.split(/\r?\n/)) {
|
|
29
|
+
if (/^\s*import\s*\(\s*$/.test(line)) { imports = true; continue; }
|
|
30
|
+
if (/^\s*\)\s*$/.test(line)) imports = false;
|
|
31
|
+
const imported = new RegExp(`^\\s*${imports ? '' : 'import\\s+'}(?:([A-Za-z_][A-Za-z0-9_]*)\\s+)?"github\\.com/pulumi/pulumi-([a-z][a-z0-9_-]*)/sdk/(?:v[0-9]+/)?go/([A-Za-z0-9_/]+)"\\s*$`).exec(line);
|
|
32
|
+
if (imported) register(imported[1] ?? imported[3].split('/').at(-1), imported[2]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Mask all strings and heredocs before looking for constructor expressions.
|
|
36
|
+
// Otherwise a code example embedded in a description could become live use.
|
|
37
|
+
for (const match of executable.matchAll(/\b(?:new\s+)?([A-Za-z_][A-Za-z0-9_]*)((?:\.[A-Za-z_][A-Za-z0-9_]*)+)\s*\(/g)) {
|
|
38
|
+
if (!aliases.has(match[1])) continue;
|
|
39
|
+
const type = match[2].slice(1).split('.').at(-1);
|
|
40
|
+
if (/^[A-Z]/.test(type) && type !== 'Provider') add('iac-resource', `${match[1]}${match[2]}`);
|
|
41
|
+
}
|
|
42
|
+
if (/\.cs$/i.test(pathname)) {
|
|
43
|
+
for (const match of executable.matchAll(/\bnew\s+(Pulumi\.([A-Za-z][A-Za-z0-9_]*)(?:\.[A-Za-z][A-Za-z0-9_]*)+)\s*\(/g)) {
|
|
44
|
+
add('iac-provider', match[2]); if (!match[1].endsWith('.Provider')) add('iac-resource', match[1]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function maskStrings(source) {
|
|
50
|
+
let result = '', quote = '', triple = false;
|
|
51
|
+
for (let i = 0; i < source.length; i++) {
|
|
52
|
+
const char = source[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
result += char === '\n' ? '\n' : ' ';
|
|
55
|
+
if (char === '\\' && quote !== '`') { const next = source[++i]; result += next === '\n' ? '\n' : ' '; }
|
|
56
|
+
else if (triple && source.slice(i, i + 3) === quote.repeat(3)) { result += ' '; i += 2; quote = ''; triple = false; }
|
|
57
|
+
else if (!triple && char === quote) quote = '';
|
|
58
|
+
} else if (['"', "'", '`'].includes(char)) {
|
|
59
|
+
quote = char; result += ' ';
|
|
60
|
+
if (source.slice(i, i + 3) === char.repeat(3)) { triple = true; result += ' '; i += 2; }
|
|
61
|
+
} else result += char;
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// These readers describe syntax only. They never resolve a tag, alias, include,
|
|
2
|
+
// interpolation or executable expression. Unsupported syntax contributes no value.
|
|
3
|
+
export const identifier = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
|
|
4
|
+
export const packageName = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*(?:\/[a-z0-9][a-z0-9_.-]*)*$/i;
|
|
5
|
+
|
|
6
|
+
export function literal(source) {
|
|
7
|
+
const value = source.trim();
|
|
8
|
+
if (value.startsWith('"')) {
|
|
9
|
+
try { const parsed = JSON.parse(value); return typeof parsed === 'string' ? parsed : undefined; } catch { return undefined; }
|
|
10
|
+
}
|
|
11
|
+
if (value.startsWith("'")) return /^'(?:[^']|'')*'$/.test(value) ? value.slice(1, -1).replace(/''/g, "'") : undefined;
|
|
12
|
+
return /^[^\s\[\]{},#'"`]+$/.test(value) ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Keep offsets/newlines, so a removed comment cannot join adjacent tokens.
|
|
16
|
+
// In YAML/TOML, # starts comments; // only starts comments in JSON/HCL/code.
|
|
17
|
+
export function comments(source, slash = false) {
|
|
18
|
+
let clean = '', quote = '', block = false, comment = '';
|
|
19
|
+
const traces = [];
|
|
20
|
+
for (let i = 0; i < source.length; i++) {
|
|
21
|
+
const char = source[i], next = source[i + 1];
|
|
22
|
+
if (block) {
|
|
23
|
+
if (char === '*' && next === '/') { traces.push(comment); comment = ''; block = false; clean += ' '; i++; }
|
|
24
|
+
else { comment += char; clean += char === '\n' ? '\n' : ' '; }
|
|
25
|
+
} else if (quote) {
|
|
26
|
+
clean += char;
|
|
27
|
+
if (char === '\\' && quote !== "'") { clean += next ?? ''; i++; }
|
|
28
|
+
else if (char === quote) {
|
|
29
|
+
if (quote === "'" && next === "'") { clean += next; i++; }
|
|
30
|
+
else quote = '';
|
|
31
|
+
}
|
|
32
|
+
} else if (char === '"' || char === "'" || (slash && char === '`')) { quote = char; clean += char; }
|
|
33
|
+
else if (slash && char === '/' && next === '*') { block = true; clean += ' '; i++; }
|
|
34
|
+
else if (char === '#' || (slash && char === '/' && next === '/')) {
|
|
35
|
+
const start = i + (char === '#' ? 1 : 2);
|
|
36
|
+
let end = source.indexOf('\n', start); if (end === -1) end = source.length;
|
|
37
|
+
traces.push(source.slice(start, end)); clean += ' '.repeat(end - i); i = end - 1;
|
|
38
|
+
} else clean += char;
|
|
39
|
+
}
|
|
40
|
+
if (block) traces.push(comment);
|
|
41
|
+
return { clean, traces };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Split delimiters outside strings and flow collections. No regexp can safely
|
|
45
|
+
// split an inline table containing a quoted comma or colon.
|
|
46
|
+
export function splitOutside(source, delimiter) {
|
|
47
|
+
const result = []; let start = 0, quote = '', depth = 0;
|
|
48
|
+
for (let i = 0; i < source.length; i++) {
|
|
49
|
+
const char = source[i];
|
|
50
|
+
if (quote) {
|
|
51
|
+
if (char === '\\' && quote === '"') i++;
|
|
52
|
+
else if (char === quote) {
|
|
53
|
+
if (quote === "'" && source[i + 1] === "'") i++;
|
|
54
|
+
else quote = '';
|
|
55
|
+
}
|
|
56
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
57
|
+
else if (char === '[' || char === '{') depth++;
|
|
58
|
+
else if (char === ']' || char === '}') depth--;
|
|
59
|
+
else if (char === delimiter && depth === 0) { result.push(source.slice(start, i)); start = i + 1; }
|
|
60
|
+
}
|
|
61
|
+
result.push(source.slice(start)); return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function keyParts(source, dotted = false) {
|
|
65
|
+
const pieces = dotted ? splitOutside(source, '.') : [source];
|
|
66
|
+
const result = pieces.map(piece => {
|
|
67
|
+
const trimmed = piece.trim(), value = literal(trimmed);
|
|
68
|
+
return value && (/^["']/.test(trimmed) || identifier.test(value)) ? value : undefined;
|
|
69
|
+
});
|
|
70
|
+
return result.length && result.every(part => part !== undefined) ? result : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function flowEntries(source, path, delimiter, entries, depth = 0) {
|
|
74
|
+
if (depth > 48) return;
|
|
75
|
+
const value = source.trim();
|
|
76
|
+
if (value.startsWith('{') && value.endsWith('}')) {
|
|
77
|
+
for (const pair of splitOutside(value.slice(1, -1), ',')) {
|
|
78
|
+
const parts = splitOutside(pair, delimiter); if (parts.length < 2) continue;
|
|
79
|
+
const keys = keyParts(parts.shift(), delimiter === '='); if (!keys) continue;
|
|
80
|
+
const child = [...path, ...keys], raw = parts.join(delimiter).trim();
|
|
81
|
+
entries.push({ path: child, value: literal(raw) }); flowEntries(raw, child, delimiter, entries, depth + 1);
|
|
82
|
+
}
|
|
83
|
+
} else if (value.startsWith('[') && value.endsWith(']')) {
|
|
84
|
+
for (const item of splitOutside(value.slice(1, -1), ',')) {
|
|
85
|
+
const child = [...path, '[]']; entries.push({ path: child, value: literal(item) });
|
|
86
|
+
flowEntries(item, child, delimiter, entries, depth + 1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function jsonEntries(source) {
|
|
92
|
+
let root;
|
|
93
|
+
try { root = JSON.parse(source); } catch { return []; }
|
|
94
|
+
const entries = [], pending = [{ value: root, path: [] }];
|
|
95
|
+
while (pending.length) {
|
|
96
|
+
const { value, path } = pending.pop(); if (path.length > 48) continue;
|
|
97
|
+
if (Array.isArray(value)) {
|
|
98
|
+
for (const child of value) {
|
|
99
|
+
const next = [...path, '[]']; entries.push({ path: next, value: typeof child === 'string' ? child : undefined });
|
|
100
|
+
if (child && typeof child === 'object') pending.push({ path: next, value: child });
|
|
101
|
+
}
|
|
102
|
+
} else if (value && typeof value === 'object') {
|
|
103
|
+
for (const [key, child] of Object.entries(value)) {
|
|
104
|
+
// JSON object keys are names, including quoted names with spaces. The
|
|
105
|
+
// caller applies its output detector to every candidate, including keys.
|
|
106
|
+
if (!key) continue;
|
|
107
|
+
const next = [...path, key]; entries.push({ path: next, value: typeof child === 'string' ? child : undefined });
|
|
108
|
+
if (child && typeof child === 'object') pending.push({ path: next, value: child });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return entries;
|
|
113
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
function tokens(source) {
|
|
2
|
+
const result = [];
|
|
3
|
+
for (let i = 0; i < source.length;) {
|
|
4
|
+
if (/\s/.test(source[i])) { i++; continue; }
|
|
5
|
+
if (source.slice(i, i + 2) === '<<') {
|
|
6
|
+
const marker = /^<<-?([A-Za-z_][A-Za-z0-9_]*)[^\S\n]*\r?\n/.exec(source.slice(i));
|
|
7
|
+
if (marker) {
|
|
8
|
+
i += marker[0].length;
|
|
9
|
+
while (i < source.length) {
|
|
10
|
+
let end = source.indexOf('\n', i); if (end === -1) end = source.length;
|
|
11
|
+
const line = source.slice(i, end).trim(); i = end + 1;
|
|
12
|
+
if (line === marker[1]) break;
|
|
13
|
+
}
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (source[i] === '"') {
|
|
18
|
+
let end = i + 1;
|
|
19
|
+
for (; end < source.length; end++) {
|
|
20
|
+
if (source[end] === '\\') end++;
|
|
21
|
+
else if (source[end] === '"') { end++; break; }
|
|
22
|
+
}
|
|
23
|
+
let value; try { value = JSON.parse(source.slice(i, end)); } catch { /* Opaque malformed string. */ }
|
|
24
|
+
result.push({ type: 'string', value }); i = end; continue;
|
|
25
|
+
}
|
|
26
|
+
const word = /^[A-Za-z_][A-Za-z0-9_-]*/.exec(source.slice(i));
|
|
27
|
+
if (word) { result.push({ type: 'word', value: word[0] }); i += word[0].length; }
|
|
28
|
+
else { result.push({ type: source[i], value: source[i] }); i++; }
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function terraformNames(source, add) {
|
|
34
|
+
const syntax = tokens(source), stack = [];
|
|
35
|
+
for (let i = 0; i < syntax.length; i++) {
|
|
36
|
+
const token = syntax[i];
|
|
37
|
+
if (token.type === '{') { stack.push(syntax[i - 1]?.value === 'required_providers'); continue; }
|
|
38
|
+
if (token.type === '}') { stack.pop(); continue; }
|
|
39
|
+
if (token.type !== 'word') continue;
|
|
40
|
+
if (['provider', 'resource', 'data'].includes(token.value) && syntax[i + 1]?.type === 'string') {
|
|
41
|
+
const label = syntax[i + 1].value, next = i + (token.value === 'provider' ? 2 : 3);
|
|
42
|
+
if (typeof label === 'string' && /^[A-Za-z][A-Za-z0-9_-]*$/.test(label) && syntax[next]?.type === '{'
|
|
43
|
+
&& (token.value === 'provider' || syntax[i + 2]?.type === 'string')) {
|
|
44
|
+
add(token.value === 'provider' ? 'iac-provider' : 'iac-resource', label);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (stack.at(-1) && syntax[i + 1]?.type === '=' && syntax[i + 2]?.type === '{') add('iac-provider', token.value);
|
|
48
|
+
if (stack.includes(true) && token.value === 'source' && syntax[i + 1]?.type === '=' && syntax[i + 2]?.type === 'string') {
|
|
49
|
+
const value = syntax[i + 2].value;
|
|
50
|
+
if (typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.-]*(?:\/[A-Za-z0-9][A-Za-z0-9_.-]*){1,2}$/.test(value)) add('iac-provider', value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { comments, jsonEntries } from './parsers-syntax.mjs';
|
|
2
|
+
import { configNames, tomlEntries, yamlEntries } from './parsers-config.mjs';
|
|
3
|
+
import { environmentNames, packageNames } from './parsers-packages.mjs';
|
|
4
|
+
import { infrastructureDocument, infrastructureNames } from './parsers-infrastructure.mjs';
|
|
5
|
+
import { pulumiNames } from './parsers-pulumi.mjs';
|
|
6
|
+
|
|
7
|
+
const examples = /(?:^|[/.\-_])(?:examples?|samples?|templates?|fixtures?)(?:[/.\-_]|$)/i;
|
|
8
|
+
const manifests = /^(?:package\.json|composer\.json|requirements[^/]*\.txt|pyproject\.toml|gemfile|go\.mod|cargo\.toml)$/;
|
|
9
|
+
const code = /\.(?:[cm]?[jt]sx?|py|go|cs)$/i;
|
|
10
|
+
|
|
11
|
+
function entriesFor(pathname, source) {
|
|
12
|
+
if (/\.jsonc?(?:\.(?:example|sample|template|tpl))?$/i.test(pathname)) return jsonEntries(source);
|
|
13
|
+
if (/\.toml(?:\.(?:example|sample|template|tpl))?$/i.test(pathname)) return tomlEntries(source);
|
|
14
|
+
if (/\.ya?ml(?:\.(?:example|sample|template|tpl))?$/i.test(pathname)) return yamlEntries(source);
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// No I/O, evaluation or diagnostics containing input. Each extractor emits a
|
|
19
|
+
// narrow syntactic name at its source, rather than redacting scalar values later.
|
|
20
|
+
export function parseNames(relativePath, text) {
|
|
21
|
+
if (typeof relativePath !== 'string' || typeof text !== 'string') return [];
|
|
22
|
+
const pathname = relativePath.replace(/\\/g, '/'), filename = pathname.split('/').at(-1).toLowerCase();
|
|
23
|
+
const ci = /(?:^|\/)(?:\.github\/workflows\/|\.circleci\/|\.gitlab-ci(?:[./-]|$)|azure-pipelines[./-]|\.travis[./-]|jenkinsfile$|bitbucket-pipelines[./-]|\.buildkite\/)/i.test(pathname);
|
|
24
|
+
const env = /(?:^|\/)(?:\.?env(?:[.\-_]|$)|[^/]*(?:env|config|settings)[^/]*(?:example|sample|template))/i.test(pathname);
|
|
25
|
+
const helm = /(?:^|\/)(?:charts?|helm)\/.*(?:^|\/)templates\//i.test(pathname)
|
|
26
|
+
|| /(?:^|\/)(?:charts?|helm)\/templates\//i.test(pathname);
|
|
27
|
+
const explicitExample = /(?:^|[/.\-_])(?:examples?|samples?|fixtures?)(?:[/.\-_]|$)/i.test(pathname);
|
|
28
|
+
const manifest = manifests.test(filename), classification = examples.test(pathname) && (!helm || explicitExample) ? 'trace' : 'live-use';
|
|
29
|
+
const result = [], seen = new Set();
|
|
30
|
+
const emit = evidenceClass => (kind, value) => {
|
|
31
|
+
if (typeof value !== 'string' || !value || value.length > 512 || /[\r\n\0]/.test(value)) return;
|
|
32
|
+
const key = `${evidenceClass}\0${kind}\0${value}`;
|
|
33
|
+
if (!seen.has(key)) { seen.add(key); result.push({ kind, value, class: evidenceClass }); }
|
|
34
|
+
};
|
|
35
|
+
const parse = (source, evidenceClass, isComment) => {
|
|
36
|
+
const entries = entriesFor(pathname, source);
|
|
37
|
+
const deployed = !isComment && !explicitExample && (ci || infrastructureDocument(pathname, entries));
|
|
38
|
+
const add = emit(deployed ? 'live-use' : evidenceClass);
|
|
39
|
+
if (manifest) packageNames(filename, source, entries, add);
|
|
40
|
+
if (env) environmentNames(source, add);
|
|
41
|
+
if (!manifest && !code.test(pathname)) configNames(entries, add);
|
|
42
|
+
infrastructureNames(pathname, source, entries, ci, add);
|
|
43
|
+
if (code.test(pathname)) pulumiNames(pathname, source, add);
|
|
44
|
+
// Commented-out env declarations are useful traces even in config files.
|
|
45
|
+
if (isComment && !manifest) environmentNames(source, add);
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
const templateTraces = [];
|
|
49
|
+
const templateClean = text.replace(/\{\{\s*\/\*([\s\S]*?)\*\/\s*\}\}/g, (whole, content) => {
|
|
50
|
+
templateTraces.push(content); return whole.replace(/[^\n]/g, ' ');
|
|
51
|
+
});
|
|
52
|
+
const { clean, traces } = comments(templateClean, filename === 'go.mod' || /\.(?:jsonc?|tf|hcl|[cm]?[jt]sx?|go|cs)(?:\.(?:example|sample|template|tpl))?$/i.test(pathname));
|
|
53
|
+
parse(clean, classification, false);
|
|
54
|
+
// Group consecutive comment lines so commented TOML/YAML sections retain
|
|
55
|
+
// their structural context. Comments never inherit live-use classification.
|
|
56
|
+
if (traces.length) parse(traces.join('\n'), 'trace', true);
|
|
57
|
+
for (const trace of templateTraces) parse(trace, 'trace', true);
|
|
58
|
+
} catch {
|
|
59
|
+
// Invalid/unsupported syntax is not permission to expose its scalar text.
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
|
|
3
|
+
const outputs = new Set(['node_modules', 'vendor', '.git', 'dist', 'build', 'target', 'coverage', '.next', '.nuxt', '.output', '.cache', '.venv', 'venv', '__pycache__', '.terraform', '.pulumi', '.wrangler', '.rer', '.seed', 'playwright-report', 'test-results']);
|
|
4
|
+
|
|
5
|
+
export const skipped = path => path.split('/').some(part => outputs.has(part.toLowerCase()));
|
|
6
|
+
|
|
7
|
+
const stores = new Set(['secrets', '.ssh', '.aws', '.gnupg', 'keychains', 'keychain', 'browser profiles', 'browser-profiles', '.mozilla', '.password-store', '.1password']);
|
|
8
|
+
|
|
9
|
+
function browserStore(path) {
|
|
10
|
+
// Recognize browser data locations, rather than projects or arbitrary
|
|
11
|
+
// directories named profiles, Firefox, Chromium or Safari.
|
|
12
|
+
return /(?:^|\/)\.config\/(?:google-chrome(?:-[^/]+)?|chromium|brave-browser|bravesoftware\/brave-browser|microsoft-edge(?:-[^/]+)?)(?:\/|$)/.test(path) ||
|
|
13
|
+
/(?:^|\/)library\/application support\/(?:google\/chrome(?: [^/]+)?|chromium|bravesoftware\/brave-browser|microsoft edge(?: [^/]+)?|firefox)(?:\/|$)/.test(path) ||
|
|
14
|
+
/(?:^|\/)appdata\/(?:local\/(?:google\/chrome|chromium|bravesoftware\/brave-browser|microsoft\/edge)\/user data|roaming\/mozilla\/firefox)(?:\/|$)/.test(path) ||
|
|
15
|
+
/(?:^|\/)library\/(?:safari|containers\/com\.apple\.safari|group containers\/[^/]*\.com\.apple\.safari)(?:\/|$)/.test(path);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function passwordExport(name) {
|
|
19
|
+
return /^(?:1password|bitwarden|lastpass|dashlane|keeper|enpass|nordpass|keepass)(?:[._ -](?:exports?|backups?|credentials?|passwords?|logins?).*)?\.(?:csv|json|zip|txt|xml)$/.test(name) ||
|
|
20
|
+
/^(?:password-manager|passwords?|vault|logins)[._ -](?:exports?|backups?)(?:[._ -].*)?\.(?:csv|json|zip|txt|xml)$/.test(name) ||
|
|
21
|
+
/^(?:passwords?|logins)\.csv$/.test(name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Specific stores apply to absolute ancestors, including those of explicit
|
|
25
|
+
// roots. Filename rules apply only to the file, never to its parent projects.
|
|
26
|
+
// Denied directories are enumerated for metadata only, never file content.
|
|
27
|
+
export function denied(path) {
|
|
28
|
+
const lower = path.toLowerCase(), name = basename(lower);
|
|
29
|
+
return lower.split('/').some(part => stores.has(part) || /\.(?:opvault|agilekeychain)$/.test(part)) || browserStore(lower) ||
|
|
30
|
+
/\.(?:pem|key|p12|pfx|keychain|keychain-db|kdbx|kdb|1pux|1pif|opvault|agilekeychain)$/.test(name) ||
|
|
31
|
+
/^id_/.test(name) || /^credentials/.test(name) || /^service-account.*\.json$/.test(name) ||
|
|
32
|
+
/^\.env/.test(name) && !/\.(?:example|sample)$/.test(name) ||
|
|
33
|
+
/^\.dev\.vars(?:$|\.)/.test(name) || /\.tfvars(?:\.json)?$/.test(name) || /kubeconfig/.test(name) || passwordExport(name);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const example = path => /(?:^|[./_-])(?:examples?|samples?|templates?)(?:[./_-]|$)/i.test(path);
|
|
37
|
+
|
|
38
|
+
// Only recognised source/config formats are opened. Executable IaC is lexed,
|
|
39
|
+
// never imported, and arbitrary documents and binary files are left untouched.
|
|
40
|
+
export function readable(path) {
|
|
41
|
+
const name = basename(path).toLowerCase();
|
|
42
|
+
return /\.(?:jsonc?|ya?ml|toml|tf|hcl)(?:\.(?:example|sample|template|tpl))?$/.test(name) ||
|
|
43
|
+
['gemfile', 'go.mod', 'jenkinsfile'].includes(name) || /^requirements.*\.txt$/.test(name) ||
|
|
44
|
+
example(path) && /(?:env|config|settings)/i.test(path) ||
|
|
45
|
+
/(?:^|\/)(?:pulumi[^/]*|infra(?:structure)?)(?:\/|\.)/i.test(path) && /\.(?:[cm]?[jt]s|tsx|py|go|cs)$/.test(name);
|
|
46
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, open, readdir, realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, join, relative, resolve, parse } from 'node:path';
|
|
4
|
+
import { blockedSignal } from './detector.mjs';
|
|
5
|
+
import { denied, example, readable, skipped } from './policy.mjs';
|
|
6
|
+
import { parseNames } from './parsers.mjs';
|
|
7
|
+
|
|
8
|
+
// Caller-named roots are canonicalized once; below them, refuse symlink
|
|
9
|
+
// ancestors as well as symlink entries before reading any file content.
|
|
10
|
+
async function plainAncestors(path) {
|
|
11
|
+
const root = parse(path).root;
|
|
12
|
+
let current = root;
|
|
13
|
+
for (const part of path.slice(root.length).split('/').filter(Boolean)) {
|
|
14
|
+
current = join(current, part);
|
|
15
|
+
if ((await lstat(current)).isSymbolicLink()) return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function namesFromFile(path, info, locator, pulumi) {
|
|
21
|
+
if (!readable(locator) && !(pulumi && /\.(?:[cm]?[jt]sx?|py|go|cs)$/i.test(locator))) return [];
|
|
22
|
+
// O_NOFOLLOW blocks a replaced leaf; compare the opened inode before reading.
|
|
23
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
24
|
+
try {
|
|
25
|
+
const opened = await file.stat();
|
|
26
|
+
if (!opened.isFile() || opened.ino !== info.ino || opened.dev !== info.dev || !await plainAncestors(dirname(path))) throw Error('Changed scan input');
|
|
27
|
+
return parseNames(locator, await file.readFile('utf8'));
|
|
28
|
+
} finally { await file.close(); }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function scan(directories) {
|
|
32
|
+
const result = { schema: 'rer-business-signals/1', source: 'local', signals: [], withheld: 0 };
|
|
33
|
+
const observedAt = new Date().toISOString(), seen = new Set();
|
|
34
|
+
const roots = [...new Set(directories.map(path => resolve(path)))];
|
|
35
|
+
function emit(signal) {
|
|
36
|
+
if (blockedSignal(signal)) { result.withheld++; return; }
|
|
37
|
+
result.signals.push(signal);
|
|
38
|
+
}
|
|
39
|
+
for (const requested of roots) {
|
|
40
|
+
const root = await realpath(requested);
|
|
41
|
+
const rootInfo = await lstat(root), base = rootInfo.isDirectory() ? root : dirname(root), repo = basename(base);
|
|
42
|
+
async function walk(path, pulumi = false) {
|
|
43
|
+
if (skipped(relative(root, path)) || seen.has(path)) return;
|
|
44
|
+
seen.add(path);
|
|
45
|
+
const info = await lstat(path);
|
|
46
|
+
if (info.isSymbolicLink()) return;
|
|
47
|
+
if (info.isDirectory()) {
|
|
48
|
+
const names = (await readdir(path)).sort();
|
|
49
|
+
pulumi ||= names.some(name => /^Pulumi\.ya?ml$/i.test(name));
|
|
50
|
+
for (const name of names) await walk(join(path, name), pulumi);
|
|
51
|
+
} else if (info.isFile()) {
|
|
52
|
+
const locator = relative(base, path).split('\\').join('/');
|
|
53
|
+
const common = { locator, repo, class: example(locator) ? 'trace' : 'live-use', observedAt };
|
|
54
|
+
// A caller-named store remains metadata-only even when it is an alias.
|
|
55
|
+
if (denied(path) || denied(join(requested, relative(root, path)))) {
|
|
56
|
+
emit({ kind: 'secret-file', value: basename(path), ...common, size: info.size, mtime: info.mtime.toISOString() });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const name of await namesFromFile(path, info, locator, pulumi)) {
|
|
60
|
+
emit({ ...common, kind: name.kind, value: name.value, class: name.class ?? common.class });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
await walk(root);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
package/cli/contract.mjs
CHANGED
|
@@ -26,5 +26,5 @@ export const demoVerb = Object.freeze({ flags: [...commonFlags, '--port', '--hos
|
|
|
26
26
|
// sign the owner in to, so no seed declares it and check does not ask for it.
|
|
27
27
|
export const signinVerb = Object.freeze({ flags: [...commonFlags, '--environment', '--env-file'], effects: 'A one-time sign-in link for the hosted owner, without mail. Uses the Cloudflare credentials that deployed --environment (default production; from the environment or --env-file) to write a single-use grant for the recorded owner into that deployment\'s auth database, then prints the link once to this terminal; it is never saved. The link works once, only for that owner, expires within 15 minutes, and its use is recorded in the owner\'s audit log. Signed in this way, the owner can correct a wrong email in settings.' });
|
|
28
28
|
export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
|
|
29
|
-
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
|
29
|
+
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
|
30
30
|
export const requiredHooks = ['preview', 'dependencies', 'build', 'migrate', 'start', 'health', 'owner', 'signIn', 'verify', 'deploy', 'portability', 'state', 'settings', 'input'];
|
package/cli/main.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { check, describe } from './inspect.mjs';
|
|
|
6
6
|
import { selectNodeRuntime } from './node-runtime.mjs';
|
|
7
7
|
|
|
8
8
|
export async function main(argv = process.argv.slice(2)) {
|
|
9
|
+
if (argv[0] === 'business') return (await import('./business/command.mjs')).businessCommand(argv.slice(1));
|
|
9
10
|
// Every runtime a seed's hooks start inherits this: Wrangler and the Cloudflare
|
|
10
11
|
// Vite plugin otherwise serve the Local Explorer, which reads and writes the
|
|
11
12
|
// store without the dev key.
|
package/cli/release.mjs
CHANGED
|
@@ -19,6 +19,9 @@ Without --tag, write a preview. This command never pushes, uploads or deploys.
|
|
|
19
19
|
--dry-run Run the real gates and suppress local tag creation.
|
|
20
20
|
--local-verify Run the seed's full verification locally instead of
|
|
21
21
|
requiring its exact commit's green GitHub Verify.
|
|
22
|
+
--verify-workflow NAME_OR_FILE
|
|
23
|
+
Override the seed's declared GitHub verification workflow
|
|
24
|
+
by name or file (case-insensitive).
|
|
22
25
|
--clean-history Prepare a parentless public export.
|
|
23
26
|
--onto GITHUB_URL#BRANCH
|
|
24
27
|
Prepare a public child of the destination's current branch;
|
|
@@ -53,8 +56,8 @@ export async function dispatchRelease(args) {
|
|
|
53
56
|
else if (args[index] === '--dry-run') options.dryRun = true;
|
|
54
57
|
else if (args[index] === '--allow-placeholder-mark') options.allowPlaceholderMark = true;
|
|
55
58
|
else if (args[index] === '--local-verify') options.localVerify = true;
|
|
56
|
-
else if (['--repo', '--project', '--repository', '--output', '--ref', '--env-file', '--onto', '--public-base'].includes(args[index]) && args[index + 1] && !args[index + 1].startsWith('--'))
|
|
57
|
-
options[args[index] === '--env-file' ? 'envFile' : args[index] === '--public-base' ? 'publicBase' : args[index].slice(2)] = args[++index];
|
|
59
|
+
else if (['--repo', '--project', '--repository', '--output', '--ref', '--env-file', '--onto', '--public-base', '--verify-workflow'].includes(args[index]) && args[index + 1] && !args[index + 1].startsWith('--'))
|
|
60
|
+
options[args[index] === '--env-file' ? 'envFile' : args[index] === '--public-base' ? 'publicBase' : args[index] === '--verify-workflow' ? 'verifyWorkflow' : args[index].slice(2)] = args[++index];
|
|
58
61
|
else throw Error('Invalid release arguments');
|
|
59
62
|
}
|
|
60
63
|
if(args.includes('--no-queue')){const {shared}=await import('./shared.mjs');const {commandPolicy}=await shared('queue.mjs');const policy=await commandPolicy();try{if(!policy.ci)throw Error('Original CI required');}finally{await policy.close();}}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.31
|
|
4
|
+
|
|
5
|
+
- **Each seed's verify workflow.** For a GitHub source, `rer release` takes the verify workflow from `--verify-workflow NAME_OR_FILE`. If that is absent, it uses the selected commit's `rer-project.json` `verifyWorkflow`, then `.github/workflows/verify.yml`/`verify.yaml`, then exactly one workflow named `verify`, in that order. Names, full file paths and basenames match case-insensitively. An explicit selection must resolve uniquely and never falls through. An ambiguous selection blocks and lists the candidates with the `--verify-workflow` remedy. The exact-SHA run checks are unchanged. `gates.verify` in the receipt and site provenance records `workflowFile`, `workflowName`, `workflowId`, `runId` and `runUrl`. `operations.verify` is unchanged.
|
|
6
|
+
- **`rer business scan [DIR...] [--json]`.** Names-only discovery of package, environment, CI, infrastructure and configuration names in local directories, outside RER checkouts too. It needs no install, project code or network. It prints one JSON document, `{schema: "rer-business-signals/1", source: "local", signals, withheld}`, and each signal has a relative `locator`, a `repo` basename, a `live-use`/`trace` class and `observedAt`. Secret files are never opened and contribute only filename, path, size and mtime. Sensitive-looking outbound names are dropped and counted in `withheld`.
|
|
7
|
+
- **Opt-in import door.** import-kit's `createImportDoorHandler` (`modules/import-kit/src/door/`) is a D1-only door that a seed may mount under POST `/api/rer/import/{uploads,plan,apply,status,reconcile,undo}`.
|
|
8
|
+
- It returns 404 until the owner opts in through `writeImportDoorSettings`.
|
|
9
|
+
- Every request needs a fresh single-use ES256 grant, lasting at most five minutes, from the owner-claim key ring.
|
|
10
|
+
- Uploads are resumable and SHA-256 checked. Plan makes no writes, and apply runs bounded batches bound to the owner's approved plan fingerprint.
|
|
11
|
+
- Bounded catch-up stays strictly below 5% of the baseline. Reconcile and owner undo are included.
|
|
12
|
+
- Base mounts it in no seed.
|
|
13
|
+
|
|
14
|
+
### Upgrade notes
|
|
15
|
+
|
|
16
|
+
- Update the exact rer package pin, or refresh vendored operating commands, to receive these changes.
|
|
17
|
+
- A seed whose verify workflow is not `verify.yml`/`verify.yaml` or named `verify` sets `"verifyWorkflow"` in `rer-project.json`, or passes `--verify-workflow`. It no longer needs `--local-verify` for a GitHub release.
|
|
18
|
+
- The import door is opt-in: a seed mounts the handler, applies `importDoorSchema` in a new numbered migration, and copies import-kit's `CONTRACT.md` and `src/door/README.md`. See "Optional grant-authorised import door" in SEED-COMMAND-CONTRACT.md.
|
|
19
|
+
|
|
3
20
|
## 0.2.30
|
|
4
21
|
|
|
5
22
|
- **Hosted demos run as native Workers.** `rer deploy --demo` gives each visitor their own Worker Loader isolate of the seed's ordinary production bundle, with SQLite Durable Object storage and static files served at the edge, instead of a Cloudflare Container. Docker and the Containers permission are no longer needed for a new demo host. Portable container hosting (`rer build`/`rer deploy --platform container`, Node/workerd and SSH) is unchanged; only the hosted-demo image, runtime and placement code are removed.
|
package/global/README.md
CHANGED
|
@@ -296,3 +296,19 @@ No global package manager installation or sudo is needed. Independent projects
|
|
|
296
296
|
continue to run their declared commands with their own tools. Server and job
|
|
297
297
|
state default to `$HOME/.rer/servers` and `$HOME/.rer/jobs`; supplied
|
|
298
298
|
`RER_SERVERS_DIR` and `RER_JOBS_DIR` take precedence and are passed to older pins.
|
|
299
|
+
|
|
300
|
+
## Inspect local business signals
|
|
301
|
+
|
|
302
|
+
`rer business scan [DIR...] [--json]` scans the current directory or the named
|
|
303
|
+
local directories without installing dependencies, executing project code or
|
|
304
|
+
using the network. It works outside RER checkouts. Both forms print one JSON
|
|
305
|
+
document: `{schema: "rer-business-signals/1", source: "local", signals: [...],
|
|
306
|
+
withheld: N}`. Signals identify package, environment, CI, infrastructure and
|
|
307
|
+
configuration names with a relative `locator`, repository basename `repo`,
|
|
308
|
+
`class` (`live-use` or `trace`) and `observedAt`.
|
|
309
|
+
|
|
310
|
+
Only names leave the scanner. Secret files are never opened and contribute
|
|
311
|
+
`secret-file` metadata (filename, path, size and modification time).
|
|
312
|
+
Sensitive-looking outbound names are dropped and counted in `withheld`.
|
|
313
|
+
Symlinks, generated outputs and dependency trees are skipped; unsupported
|
|
314
|
+
formats and syntax may yield no signals.
|
package/global/main.mjs
CHANGED
|
@@ -17,6 +17,8 @@ pins (installed first by any verb when node_modules holds another), else its ven
|
|
|
17
17
|
to 10 minutes on a first launch, or rerun it to reattach. rer dev --stop stops it.
|
|
18
18
|
rer list [DIR] The checkouts in DIR (default: here), newest first, with whether rer dev can
|
|
19
19
|
launch them, whether they are set up, and their running URL. --json for data.
|
|
20
|
+
rer business scan [DIR...] [--json]
|
|
21
|
+
Discover local package, config and infrastructure names without secret values.
|
|
20
22
|
rer door ... The opt-in front door: every checkout at http://NAME.localhost:PORT, started
|
|
21
23
|
on its first visit and stopped when idle. rer door --help for its verbs.
|
|
22
24
|
rer cli status This rer: version, contents digest, install channel, launcher and other rer
|
|
@@ -50,6 +52,7 @@ export async function main(argv) {
|
|
|
50
52
|
// verb never inherits it.
|
|
51
53
|
delete process.env[localDefaults];
|
|
52
54
|
if (verb === 'update') return (await import('./update/command.mjs')).update(argv.slice(1));
|
|
55
|
+
if (verb === 'business') return (await import('../cli/business/command.mjs')).businessCommand(argv.slice(1));
|
|
53
56
|
const notice = await import('./update/notice.mjs');
|
|
54
57
|
if (verb !== 'doctor' && notice.wantsNotice(argv)) await notice.updateNotice();
|
|
55
58
|
if (!verb || verb === '--help' || verb === '-h' || verb === 'help') { process.stdout.write(help); return 0; }
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { OwnerClaimConfig } from './index.mjs';
|
|
2
|
+
|
|
3
|
+
export type { OwnerClaim, OwnerClaimConfig } from './index.mjs';
|
|
4
|
+
export { OwnerClaimError, verifyOwnerClaim } from './index.mjs';
|
|
5
|
+
export function configureClaim(input: OwnerClaimConfig): Readonly<OwnerClaimConfig>;
|
|
@@ -56,9 +56,19 @@ it is independent of the publication destination. Only a completed successful
|
|
|
56
56
|
tag qualifies. The run and head repository must both match the source repository,
|
|
57
57
|
and a release tag must resolve remotely to the exact source commit. PR merge runs,
|
|
58
58
|
other SHAs, repositories, branches and unsuccessful runs cannot authorize release.
|
|
59
|
-
`gates.verify` records the source repository and commit,
|
|
59
|
+
`gates.verify` records the source repository and commit, `workflowId`,
|
|
60
|
+
`workflowFile`, `workflowName`, `runId`,
|
|
60
61
|
`runUrl`, event, branch and conclusion in both receipt and site provenance.
|
|
61
62
|
|
|
63
|
+
Workflow selection uses `--verify-workflow NAME_OR_FILE` first, then the
|
|
64
|
+
optional top-level `verifyWorkflow` from committed `rer-project.json`, then
|
|
65
|
+
`.github/workflows/verify.yml` or `verify.yaml`, then a single workflow named
|
|
66
|
+
`verify`. Names, full file paths and basenames match case-insensitively. For
|
|
67
|
+
example, `"verifyWorkflow": "Verify Slate"` or
|
|
68
|
+
`--verify-workflow .github/workflows/candidate.yml` selects a seed's own gate.
|
|
69
|
+
An explicit selection that is missing or ambiguous blocks; multiple conventional
|
|
70
|
+
files or matching names also block, naming the candidates and the flag.
|
|
71
|
+
|
|
62
72
|
CI is the verification wall: this path skips both local `verify` targets. It
|
|
63
73
|
still installs frozen dependencies and runs the committed `pnpm run build`
|
|
64
74
|
script, when declared, in a disposable clone. `gates.verify.install` and
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { git } from './source.mjs';
|
|
3
|
+
import { verifyWorkflow } from './verify-workflow.mjs';
|
|
3
4
|
|
|
4
5
|
const same = (left, right) => typeof left === 'string' && left.toLowerCase() === right.toLowerCase();
|
|
5
6
|
function identity(value) {
|
|
@@ -39,7 +40,7 @@ function tagCommit(repository, tag) {
|
|
|
39
40
|
return object?.type === 'commit' ? object.sha : null;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export function githubVerify(source, repository) {
|
|
43
|
+
export function githubVerify(source, repository, selector) {
|
|
43
44
|
const result = { status: 'FAIL', provider: 'github', repository, commit: source.commit,
|
|
44
45
|
reason: 'github-verify-not-successful',
|
|
45
46
|
message: `No successful Verify run exists for ${repository} at exact source commit ${source.commit}. Push this commit to the default branch or release tag, or re-run Verify for this SHA with workflow_dispatch. Use --local-verify to run verification locally.` };
|
|
@@ -47,35 +48,38 @@ export function githubVerify(source, repository) {
|
|
|
47
48
|
const metadata = api(`repos/${repository}`);
|
|
48
49
|
if (!same(metadata.full_name, repository) || typeof metadata.default_branch !== 'string' || !metadata.default_branch) throw Error('repository');
|
|
49
50
|
const workflows = api(`repos/${repository}/actions/workflows?per_page=100`, true)
|
|
50
|
-
.flatMap(page => page.workflows).filter(workflow =>
|
|
51
|
+
.flatMap(page => page.workflows).filter(workflow => Number.isSafeInteger(workflow.id));
|
|
52
|
+
const selected = verifyWorkflow(source, workflows, selector);
|
|
53
|
+
if (selected.error) return { ...result, details: selected.error };
|
|
54
|
+
const workflow = selected.workflow;
|
|
55
|
+
Object.assign(result, { workflowId: workflow.id, workflowFile: workflow.path, workflowName: workflow.name });
|
|
51
56
|
const rejected = new Set();
|
|
52
57
|
let checkedTag = false, tagSHA;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
rejected.add('different source repository'); continue;
|
|
60
|
-
}
|
|
61
|
-
if (run.workflow_id !== workflow.id) { rejected.add('different workflow'); continue; }
|
|
62
|
-
if (!['push', 'workflow_dispatch'].includes(run.event)) { rejected.add('event must be push or workflow_dispatch'); continue; }
|
|
63
|
-
if (run.status !== 'completed' || run.conclusion !== 'success') {
|
|
64
|
-
rejected.add(run.status === 'completed' ? `conclusion ${['failure', 'cancelled', 'skipped', 'timed_out', 'neutral', 'action_required', 'stale'].includes(run.conclusion) ? run.conclusion : 'not success'}` : 'run not completed');
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (run.head_branch !== metadata.default_branch) {
|
|
68
|
-
if (run.head_branch !== source.tag) { rejected.add('neither default branch nor release tag'); continue; }
|
|
69
|
-
if (!checkedTag) { tagSHA = tagCommit(repository, source.tag); checkedTag = true; }
|
|
70
|
-
if (tagSHA !== source.commit) { rejected.add('release tag points at a different commit'); continue; }
|
|
71
|
-
}
|
|
72
|
-
if (!Number.isSafeInteger(run.id) || run.id <= 0) throw Error('run');
|
|
73
|
-
return { status: 'PASS', provider: 'github', repository: metadata.full_name, commit: source.commit,
|
|
74
|
-
workflowId: workflow.id, runId: run.id, runUrl: `https://github.com/${metadata.full_name}/actions/runs/${run.id}`,
|
|
75
|
-
event: run.event, branch: run.head_branch, conclusion: run.conclusion };
|
|
58
|
+
const runs = api(`repos/${repository}/actions/workflows/${workflow.id}/runs?head_sha=${source.commit}&per_page=100`, true)
|
|
59
|
+
.flatMap(page => page.workflow_runs);
|
|
60
|
+
for (const run of runs) {
|
|
61
|
+
if (run.head_sha !== source.commit) { rejected.add('different source SHA'); continue; }
|
|
62
|
+
if (!same(run.repository?.full_name, repository) || !same(run.head_repository?.full_name, repository)) {
|
|
63
|
+
rejected.add('different source repository'); continue;
|
|
76
64
|
}
|
|
65
|
+
if (run.workflow_id !== workflow.id) { rejected.add('different workflow'); continue; }
|
|
66
|
+
if (!['push', 'workflow_dispatch'].includes(run.event)) { rejected.add('event must be push or workflow_dispatch'); continue; }
|
|
67
|
+
if (run.status !== 'completed' || run.conclusion !== 'success') {
|
|
68
|
+
rejected.add(run.status === 'completed' ? `conclusion ${['failure', 'cancelled', 'skipped', 'timed_out', 'neutral', 'action_required', 'stale'].includes(run.conclusion) ? run.conclusion : 'not success'}` : 'run not completed');
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (run.head_branch !== metadata.default_branch) {
|
|
72
|
+
if (run.head_branch !== source.tag) { rejected.add('neither default branch nor release tag'); continue; }
|
|
73
|
+
if (!checkedTag) { tagSHA = tagCommit(repository, source.tag); checkedTag = true; }
|
|
74
|
+
if (tagSHA !== source.commit) { rejected.add('release tag points at a different commit'); continue; }
|
|
75
|
+
}
|
|
76
|
+
if (!Number.isSafeInteger(run.id) || run.id <= 0) throw Error('run');
|
|
77
|
+
return { status: 'PASS', provider: 'github', repository: metadata.full_name, commit: source.commit,
|
|
78
|
+
workflowId: workflow.id, workflowFile: workflow.path, workflowName: workflow.name,
|
|
79
|
+
runId: run.id, runUrl: `https://github.com/${metadata.full_name}/actions/runs/${run.id}`,
|
|
80
|
+
event: run.event, branch: run.head_branch, conclusion: run.conclusion };
|
|
77
81
|
}
|
|
78
|
-
result.details =
|
|
82
|
+
result.details = rejected.size ? [...rejected].join('; ') : 'No runs found for this SHA.';
|
|
79
83
|
} catch {
|
|
80
84
|
result.reason = 'github-verify-unavailable';
|
|
81
85
|
result.details = 'GitHub Verify could not be resolved. Check gh authentication and repository access, then try again; no local verification was substituted.';
|
|
@@ -14,7 +14,7 @@ import { placeholderMarks, placeholderMessage } from '../../cli/placeholder-mark
|
|
|
14
14
|
// Failure output belongs to the private receipt, not the site preview.
|
|
15
15
|
const withoutOutput = gates => JSON.parse(JSON.stringify(gates, (key, value) => key === 'output' ? undefined : value));
|
|
16
16
|
|
|
17
|
-
export async function release({ repo, ref = 'HEAD', output, project, repository, dryRun = false, tag = false, cleanHistory: clean = false, envFile, onto, publicBase, localVerify = false, allowPlaceholderMark = false }) {
|
|
17
|
+
export async function release({ repo, ref = 'HEAD', output, project, repository, dryRun = false, tag = false, cleanHistory: clean = false, envFile, onto, publicBase, localVerify = false, allowPlaceholderMark = false, verifyWorkflow }) {
|
|
18
18
|
if (!/^[\w.-]+\/[\w.-]+$/.test(project ?? '')) throw Error('--project must be publisher/name');
|
|
19
19
|
if (!/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+(?:\.git)?$/i.test(repository ?? '')) throw Error('--repository must be a credential-free GitHub repository URL');
|
|
20
20
|
if (onto !== undefined && clean) throw Error('--onto and --clean-history are mutually exclusive');
|
|
@@ -47,7 +47,7 @@ export async function release({ repo, ref = 'HEAD', output, project, repository,
|
|
|
47
47
|
const checkout = resolve(temporary, 'seed');
|
|
48
48
|
git(source.repo, 'clone', '--no-hardlinks', '--no-checkout', '--', source.repo, checkout);
|
|
49
49
|
git(checkout, 'checkout', '--detach', source.commit);
|
|
50
|
-
const verify = await verifySource(source, checkout, localVerify);
|
|
50
|
+
const verify = await verifySource(source, checkout, localVerify, verifyWorkflow);
|
|
51
51
|
// Explicit clean-history publication scans every byte and ref of the actual
|
|
52
52
|
// parentless export. Exact-source releases classify against public history
|
|
53
53
|
// when available, retaining the selected source commit and tag identity.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { command, git } from './source.mjs';
|
|
2
2
|
import { githubSource, githubVerify } from './github-verify.mjs';
|
|
3
3
|
|
|
4
|
-
export async function verifySource(source, checkout, localVerify) {
|
|
4
|
+
export async function verifySource(source, checkout, localVerify, verifyWorkflow) {
|
|
5
5
|
const repository = localVerify ? null : githubSource(source);
|
|
6
|
-
const verify = repository ? githubVerify(source, repository) : null;
|
|
6
|
+
const verify = repository ? githubVerify(source, repository, verifyWorkflow) : null;
|
|
7
7
|
// Refuse missing CI evidence before spending time installing or building.
|
|
8
8
|
if (verify?.status === 'FAIL') return verify;
|
|
9
9
|
const install = await command('pnpm', ['install', '--frozen-lockfile'], checkout, { dependencies: true });
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const same = (left, right) => typeof left === 'string' && left.toLowerCase() === right.toLowerCase();
|
|
2
|
+
const filename = path => typeof path === 'string' ? path.split('/').at(-1) : undefined;
|
|
3
|
+
const describe = workflow => `${workflow.name} (${workflow.path ?? 'file unknown'})`;
|
|
4
|
+
|
|
5
|
+
// A selector is authoritative: a typo must never silently choose another gate.
|
|
6
|
+
export function verifyWorkflow(source, workflows, override) {
|
|
7
|
+
const declared = override === undefined && source.entries.has('rer-project.json')
|
|
8
|
+
? JSON.parse(source.bytes('rer-project.json')).verifyWorkflow : undefined;
|
|
9
|
+
const selector = override ?? declared;
|
|
10
|
+
let matches;
|
|
11
|
+
if (selector !== undefined) {
|
|
12
|
+
if (typeof selector !== 'string' || !selector.trim()) {
|
|
13
|
+
return { error: 'verifyWorkflow must be a nonempty workflow name or file; use --verify-workflow <name|file>.' };
|
|
14
|
+
}
|
|
15
|
+
matches = workflows.filter(workflow => same(workflow.name, selector) || same(workflow.path, selector) || same(filename(workflow.path), selector));
|
|
16
|
+
} else {
|
|
17
|
+
matches = workflows.filter(workflow => ['.github/workflows/verify.yml', '.github/workflows/verify.yaml'].some(path => same(workflow.path, path)));
|
|
18
|
+
if (!matches.length) matches = workflows.filter(workflow => same(workflow.name, 'verify'));
|
|
19
|
+
}
|
|
20
|
+
if (matches.length === 1) return { workflow: matches[0] };
|
|
21
|
+
if (matches.length > 1) return { error: `Ambiguous Verify workflows: ${matches.map(describe).join('; ')}. Select one with --verify-workflow <name|file>.` };
|
|
22
|
+
return { error: `${selector === undefined ? 'No Verify workflow found' : `No Verify workflow matches ${JSON.stringify(selector)}`}. Select a workflow with --verify-workflow <name|file>.` };
|
|
23
|
+
}
|