vouchington-tooling 0.80.1 → 0.80.2
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.
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface Step {
|
|
2
|
+
id?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
run?: string;
|
|
5
|
+
uses?: string;
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
with?: Record<string, unknown>;
|
|
8
|
+
if?: string;
|
|
9
|
+
'timeout-minutes'?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const source: string;
|
|
12
|
+
export declare const workflow: {
|
|
13
|
+
on: {
|
|
14
|
+
workflow_call: {
|
|
15
|
+
inputs: Record<string, {
|
|
16
|
+
default?: string;
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
jobs: {
|
|
21
|
+
gitleaks: {
|
|
22
|
+
"timeout-minutes": number;
|
|
23
|
+
steps: Step[];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare const steps: Step[];
|
|
28
|
+
export declare function step(name: string): Step;
|
|
29
|
+
export declare const FAKE_TIP: string;
|
|
30
|
+
export declare const FAKE_TOP: string;
|
|
31
|
+
export declare const FAKE_BOUNDARY: string;
|
|
32
|
+
export declare function runRange(env: Record<string, string>): {
|
|
33
|
+
fetchCalls: string;
|
|
34
|
+
status: number | null;
|
|
35
|
+
stderr: string;
|
|
36
|
+
stdout: string;
|
|
37
|
+
written: string;
|
|
38
|
+
};
|
|
39
|
+
export declare function git(cwd: string, ...args: string[]): string;
|
|
40
|
+
export declare function shallowClient(remote: string, directory: string, refspec: string, ref: string): void;
|
|
41
|
+
export declare function writeGhStub(directory: string, sourceRepo: string): void;
|
|
42
|
+
export declare function runActualRange(directory: string, env: Record<string, string>): {
|
|
43
|
+
stderr: string;
|
|
44
|
+
status: number | null;
|
|
45
|
+
stdout: string;
|
|
46
|
+
written: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { parse as load } from 'yaml';
|
|
7
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
8
|
+
export const source = readFileSync(join(root, '.github/workflows/gitleaks.yml'), 'utf8');
|
|
9
|
+
export const workflow = load(source);
|
|
10
|
+
export const steps = workflow.jobs.gitleaks.steps;
|
|
11
|
+
export function step(name) {
|
|
12
|
+
const found = steps.find((candidate) => candidate.name === name);
|
|
13
|
+
if (!found?.run)
|
|
14
|
+
throw new Error(`missing step ${name}`);
|
|
15
|
+
return found;
|
|
16
|
+
}
|
|
17
|
+
export const FAKE_TIP = 'f'.repeat(40);
|
|
18
|
+
export const FAKE_TOP = '1'.repeat(40);
|
|
19
|
+
export const FAKE_BOUNDARY = 'e'.repeat(40);
|
|
20
|
+
export function runRange(env) {
|
|
21
|
+
const directory = mkdtempSync(join(tmpdir(), 'gitleaks-range-'));
|
|
22
|
+
const bin = join(directory, 'bin');
|
|
23
|
+
const output = join(directory, 'output');
|
|
24
|
+
const fetchLog = join(directory, 'fetch-log');
|
|
25
|
+
mkdirSync(bin);
|
|
26
|
+
writeFileSync(join(bin, 'git'), `#!/bin/bash
|
|
27
|
+
if [ "$1" = fetch ]; then printf '%s\\n' "$*" >> "$GIT_FETCH_LOG"; exit 0; fi
|
|
28
|
+
if [ "$1" = rev-list ] && [ "$2" = --no-walk ]; then [ -z "$GIT_PARENTS" ] || printf '%b\n' "$GIT_PARENTS"; exit 0; fi
|
|
29
|
+
if [ "$1" = rev-list ]; then [ -z "$GIT_RANGE" ] || printf '%b\n' "$GIT_RANGE"; exit 0; fi
|
|
30
|
+
echo "unexpected git $*" >&2
|
|
31
|
+
exit 1
|
|
32
|
+
`);
|
|
33
|
+
chmodSync(join(bin, 'git'), 0o755);
|
|
34
|
+
writeFileSync(join(bin, 'gh'), `#!/bin/bash
|
|
35
|
+
printf 'api %s\n' "$2" >> "$GIT_FETCH_LOG"
|
|
36
|
+
case "$2" in *'&page='*) printf '%b\n' "$GH_COMMITS" ;; *) printf '%s\n' "$GH_AHEAD" ;; esac
|
|
37
|
+
`);
|
|
38
|
+
chmodSync(join(bin, 'gh'), 0o755);
|
|
39
|
+
try {
|
|
40
|
+
const result = spawnSync('bash', [
|
|
41
|
+
'--noprofile',
|
|
42
|
+
'--norc',
|
|
43
|
+
'-eo',
|
|
44
|
+
'pipefail',
|
|
45
|
+
'-c',
|
|
46
|
+
step('Determine Gitleaks scan range').run ?? '',
|
|
47
|
+
], {
|
|
48
|
+
encoding: 'utf8',
|
|
49
|
+
timeout: 10_000,
|
|
50
|
+
env: {
|
|
51
|
+
...process.env,
|
|
52
|
+
PATH: `${bin}:${process.env.PATH ?? ''}`,
|
|
53
|
+
GITHUB_OUTPUT: output,
|
|
54
|
+
GIT_FETCH_LOG: fetchLog,
|
|
55
|
+
GH_TOKEN: 'test-token',
|
|
56
|
+
GITHUB_REPOSITORY: 'owner/repo',
|
|
57
|
+
GH_AHEAD: '2',
|
|
58
|
+
GH_COMMITS: `${FAKE_TIP}\n${FAKE_TOP}`,
|
|
59
|
+
GIT_PARENTS: `${FAKE_TIP} ${FAKE_BOUNDARY}\n${FAKE_TOP} ${FAKE_TIP}`,
|
|
60
|
+
GIT_RANGE: `${FAKE_TIP}\n${FAKE_TOP}`,
|
|
61
|
+
...env,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const written = result.status === 0 ? readFileSync(output, 'utf8') : '';
|
|
65
|
+
return {
|
|
66
|
+
fetchCalls: existsSync(fetchLog) ? readFileSync(fetchLog, 'utf8') : '',
|
|
67
|
+
status: result.status,
|
|
68
|
+
stderr: result.stderr,
|
|
69
|
+
stdout: result.stdout,
|
|
70
|
+
written,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
rmSync(directory, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function git(cwd, ...args) {
|
|
78
|
+
const result = spawnSync('git', ['-C', cwd, ...args], { encoding: 'utf8', timeout: 10_000 });
|
|
79
|
+
if (result.status !== 0) {
|
|
80
|
+
throw new Error(`git ${args.join(' ')} failed: ${result.stderr}`);
|
|
81
|
+
}
|
|
82
|
+
return result.stdout.trim();
|
|
83
|
+
}
|
|
84
|
+
export function shallowClient(remote, directory, refspec, ref) {
|
|
85
|
+
mkdirSync(directory);
|
|
86
|
+
git(directory, 'init', '--quiet');
|
|
87
|
+
git(directory, 'remote', 'add', 'origin', remote);
|
|
88
|
+
git(directory, 'fetch', '--quiet', '--depth=1', 'origin', refspec);
|
|
89
|
+
git(directory, 'checkout', '--quiet', '--detach', ref);
|
|
90
|
+
}
|
|
91
|
+
let ghStubDir = '';
|
|
92
|
+
export function writeGhStub(directory, sourceRepo) {
|
|
93
|
+
ghStubDir = join(directory, 'gh-bin');
|
|
94
|
+
mkdirSync(ghStubDir);
|
|
95
|
+
writeFileSync(join(ghStubDir, 'gh'), `#!/bin/bash
|
|
96
|
+
url="$2"
|
|
97
|
+
range="\${url##*/compare/}"
|
|
98
|
+
range="\${range%%[?]*}"
|
|
99
|
+
base="\${range%%...*}"
|
|
100
|
+
head="\${range##*...}"
|
|
101
|
+
mb=$(git -C '${sourceRepo}' merge-base "$base" "$head")
|
|
102
|
+
case "$url" in
|
|
103
|
+
*'&page='*)
|
|
104
|
+
size="\${url##*per_page=}"
|
|
105
|
+
size="\${size%%&*}"
|
|
106
|
+
page="\${url##*&page=}"
|
|
107
|
+
git -C '${sourceRepo}' rev-list "$mb..$head" | sed -n "$(( (page - 1) * size + 1 )),$(( page * size ))p"
|
|
108
|
+
;;
|
|
109
|
+
*) git -C '${sourceRepo}' rev-list --count "$mb..$head" ;;
|
|
110
|
+
esac
|
|
111
|
+
`);
|
|
112
|
+
chmodSync(join(ghStubDir, 'gh'), 0o755);
|
|
113
|
+
}
|
|
114
|
+
export function runActualRange(directory, env) {
|
|
115
|
+
const output = join(directory, 'range-output');
|
|
116
|
+
const result = spawnSync('bash', [
|
|
117
|
+
'--noprofile',
|
|
118
|
+
'--norc',
|
|
119
|
+
'-eo',
|
|
120
|
+
'pipefail',
|
|
121
|
+
'-c',
|
|
122
|
+
step('Determine Gitleaks scan range').run ?? '',
|
|
123
|
+
], {
|
|
124
|
+
encoding: 'utf8',
|
|
125
|
+
cwd: directory,
|
|
126
|
+
timeout: 30_000,
|
|
127
|
+
env: {
|
|
128
|
+
...process.env,
|
|
129
|
+
GITHUB_OUTPUT: output,
|
|
130
|
+
GH_TOKEN: 'test-token',
|
|
131
|
+
GITHUB_REPOSITORY: 'owner/repo',
|
|
132
|
+
PATH: `${ghStubDir}:${process.env.PATH ?? ''}`,
|
|
133
|
+
...env,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
stderr: result.stderr,
|
|
138
|
+
status: result.status,
|
|
139
|
+
stdout: result.stdout,
|
|
140
|
+
written: result.status === 0 ? readFileSync(output, 'utf8') : '',
|
|
141
|
+
};
|
|
142
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vouchington-tooling",
|
|
3
|
-
"version": "0.80.
|
|
3
|
+
"version": "0.80.2",
|
|
4
4
|
"description": "Vouchington CLI and extractable tooling libraries.",
|
|
5
5
|
"homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
|
|
6
6
|
"bugs": {
|
|
Binary file
|