vouchington-tooling 0.57.0 → 0.59.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 +26 -0
- package/dist/agent-issue-labels/ensure-labels.d.mts +17 -0
- package/dist/agent-issue-labels/ensure-labels.mjs +55 -0
- package/dist/agent-issue-labels/index.d.mts +5 -0
- package/dist/agent-issue-labels/index.mjs +3 -0
- package/dist/agent-issue-labels/label-policy.d.mts +21 -0
- package/dist/agent-issue-labels/label-policy.mjs +67 -0
- package/dist/agent-issue-labels/labels-from-paths.d.mts +9 -0
- package/dist/agent-issue-labels/labels-from-paths.mjs +54 -0
- package/dist/browser-session-runner/tail-queue.d.mts +1 -1
- package/dist/browser-session-runner/tail-queue.mjs +1 -1
- package/dist/cli/commands/agent-issue-labels.d.mts +2 -0
- package/dist/cli/commands/agent-issue-labels.mjs +17 -0
- package/dist/cli/commands/gitleaks-directory-scan.d.mts +4 -0
- package/dist/cli/commands/gitleaks-directory-scan.mjs +9 -0
- package/dist/cli/commands/transient-retry.d.mts +13 -0
- package/dist/cli/commands/transient-retry.mjs +68 -0
- package/dist/cli/index.mjs +14 -53
- package/dist/cli/parse-agent-issue-labels.d.mts +19 -0
- package/dist/cli/parse-agent-issue-labels.mjs +70 -0
- package/dist/cli/parse-forwarded-commands.d.mts +9 -0
- package/dist/cli/parse-forwarded-commands.mjs +6 -0
- package/dist/cli/parse.d.mts +11 -1
- package/dist/cli/parse.mjs +3 -0
- package/dist/cli/script-paths.d.mts +5 -0
- package/dist/cli/script-paths.mjs +48 -0
- package/dist/cli/usage.d.mts +1 -1
- package/dist/cli/usage.mjs +12 -0
- package/dist/dead-code/baseline.d.mts +19 -0
- package/dist/dead-code/baseline.mjs +124 -0
- package/dist/dead-code/child-command.d.mts +6 -0
- package/dist/dead-code/child-command.mjs +107 -0
- package/dist/dead-code/cli.d.mts +5 -0
- package/dist/dead-code/cli.mjs +71 -0
- package/dist/dead-code/entry-roots.d.mts +7 -0
- package/dist/dead-code/entry-roots.mjs +43 -0
- package/dist/dead-code/fixture-deadline.test-helpers.d.mts +1 -0
- package/dist/dead-code/fixture-deadline.test-helpers.mjs +9 -0
- package/dist/dead-code/gate.d.mts +29 -0
- package/dist/dead-code/gate.mjs +33 -0
- package/dist/dead-code/gate.test-helpers.d.mts +14 -0
- package/dist/dead-code/gate.test-helpers.mjs +35 -0
- package/dist/dead-code/index.d.mts +9 -0
- package/dist/dead-code/index.mjs +7 -0
- package/dist/dead-code/scan.d.mts +11 -0
- package/dist/dead-code/scan.mjs +37 -0
- package/dist/dead-code/tracked-snapshot.d.mts +2 -0
- package/dist/dead-code/tracked-snapshot.mjs +72 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/markdown/details-scope.d.mts +1 -1
- package/dist/markdown/details-scope.mjs +1 -1
- package/dist/transient-retry/attempts.d.mts +1 -1
- package/dist/transient-retry/attempts.mjs +1 -1
- package/dist/transient-retry/decision-evaluator.d.mts +3 -3
- package/dist/transient-retry/gh-api.d.mts +30 -0
- package/dist/transient-retry/gh-api.mjs +68 -0
- package/dist/transient-retry/github-actions-log.d.mts +7 -0
- package/dist/transient-retry/github-actions-log.mjs +33 -0
- package/dist/transient-retry/index.d.mts +15 -0
- package/dist/transient-retry/index.mjs +8 -0
- package/dist/transient-retry/log-stream.d.mts +12 -0
- package/dist/transient-retry/log-stream.mjs +39 -0
- package/dist/transient-retry/log-window.d.mts +18 -0
- package/dist/transient-retry/log-window.mjs +94 -0
- package/dist/transient-retry/rerun.d.mts +23 -0
- package/dist/transient-retry/rerun.mjs +68 -0
- package/dist/transient-retry/run-context-annotations.d.mts +7 -0
- package/dist/transient-retry/run-context-annotations.mjs +44 -0
- package/dist/transient-retry/run-context-jobs.d.mts +20 -0
- package/dist/transient-retry/run-context-jobs.mjs +54 -0
- package/dist/transient-retry/run-context-logs.d.mts +12 -0
- package/dist/transient-retry/run-context-logs.mjs +86 -0
- package/dist/transient-retry/run-context-rule-attempts.d.mts +14 -0
- package/dist/transient-retry/run-context-rule-attempts.mjs +65 -0
- package/dist/transient-retry/run-context-types.d.mts +49 -0
- package/dist/transient-retry/run-context-types.mjs +3 -0
- package/dist/transient-retry/run-context.d.mts +9 -0
- package/dist/transient-retry/run-context.mjs +25 -0
- package/dist/transient-retry/run-context.test-helpers.d.mts +16 -0
- package/dist/transient-retry/run-context.test-helpers.mjs +56 -0
- package/dist/transient-retry/types.d.mts +8 -7
- package/dist/vitest-diagnostics/vitest-worker-exit-diagnostics-reporter.mjs +1 -1
- package/dist/workflow-secrets-drift/cli.d.mts +10 -0
- package/dist/workflow-secrets-drift/cli.mjs +73 -0
- package/dist/workflow-secrets-drift/collect.d.mts +10 -0
- package/dist/workflow-secrets-drift/collect.mjs +70 -0
- package/dist/workflow-secrets-drift/drift.d.mts +22 -0
- package/dist/workflow-secrets-drift/drift.mjs +49 -0
- package/dist/workflow-secrets-drift/gh-parse.d.mts +5 -0
- package/dist/workflow-secrets-drift/gh-parse.mjs +41 -0
- package/dist/workflow-secrets-drift/gh.d.mts +4 -0
- package/dist/workflow-secrets-drift/gh.mjs +51 -0
- package/dist/workflow-secrets-drift/index.d.mts +11 -0
- package/dist/workflow-secrets-drift/index.mjs +6 -0
- package/dist/workflow-secrets-drift/inventory.d.mts +10 -0
- package/dist/workflow-secrets-drift/inventory.mjs +78 -0
- package/dist/workflow-secrets-drift/scopes.d.mts +12 -0
- package/dist/workflow-secrets-drift/scopes.mjs +56 -0
- package/dist/workflow-secrets-drift/settle.d.mts +3 -0
- package/dist/workflow-secrets-drift/settle.mjs +19 -0
- package/dist/workflow-secrets-drift/types.d.mts +33 -0
- package/dist/workflow-secrets-drift/types.mjs +1 -0
- package/package.json +16 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export const LOG_OMISSION_MARKER = '\n[...job log middle omitted...]\n';
|
|
2
|
+
export const DEFAULT_LOG_LIMITS = {
|
|
3
|
+
headBytes: 256 * 1024,
|
|
4
|
+
tailBytes: 512 * 1024,
|
|
5
|
+
maxReadBytes: 64 * 1024 * 1024,
|
|
6
|
+
totalBytes: 16 * 1024 * 1024,
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Reads a log stream keeping only a head and a tail window, so memory stays bounded by the limits
|
|
10
|
+
* rather than by the log size. Bytes between the windows are replaced by an omission marker.
|
|
11
|
+
*/
|
|
12
|
+
export async function collectDiagnosticWindow(stream, { headBytes, tailBytes, maxReadBytes }) {
|
|
13
|
+
const head = [];
|
|
14
|
+
const tail = [];
|
|
15
|
+
let headLength = 0;
|
|
16
|
+
let tailLength = 0;
|
|
17
|
+
let total = 0;
|
|
18
|
+
let capped = false;
|
|
19
|
+
for await (let chunk of stream) {
|
|
20
|
+
if (total + chunk.byteLength > maxReadBytes) {
|
|
21
|
+
chunk = chunk.subarray(0, maxReadBytes - total);
|
|
22
|
+
capped = true;
|
|
23
|
+
}
|
|
24
|
+
total += chunk.byteLength;
|
|
25
|
+
const headPart = chunk.subarray(0, headBytes - headLength);
|
|
26
|
+
if (headPart.byteLength > 0)
|
|
27
|
+
head.push(headPart);
|
|
28
|
+
headLength += headPart.byteLength;
|
|
29
|
+
tail.push(chunk);
|
|
30
|
+
tailLength += chunk.byteLength;
|
|
31
|
+
while (tailLength > tailBytes) {
|
|
32
|
+
const excess = tailLength - tailBytes;
|
|
33
|
+
const first = tail[0];
|
|
34
|
+
if (first.byteLength <= excess)
|
|
35
|
+
tail.shift();
|
|
36
|
+
else
|
|
37
|
+
tail[0] = first.subarray(excess);
|
|
38
|
+
tailLength -= Math.min(first.byteLength, excess);
|
|
39
|
+
}
|
|
40
|
+
if (capped)
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
const headBuffer = Buffer.concat(head);
|
|
44
|
+
const tailBuffer = Buffer.concat(tail);
|
|
45
|
+
if (capped || total > headBytes + tailBytes) {
|
|
46
|
+
return headBuffer.toString('utf8') + LOG_OMISSION_MARKER + tailBuffer.toString('utf8');
|
|
47
|
+
}
|
|
48
|
+
const unseen = total - headBuffer.byteLength;
|
|
49
|
+
return (headBuffer.toString('utf8') +
|
|
50
|
+
tailBuffer.subarray(tailBuffer.byteLength - unseen).toString('utf8'));
|
|
51
|
+
}
|
|
52
|
+
export function fitDiagnosticWindow(log, maxBytes) {
|
|
53
|
+
if (Buffer.byteLength(log) <= maxBytes)
|
|
54
|
+
return log;
|
|
55
|
+
const markerBytes = Buffer.byteLength(LOG_OMISSION_MARKER);
|
|
56
|
+
if (maxBytes <= markerBytes)
|
|
57
|
+
return takeUtf8Suffix(log, maxBytes);
|
|
58
|
+
const contentBytes = maxBytes - markerBytes;
|
|
59
|
+
const headBytes = Math.floor(contentBytes / 3);
|
|
60
|
+
return (takeUtf8Prefix(log, headBytes) +
|
|
61
|
+
LOG_OMISSION_MARKER +
|
|
62
|
+
takeUtf8Suffix(log, contentBytes - headBytes));
|
|
63
|
+
}
|
|
64
|
+
function takeUtf8Prefix(value, maxBytes) {
|
|
65
|
+
let bytes = 0;
|
|
66
|
+
let end = 0;
|
|
67
|
+
for (const character of value) {
|
|
68
|
+
const characterBytes = Buffer.byteLength(character);
|
|
69
|
+
if (bytes + characterBytes > maxBytes)
|
|
70
|
+
break;
|
|
71
|
+
bytes += characterBytes;
|
|
72
|
+
end += character.length;
|
|
73
|
+
}
|
|
74
|
+
return value.slice(0, end);
|
|
75
|
+
}
|
|
76
|
+
function takeUtf8Suffix(value, maxBytes) {
|
|
77
|
+
let bytes = 0;
|
|
78
|
+
let start = value.length;
|
|
79
|
+
while (start > 0) {
|
|
80
|
+
let characterStart = start - 1;
|
|
81
|
+
const trailing = value.charCodeAt(characterStart);
|
|
82
|
+
if (trailing >= 0xdc00 && trailing <= 0xdfff && characterStart > 0) {
|
|
83
|
+
const leading = value.charCodeAt(characterStart - 1);
|
|
84
|
+
if (leading >= 0xd800 && leading <= 0xdbff)
|
|
85
|
+
characterStart -= 1;
|
|
86
|
+
}
|
|
87
|
+
const characterBytes = Buffer.byteLength(value.slice(characterStart, start));
|
|
88
|
+
if (bytes + characterBytes > maxBytes)
|
|
89
|
+
break;
|
|
90
|
+
bytes += characterBytes;
|
|
91
|
+
start = characterStart;
|
|
92
|
+
}
|
|
93
|
+
return value.slice(start);
|
|
94
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type GhApi } from './gh-api.mts';
|
|
2
|
+
import { type LogLimits } from './log-window.mts';
|
|
3
|
+
import { type WorkflowRetryRule } from './run-context-types.mts';
|
|
4
|
+
export interface RerunKnownTransientOptions {
|
|
5
|
+
/** `owner/name`; inferred from the current checkout when omitted. */
|
|
6
|
+
repository?: string;
|
|
7
|
+
runId: string;
|
|
8
|
+
/** The caller's rule catalog. The engine has no built-in rules. */
|
|
9
|
+
rules: readonly WorkflowRetryRule[];
|
|
10
|
+
dryRun?: boolean;
|
|
11
|
+
limits?: Partial<LogLimits>;
|
|
12
|
+
api?: GhApi;
|
|
13
|
+
streamLog?: (path: string) => AsyncIterable<Buffer>;
|
|
14
|
+
log?: (message: string) => void;
|
|
15
|
+
}
|
|
16
|
+
/** Process exit codes: a rerun was requested (or would be), or none was warranted. */
|
|
17
|
+
export declare const RERUN_REQUESTED = 0;
|
|
18
|
+
export declare const NO_RERUN = 2;
|
|
19
|
+
/**
|
|
20
|
+
* Evaluates the injected rules for a failed workflow run and reruns it only when one rule asks
|
|
21
|
+
* for a rerun. Only job names and the decision are logged; log text is never printed.
|
|
22
|
+
*/
|
|
23
|
+
export declare function rerunKnownTransient({ repository: requestedRepository, runId, rules, dryRun, limits, api, streamLog, log, }: RerunKnownTransientOptions): Promise<number>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { decide } from "./decision-evaluator.mjs";
|
|
2
|
+
import { createGhApi } from "./gh-api.mjs";
|
|
3
|
+
import { streamGhApiLog } from "./log-stream.mjs";
|
|
4
|
+
import { DEFAULT_LOG_LIMITS } from "./log-window.mjs";
|
|
5
|
+
import { buildWorkflowRunContext } from "./run-context.mjs";
|
|
6
|
+
import { fetchWorkflowRunSummary } from "./run-context-jobs.mjs";
|
|
7
|
+
import { isFailedWorkflowConclusion, } from "./run-context-types.mjs";
|
|
8
|
+
/** Process exit codes: a rerun was requested (or would be), or none was warranted. */
|
|
9
|
+
export const RERUN_REQUESTED = 0;
|
|
10
|
+
export const NO_RERUN = 2;
|
|
11
|
+
async function resolveRepository(repository, api) {
|
|
12
|
+
if (repository)
|
|
13
|
+
return repository;
|
|
14
|
+
try {
|
|
15
|
+
const inferred = (await api.run(['repo', 'view', '--json', 'nameWithOwner', '--jq', '.nameWithOwner'])).trim();
|
|
16
|
+
if (inferred)
|
|
17
|
+
return inferred;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Fall through to the actionable error below.
|
|
21
|
+
}
|
|
22
|
+
throw new Error('Missing repository. Pass --repo owner/name, set GITHUB_REPOSITORY, or run from a gh-authenticated checkout.');
|
|
23
|
+
}
|
|
24
|
+
function describeDecision(result) {
|
|
25
|
+
return result.matchedRule ? `${result.decision} (rule ${result.matchedRule})` : result.decision;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Evaluates the injected rules for a failed workflow run and reruns it only when one rule asks
|
|
29
|
+
* for a rerun. Only job names and the decision are logged; log text is never printed.
|
|
30
|
+
*/
|
|
31
|
+
export async function rerunKnownTransient({ repository: requestedRepository, runId, rules, dryRun = false, limits, api = createGhApi(), streamLog = streamGhApiLog, log = console.log, }) {
|
|
32
|
+
const repository = await resolveRepository(requestedRepository, api);
|
|
33
|
+
const env = {
|
|
34
|
+
api,
|
|
35
|
+
limits: { ...DEFAULT_LOG_LIMITS, ...limits },
|
|
36
|
+
repository,
|
|
37
|
+
runId,
|
|
38
|
+
streamLog,
|
|
39
|
+
};
|
|
40
|
+
const summary = await fetchWorkflowRunSummary(env);
|
|
41
|
+
log(`Workflow: ${summary.workflowName}`);
|
|
42
|
+
log(`Conclusion: ${summary.conclusion ?? '(none)'}`);
|
|
43
|
+
if (!isFailedWorkflowConclusion(summary.conclusion)) {
|
|
44
|
+
log('Run conclusion is not failure, timed_out, or cancelled; no rerun requested.');
|
|
45
|
+
return NO_RERUN;
|
|
46
|
+
}
|
|
47
|
+
const context = await buildWorkflowRunContext(env, {
|
|
48
|
+
conclusion: summary.conclusion,
|
|
49
|
+
rules,
|
|
50
|
+
runAttempt: summary.runAttempt,
|
|
51
|
+
workflowName: summary.workflowName,
|
|
52
|
+
});
|
|
53
|
+
const result = await decide(context, rules, { unmatchedDecision: 'dispatch' });
|
|
54
|
+
log(`Run attempt: ${context.runAttempt} (retry attempt: ${context.retryAttempt})`);
|
|
55
|
+
log(`Failed jobs: ${context.failedJobNames.join(', ') || '(none)'}`);
|
|
56
|
+
log(`Decision: ${describeDecision(result)}`);
|
|
57
|
+
if (result.decision !== 'rerun') {
|
|
58
|
+
log(`No rerun requested: decision is '${result.decision}', not 'rerun'.`);
|
|
59
|
+
return NO_RERUN;
|
|
60
|
+
}
|
|
61
|
+
if (dryRun) {
|
|
62
|
+
log(`Dry run: would run gh run rerun --repo ${repository} ${runId}`);
|
|
63
|
+
return RERUN_REQUESTED;
|
|
64
|
+
}
|
|
65
|
+
await api.run(['run', 'rerun', '--repo', repository, runId]);
|
|
66
|
+
log(`Requested rerun for run ${runId}.`);
|
|
67
|
+
return RERUN_REQUESTED;
|
|
68
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JobEntry, RunFetchEnv } from './run-context-types.mts';
|
|
2
|
+
export declare function annotationMessagesFromPages(stdout: string): string[];
|
|
3
|
+
/** Lazily fetches and caches check-run annotation messages for the failed jobs. */
|
|
4
|
+
export declare function createAnnotationFetchers(env: RunFetchEnv, failedJobs: readonly JobEntry[]): {
|
|
5
|
+
failedJobAnnotations: (jobName: string) => Promise<string[]>;
|
|
6
|
+
failedJobAnnotationFetchFailures: () => Promise<Set<string>>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function annotationMessagesFromPages(stdout) {
|
|
2
|
+
const pages = JSON.parse(stdout.trim());
|
|
3
|
+
return Array.isArray(pages)
|
|
4
|
+
? pages.flatMap((page) => (Array.isArray(page) ? page.flatMap(annotationMessage) : []))
|
|
5
|
+
: [];
|
|
6
|
+
}
|
|
7
|
+
function annotationMessage(annotation) {
|
|
8
|
+
const message = annotation?.message;
|
|
9
|
+
return typeof message === 'string' ? [message] : [];
|
|
10
|
+
}
|
|
11
|
+
/** Lazily fetches and caches check-run annotation messages for the failed jobs. */
|
|
12
|
+
export function createAnnotationFetchers(env, failedJobs) {
|
|
13
|
+
const cache = new Map();
|
|
14
|
+
const failures = new Set();
|
|
15
|
+
const failedJobAnnotations = async (jobName) => {
|
|
16
|
+
const cached = cache.get(jobName);
|
|
17
|
+
if (cached !== undefined)
|
|
18
|
+
return cached;
|
|
19
|
+
const job = failedJobs.find((entry) => entry.name === jobName);
|
|
20
|
+
let messages = [];
|
|
21
|
+
if (job !== undefined) {
|
|
22
|
+
try {
|
|
23
|
+
messages = annotationMessagesFromPages(await env.api.call([
|
|
24
|
+
'-X',
|
|
25
|
+
'GET',
|
|
26
|
+
`repos/${env.repository}/check-runs/${job.id}/annotations`,
|
|
27
|
+
'-F',
|
|
28
|
+
'per_page=100',
|
|
29
|
+
'--paginate',
|
|
30
|
+
'--slurp',
|
|
31
|
+
]));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
failures.add(jobName);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
cache.set(jobName, messages);
|
|
38
|
+
return messages;
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
failedJobAnnotations,
|
|
42
|
+
failedJobAnnotationFetchFailures: async () => new Set(failures),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type JobEntry, type RunFetchEnv, type WorkflowConclusion, type WorkflowRunContext } from './run-context-types.mts';
|
|
2
|
+
export declare function parseWorkflowJobEntries(stdout: string): JobEntry[];
|
|
3
|
+
/** Every job of the run, or of one prior attempt when `attempt` is given. */
|
|
4
|
+
export declare function fetchJobs(env: RunFetchEnv, attempt?: number): Promise<JobEntry[]>;
|
|
5
|
+
/** Job counts of attempts 1..runAttempt-1; `null` where the attempt could not be read. */
|
|
6
|
+
export declare function fetchPriorAttemptJobCounts(env: RunFetchEnv, runAttempt: number): Promise<Array<number | null>>;
|
|
7
|
+
export interface WorkflowRunSummary {
|
|
8
|
+
conclusion: string | null | undefined;
|
|
9
|
+
runAttempt: number;
|
|
10
|
+
workflowName: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function fetchWorkflowRunSummary(env: RunFetchEnv): Promise<WorkflowRunSummary>;
|
|
13
|
+
export interface JobsContextInput {
|
|
14
|
+
conclusion: WorkflowConclusion;
|
|
15
|
+
retryAttempt: number;
|
|
16
|
+
runAttempt: number;
|
|
17
|
+
workflowName: string;
|
|
18
|
+
}
|
|
19
|
+
/** Builds a context over one attempt's jobs. Logs and annotations stay unfetched until read. */
|
|
20
|
+
export declare function buildJobsContext(env: RunFetchEnv, jobs: readonly JobEntry[], input: JobsContextInput): WorkflowRunContext;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createAnnotationFetchers } from "./run-context-annotations.mjs";
|
|
2
|
+
import { createLogFetchers } from "./run-context-logs.mjs";
|
|
3
|
+
import { isFailedWorkflowConclusion, } from "./run-context-types.mjs";
|
|
4
|
+
export function parseWorkflowJobEntries(stdout) {
|
|
5
|
+
const pages = JSON.parse(stdout.trim());
|
|
6
|
+
return pages.flatMap((page) => page.jobs ?? []);
|
|
7
|
+
}
|
|
8
|
+
/** Every job of the run, or of one prior attempt when `attempt` is given. */
|
|
9
|
+
export async function fetchJobs(env, attempt) {
|
|
10
|
+
const base = `repos/${env.repository}/actions/runs/${env.runId}`;
|
|
11
|
+
const path = attempt === undefined ? `${base}/jobs` : `${base}/attempts/${attempt}/jobs`;
|
|
12
|
+
return parseWorkflowJobEntries(await env.api.call([path, '--paginate', '--slurp']));
|
|
13
|
+
}
|
|
14
|
+
/** Job counts of attempts 1..runAttempt-1; `null` where the attempt could not be read. */
|
|
15
|
+
export async function fetchPriorAttemptJobCounts(env, runAttempt) {
|
|
16
|
+
return Promise.all(Array.from({ length: Math.max(0, runAttempt - 1) }, async (_, index) => {
|
|
17
|
+
try {
|
|
18
|
+
return (await fetchJobs(env, index + 1)).length;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
export async function fetchWorkflowRunSummary(env) {
|
|
26
|
+
const stdout = await env.api.call([`repos/${env.repository}/actions/runs/${env.runId}`]);
|
|
27
|
+
const run = JSON.parse(stdout.trim());
|
|
28
|
+
const invalid = (what) => new Error(`Invalid workflow run ${what} in GitHub API response for run ${env.runId}`);
|
|
29
|
+
if (typeof run !== 'object' || run === null)
|
|
30
|
+
throw invalid('response');
|
|
31
|
+
const { conclusion, name, run_attempt: runAttempt } = run;
|
|
32
|
+
if (typeof runAttempt !== 'number' || !Number.isInteger(runAttempt) || runAttempt < 1) {
|
|
33
|
+
throw invalid('attempt');
|
|
34
|
+
}
|
|
35
|
+
if (typeof name !== 'string' || name.length === 0)
|
|
36
|
+
throw invalid('name');
|
|
37
|
+
if (conclusion != null && typeof conclusion !== 'string')
|
|
38
|
+
throw invalid('conclusion');
|
|
39
|
+
return { conclusion, runAttempt, workflowName: name };
|
|
40
|
+
}
|
|
41
|
+
/** Builds a context over one attempt's jobs. Logs and annotations stay unfetched until read. */
|
|
42
|
+
export function buildJobsContext(env, jobs, input) {
|
|
43
|
+
const failedJobs = jobs.filter((job) => isFailedWorkflowConclusion(job.conclusion));
|
|
44
|
+
return {
|
|
45
|
+
...input,
|
|
46
|
+
jobNames: jobs.map((job) => job.name),
|
|
47
|
+
targetNames: new Set(jobs.map((job) => job.name)),
|
|
48
|
+
jobConclusions: new Map(jobs.map((job) => [job.name, job.conclusion])),
|
|
49
|
+
jobSteps: new Map(jobs.map((job) => [job.name, job.steps ?? []])),
|
|
50
|
+
failedJobNames: failedJobs.map((job) => job.name),
|
|
51
|
+
...createLogFetchers(env, jobs, failedJobs),
|
|
52
|
+
...createAnnotationFetchers(env, failedJobs),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JobEntry, RunFetchEnv } from './run-context-types.mts';
|
|
2
|
+
/**
|
|
3
|
+
* Lazily fetches job logs through a head+tail window, one job at a time, and keeps no more than
|
|
4
|
+
* `limits.totalBytes` of text across the run. A job that cannot be read, or that arrives after the
|
|
5
|
+
* budget is spent, is recorded as a fetch failure with an empty log so rules never see a partial
|
|
6
|
+
* log presented as complete.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLogFetchers(env: RunFetchEnv, allJobs: readonly JobEntry[], failedJobs: readonly JobEntry[]): {
|
|
9
|
+
failedJobLogs: () => Promise<Map<string, string>>;
|
|
10
|
+
jobLogs: (jobNames: readonly string[]) => Promise<Map<string, string>>;
|
|
11
|
+
failedJobLogFetchFailures: () => Promise<Set<string>>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { collectDiagnosticWindow, fitDiagnosticWindow } from "./log-window.mjs";
|
|
2
|
+
const STREAM_ATTEMPTS = 3;
|
|
3
|
+
/**
|
|
4
|
+
* Lazily fetches job logs through a head+tail window, one job at a time, and keeps no more than
|
|
5
|
+
* `limits.totalBytes` of text across the run. A job that cannot be read, or that arrives after the
|
|
6
|
+
* budget is spent, is recorded as a fetch failure with an empty log so rules never see a partial
|
|
7
|
+
* log presented as complete.
|
|
8
|
+
*/
|
|
9
|
+
export function createLogFetchers(env, allJobs, failedJobs) {
|
|
10
|
+
// Fetch state is keyed by job id: distinct jobs may share a display name.
|
|
11
|
+
const cached = new Map();
|
|
12
|
+
const inFlight = new Map();
|
|
13
|
+
const jobsByName = new Map();
|
|
14
|
+
for (const job of allJobs)
|
|
15
|
+
if (!jobsByName.has(job.name))
|
|
16
|
+
jobsByName.set(job.name, job);
|
|
17
|
+
const failures = new Set();
|
|
18
|
+
let retainedBytes = 0;
|
|
19
|
+
let queueTail = Promise.resolve();
|
|
20
|
+
const readWindow = async (path, maxBytes) => {
|
|
21
|
+
for (let attempt = 1;; attempt += 1) {
|
|
22
|
+
try {
|
|
23
|
+
// A fresh collector per attempt drops partial text from a failed stream.
|
|
24
|
+
const log = await collectDiagnosticWindow(env.streamLog(path), env.limits);
|
|
25
|
+
return fitDiagnosticWindow(log, maxBytes);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (attempt >= STREAM_ATTEMPTS || !env.api.isRetryable(error))
|
|
29
|
+
throw error;
|
|
30
|
+
await env.api.sleep(attempt * 1000);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const fetchWithinBudget = async (job) => {
|
|
35
|
+
let log = '';
|
|
36
|
+
const remaining = env.limits.totalBytes - retainedBytes;
|
|
37
|
+
try {
|
|
38
|
+
if (remaining <= 0)
|
|
39
|
+
throw new Error('log budget exhausted');
|
|
40
|
+
log = await readWindow(`repos/${env.repository}/actions/jobs/${job.id}/logs`, remaining);
|
|
41
|
+
retainedBytes += Buffer.byteLength(log);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
failures.add(job.name);
|
|
45
|
+
}
|
|
46
|
+
cached.set(job.id, log);
|
|
47
|
+
return log;
|
|
48
|
+
};
|
|
49
|
+
const fetchLog = (job) => {
|
|
50
|
+
const hit = cached.get(job.id);
|
|
51
|
+
if (hit !== undefined)
|
|
52
|
+
return Promise.resolve(hit);
|
|
53
|
+
const pending = inFlight.get(job.id);
|
|
54
|
+
if (pending)
|
|
55
|
+
return pending;
|
|
56
|
+
// Sequential on purpose: many failed jobs must not hold many windows at once.
|
|
57
|
+
const settled = queueTail
|
|
58
|
+
.then(() => fetchWithinBudget(job))
|
|
59
|
+
.finally(() => inFlight.delete(job.id));
|
|
60
|
+
inFlight.set(job.id, settled);
|
|
61
|
+
// `fetchWithinBudget` records failures instead of throwing, so the queue never rejects.
|
|
62
|
+
queueTail = settled.then(() => undefined);
|
|
63
|
+
return settled;
|
|
64
|
+
};
|
|
65
|
+
let failedLogs;
|
|
66
|
+
return {
|
|
67
|
+
failedJobLogs: () => (failedLogs ??= (async () => {
|
|
68
|
+
const logs = new Map();
|
|
69
|
+
for (const job of failedJobs) {
|
|
70
|
+
const log = await fetchLog(job);
|
|
71
|
+
// Failed jobs that share a name are joined so no job's evidence is dropped.
|
|
72
|
+
logs.set(job.name, logs.has(job.name) ? `${logs.get(job.name)}\n${log}` : log);
|
|
73
|
+
}
|
|
74
|
+
return logs;
|
|
75
|
+
})()),
|
|
76
|
+
jobLogs: async (jobNames) => {
|
|
77
|
+
const logs = new Map();
|
|
78
|
+
for (const name of jobNames) {
|
|
79
|
+
const job = jobsByName.get(name);
|
|
80
|
+
logs.set(name, job === undefined ? '' : await fetchLog(job));
|
|
81
|
+
}
|
|
82
|
+
return logs;
|
|
83
|
+
},
|
|
84
|
+
failedJobLogFetchFailures: async () => new Set(failures),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RunFetchEnv, WorkflowRetryRule } from './run-context-types.mts';
|
|
2
|
+
export interface DeriveRuleAttemptsOptions {
|
|
3
|
+
priorCounts: readonly number[];
|
|
4
|
+
rules: readonly WorkflowRetryRule[];
|
|
5
|
+
runAttempt: number;
|
|
6
|
+
workflowName: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Replays the rules over each prior attempt in order and counts, per rerun rule, how many earlier
|
|
10
|
+
* attempts that rule won. The result is each rule's next-occurrence count. A rule whose replay
|
|
11
|
+
* evidence cannot be fetched, and every rule after it, drops out of the map so its shared attempt
|
|
12
|
+
* applies; if the very first rule is unreadable the whole replay throws.
|
|
13
|
+
*/
|
|
14
|
+
export declare function deriveRuleAttempts(env: RunFetchEnv, { priorCounts, rules, runAttempt, workflowName }: DeriveRuleAttemptsOptions): Promise<Map<string, number>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { deriveRetryAttempt } from "./attempts.mjs";
|
|
2
|
+
import { decide } from "./decision-evaluator.mjs";
|
|
3
|
+
import { buildJobsContext, fetchJobs } from "./run-context-jobs.mjs";
|
|
4
|
+
class ReplayEvidenceUnavailableError extends Error {
|
|
5
|
+
ruleIndex;
|
|
6
|
+
constructor(ruleId, ruleIndex) {
|
|
7
|
+
super(`Cannot replay rule ${ruleId}: required prior-attempt evidence is unavailable`);
|
|
8
|
+
this.ruleIndex = ruleIndex;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function failedConclusionFromJobs(jobs) {
|
|
12
|
+
if (jobs.some((job) => job.conclusion === 'failure'))
|
|
13
|
+
return 'failure';
|
|
14
|
+
if (jobs.some((job) => job.conclusion === 'timed_out'))
|
|
15
|
+
return 'timed_out';
|
|
16
|
+
return 'cancelled';
|
|
17
|
+
}
|
|
18
|
+
async function throwIfReplayEvidenceFailed(context, ruleId, ruleIndex) {
|
|
19
|
+
if ((await context.failedJobLogFetchFailures()).size > 0) {
|
|
20
|
+
throw new ReplayEvidenceUnavailableError(ruleId, ruleIndex);
|
|
21
|
+
}
|
|
22
|
+
if ((await context.failedJobAnnotationFetchFailures()).size > 0) {
|
|
23
|
+
throw new ReplayEvidenceUnavailableError(ruleId, ruleIndex);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Replays the rules over each prior attempt in order and counts, per rerun rule, how many earlier
|
|
28
|
+
* attempts that rule won. The result is each rule's next-occurrence count. A rule whose replay
|
|
29
|
+
* evidence cannot be fetched, and every rule after it, drops out of the map so its shared attempt
|
|
30
|
+
* applies; if the very first rule is unreadable the whole replay throws.
|
|
31
|
+
*/
|
|
32
|
+
export async function deriveRuleAttempts(env, { priorCounts, rules, runAttempt, workflowName }) {
|
|
33
|
+
const priorReruns = new Map();
|
|
34
|
+
let replayCount = rules.length;
|
|
35
|
+
for (let attempt = 1; attempt < runAttempt; attempt += 1) {
|
|
36
|
+
// An attempt that created no jobs has no failure signal; the shared attempt already discounts it.
|
|
37
|
+
if (priorCounts[attempt - 1] === 0)
|
|
38
|
+
continue;
|
|
39
|
+
const jobs = await fetchJobs(env, attempt);
|
|
40
|
+
const replayRules = rules.slice(0, replayCount);
|
|
41
|
+
const context = {
|
|
42
|
+
...buildJobsContext(env, jobs, {
|
|
43
|
+
conclusion: failedConclusionFromJobs(jobs),
|
|
44
|
+
retryAttempt: deriveRetryAttempt(attempt, priorCounts.slice(0, attempt - 1)),
|
|
45
|
+
runAttempt: attempt,
|
|
46
|
+
workflowName,
|
|
47
|
+
}),
|
|
48
|
+
retryAttempts: new Map(replayRules.map((rule) => [rule.id, (priorReruns.get(rule.id) ?? 0) + 1])),
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
const result = await decide(context, replayRules, {
|
|
52
|
+
afterRuleEvaluated: (replayContext, rule) => throwIfReplayEvidenceFailed(replayContext, rule.id, replayRules.indexOf(rule)),
|
|
53
|
+
});
|
|
54
|
+
if (result.decision === 'rerun') {
|
|
55
|
+
priorReruns.set(result.matchedRule, (priorReruns.get(result.matchedRule) ?? 0) + 1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (!(error instanceof ReplayEvidenceUnavailableError) || error.ruleIndex === 0)
|
|
60
|
+
throw error;
|
|
61
|
+
replayCount = Math.min(replayCount, error.ruleIndex);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new Map(rules.slice(0, replayCount).map((rule) => [rule.id, (priorReruns.get(rule.id) ?? 0) + 1]));
|
|
65
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { GhApi } from './gh-api.mts';
|
|
2
|
+
import type { LogLimits } from './log-window.mts';
|
|
3
|
+
import type { RetryContext, RetryRule } from './types.mts';
|
|
4
|
+
export interface WorkflowJobStep {
|
|
5
|
+
conclusion?: string | null;
|
|
6
|
+
name: string;
|
|
7
|
+
number?: number;
|
|
8
|
+
started_at?: string | null;
|
|
9
|
+
status?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface JobEntry {
|
|
12
|
+
name: string;
|
|
13
|
+
id: number;
|
|
14
|
+
conclusion?: string;
|
|
15
|
+
steps?: WorkflowJobStep[];
|
|
16
|
+
}
|
|
17
|
+
export type WorkflowConclusion = 'failure' | 'timed_out' | 'cancelled';
|
|
18
|
+
/**
|
|
19
|
+
* A workflow run as the decision core sees it. `runAttempt`, `retryAttempt`, `retryAttempts` and
|
|
20
|
+
* `targetNames` (the run's job names) satisfy {@link RetryContext}; the rest lets rules read job
|
|
21
|
+
* state, bounded logs and annotations lazily. Logs and annotations are fetched only on first use.
|
|
22
|
+
*/
|
|
23
|
+
export interface WorkflowRunContext extends RetryContext {
|
|
24
|
+
workflowName: string;
|
|
25
|
+
conclusion: WorkflowConclusion;
|
|
26
|
+
/** Every job GitHub created for the run, in API order. */
|
|
27
|
+
jobNames: readonly string[];
|
|
28
|
+
jobConclusions: ReadonlyMap<string, string | undefined>;
|
|
29
|
+
jobSteps: ReadonlyMap<string, readonly WorkflowJobStep[]>;
|
|
30
|
+
failedJobNames: readonly string[];
|
|
31
|
+
/** Bounded log text per failed job. */
|
|
32
|
+
failedJobLogs: () => Promise<Map<string, string>>;
|
|
33
|
+
/** Failed jobs whose logs could not be read; their text is the empty string. */
|
|
34
|
+
failedJobLogFetchFailures: () => Promise<Set<string>>;
|
|
35
|
+
/** Bounded log text for explicitly named jobs, including successful ones. */
|
|
36
|
+
jobLogs: (jobNames: readonly string[]) => Promise<Map<string, string>>;
|
|
37
|
+
failedJobAnnotations: (jobName: string) => Promise<string[]>;
|
|
38
|
+
failedJobAnnotationFetchFailures: () => Promise<Set<string>>;
|
|
39
|
+
}
|
|
40
|
+
export type WorkflowRetryRule = RetryRule<WorkflowRunContext>;
|
|
41
|
+
/** Everything the fetchers share: the `gh` client, the log stream and the identity of the run. */
|
|
42
|
+
export interface RunFetchEnv {
|
|
43
|
+
api: GhApi;
|
|
44
|
+
limits: LogLimits;
|
|
45
|
+
repository: string;
|
|
46
|
+
runId: string;
|
|
47
|
+
streamLog: (path: string) => AsyncIterable<Buffer>;
|
|
48
|
+
}
|
|
49
|
+
export declare function isFailedWorkflowConclusion(conclusion: string | null | undefined): conclusion is WorkflowConclusion;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RunFetchEnv, WorkflowConclusion, WorkflowRetryRule, WorkflowRunContext } from './run-context-types.mts';
|
|
2
|
+
export interface BuildWorkflowRunContextOptions {
|
|
3
|
+
conclusion: WorkflowConclusion;
|
|
4
|
+
/** Rules replayed over prior attempts to count each rerun rule's occurrences. */
|
|
5
|
+
rules?: readonly WorkflowRetryRule[];
|
|
6
|
+
runAttempt: number;
|
|
7
|
+
workflowName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function buildWorkflowRunContext(env: RunFetchEnv, { conclusion, rules, runAttempt, workflowName }: BuildWorkflowRunContextOptions): Promise<WorkflowRunContext>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { deriveRetryAttempt } from "./attempts.mjs";
|
|
2
|
+
import { buildJobsContext, fetchJobs, fetchPriorAttemptJobCounts } from "./run-context-jobs.mjs";
|
|
3
|
+
import { deriveRuleAttempts } from "./run-context-rule-attempts.mjs";
|
|
4
|
+
export async function buildWorkflowRunContext(env, { conclusion, rules, runAttempt, workflowName }) {
|
|
5
|
+
const priorCounts = await fetchPriorAttemptJobCounts(env, runAttempt);
|
|
6
|
+
const knownCounts = priorCounts.every((count) => count !== null)
|
|
7
|
+
? priorCounts
|
|
8
|
+
: undefined;
|
|
9
|
+
const retryAttempt = knownCounts === undefined ? runAttempt : deriveRetryAttempt(runAttempt, knownCounts);
|
|
10
|
+
const context = buildJobsContext(env, await fetchJobs(env), {
|
|
11
|
+
conclusion,
|
|
12
|
+
retryAttempt,
|
|
13
|
+
runAttempt,
|
|
14
|
+
workflowName,
|
|
15
|
+
});
|
|
16
|
+
if (rules === undefined || knownCounts === undefined)
|
|
17
|
+
return context;
|
|
18
|
+
const retryAttempts = await deriveRuleAttempts(env, {
|
|
19
|
+
priorCounts: knownCounts,
|
|
20
|
+
rules,
|
|
21
|
+
runAttempt,
|
|
22
|
+
workflowName,
|
|
23
|
+
}).catch(() => undefined);
|
|
24
|
+
return retryAttempts === undefined ? context : { ...context, retryAttempts };
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LogLimits } from './log-window.mts';
|
|
2
|
+
import type { RunFetchEnv } from './run-context-types.mts';
|
|
3
|
+
/** `[substring of the joined gh argv, reply]`; the first matching route wins. */
|
|
4
|
+
export type Route = [match: string, reply: string | Error];
|
|
5
|
+
/** Streamed log per `/jobs/<id>/logs` suffix: one string, several chunks, or a failure. */
|
|
6
|
+
export type LogReply = string | string[] | Error;
|
|
7
|
+
export declare const jobsPage: (...jobs: Array<Record<string, unknown>>) => string;
|
|
8
|
+
export declare const runReply: (overrides?: Record<string, unknown>) => string;
|
|
9
|
+
export declare function createFakeEnv(routes: Route[], logs?: Record<string, LogReply>, limits?: Partial<LogLimits>): {
|
|
10
|
+
api: import("./gh-api.mts").GhApi;
|
|
11
|
+
calls: string[][];
|
|
12
|
+
env: RunFetchEnv;
|
|
13
|
+
streamed: string[];
|
|
14
|
+
};
|
|
15
|
+
/** Installs a POSIX `gh` stub first on PATH. Returns the restore function. */
|
|
16
|
+
export declare function installFakeGh(script: string): () => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { createGhApi } from "./gh-api.mjs";
|
|
5
|
+
import { DEFAULT_LOG_LIMITS } from "./log-window.mjs";
|
|
6
|
+
export const jobsPage = (...jobs) => JSON.stringify([{ jobs }]);
|
|
7
|
+
export const runReply = (overrides = {}) => JSON.stringify({ conclusion: 'failure', name: 'CI', run_attempt: 1, ...overrides });
|
|
8
|
+
export function createFakeEnv(routes, logs = {}, limits = {}) {
|
|
9
|
+
const calls = [];
|
|
10
|
+
const streamed = [];
|
|
11
|
+
const api = createGhApi({
|
|
12
|
+
run: async (args) => {
|
|
13
|
+
calls.push(args);
|
|
14
|
+
const joined = args.join(' ');
|
|
15
|
+
const route = routes.find(([match]) => joined.includes(match));
|
|
16
|
+
if (route === undefined)
|
|
17
|
+
throw new Error(`unrouted gh call: ${joined}`);
|
|
18
|
+
if (route[1] instanceof Error)
|
|
19
|
+
throw route[1];
|
|
20
|
+
return route[1];
|
|
21
|
+
},
|
|
22
|
+
sleep: async () => undefined,
|
|
23
|
+
warn: () => undefined,
|
|
24
|
+
});
|
|
25
|
+
const env = {
|
|
26
|
+
api,
|
|
27
|
+
limits: { ...DEFAULT_LOG_LIMITS, ...limits },
|
|
28
|
+
repository: 'acme/widgets',
|
|
29
|
+
runId: '123',
|
|
30
|
+
streamLog: async function* (path) {
|
|
31
|
+
streamed.push(path);
|
|
32
|
+
const key = Object.keys(logs).find((suffix) => path.endsWith(suffix));
|
|
33
|
+
if (key === undefined)
|
|
34
|
+
throw new Error(`unrouted log stream: ${path}`);
|
|
35
|
+
const reply = logs[key];
|
|
36
|
+
if (reply instanceof Error)
|
|
37
|
+
throw reply;
|
|
38
|
+
for (const chunk of Array.isArray(reply) ? reply : [reply])
|
|
39
|
+
yield Buffer.from(chunk);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return { api, calls, env, streamed };
|
|
43
|
+
}
|
|
44
|
+
/** Installs a POSIX `gh` stub first on PATH. Returns the restore function. */
|
|
45
|
+
export function installFakeGh(script) {
|
|
46
|
+
const directory = mkdtempSync(join(tmpdir(), 'fake-gh-'));
|
|
47
|
+
const file = join(directory, 'gh');
|
|
48
|
+
writeFileSync(file, `#!/bin/sh\n${script}\n`);
|
|
49
|
+
chmodSync(file, 0o755);
|
|
50
|
+
const previous = process.env.PATH;
|
|
51
|
+
process.env.PATH = `${directory}:${previous ?? ''}`;
|
|
52
|
+
return () => {
|
|
53
|
+
process.env.PATH = previous;
|
|
54
|
+
rmSync(directory, { recursive: true, force: true });
|
|
55
|
+
};
|
|
56
|
+
}
|