vouchington-tooling 0.1.6 → 0.1.8
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
CHANGED
|
@@ -50,7 +50,8 @@ vouchington stage-review-payload optional|required <source> <destination>
|
|
|
50
50
|
`download-optional-run-artifacts` uses the current Actions run and host. Pattern mode discovers
|
|
51
51
|
non-expired artifacts across the run, keeps the first result for each name (matching `gh run
|
|
52
52
|
download`), and extracts each selected name into its own directory. Ordinary absence is reported as
|
|
53
|
-
`availability=unavailable
|
|
53
|
+
`availability=unavailable`. Artifact listing retries up to three times with bounded backoff;
|
|
54
|
+
exhausted transport errors, invalid names, and cancellation remain hard failures.
|
|
54
55
|
|
|
55
56
|
`retrospective-transcript` discovers Codex and Claude transcripts by default. It also reads a
|
|
56
57
|
Claude-compatible transcript when `CURSOR_SESSION_ID` is set, and Grok's `updates.jsonl` session
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type DependencyUpdate = Record<'dependencyName' | 'directory' | 'newVersion' | 'packageEcosystem' | 'prevVersion' | 'updateType', string>;
|
|
2
|
+
export interface ScriptResult {
|
|
3
|
+
failures: string[];
|
|
4
|
+
infos: string[];
|
|
5
|
+
mutationRequests: Array<{
|
|
6
|
+
body: string;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
method: string;
|
|
9
|
+
url: string;
|
|
10
|
+
}>;
|
|
11
|
+
restGetCalls: Array<Record<string, unknown>>;
|
|
12
|
+
warnings: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare function update(prevVersion: string, newVersion: string, updateType: string, dependencyName?: string): DependencyUpdate;
|
|
15
|
+
export declare function runPolicy(metadata: DependencyUpdate[] | string | undefined, pullRequestOverrides?: Record<string, unknown>, freshPullRequestOverrides?: Record<string, unknown>, mergeToken?: string | undefined, mutationResult?: {
|
|
16
|
+
jsonError?: Error;
|
|
17
|
+
payload?: unknown;
|
|
18
|
+
status?: number;
|
|
19
|
+
}, dependabot?: {
|
|
20
|
+
directory: string;
|
|
21
|
+
ecosystem: string;
|
|
22
|
+
}, expectedBase?: string, expectedHead?: string, manualRules?: string, confirmedPullRequestOverrides?: Error | Record<string, unknown>, initialRefreshError?: Error): Promise<ScriptResult>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { parse as load } from 'yaml';
|
|
3
|
+
const source = readFileSync('.github/actions/dependabot-automerge/action.yml', 'utf8');
|
|
4
|
+
const action = load(source);
|
|
5
|
+
const script = action.runs.steps.find((step) => step.uses?.startsWith('actions/github-script@'))
|
|
6
|
+
?.with?.script;
|
|
7
|
+
export function update(prevVersion, newVersion, updateType, dependencyName = 'example') {
|
|
8
|
+
return {
|
|
9
|
+
dependencyName,
|
|
10
|
+
directory: '/',
|
|
11
|
+
newVersion,
|
|
12
|
+
packageEcosystem: 'npm',
|
|
13
|
+
prevVersion,
|
|
14
|
+
updateType,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export async function runPolicy(metadata, pullRequestOverrides = {}, freshPullRequestOverrides = {}, mergeToken = 'merge-token', mutationResult = {}, dependabot = { directory: '/', ecosystem: 'npm' }, expectedBase, expectedHead, manualRules = '[]', confirmedPullRequestOverrides = freshPullRequestOverrides, initialRefreshError) {
|
|
18
|
+
if (!script)
|
|
19
|
+
throw new Error('Dependabot auto-merge script is missing');
|
|
20
|
+
const failures = [];
|
|
21
|
+
const infos = [];
|
|
22
|
+
const mutationRequests = [];
|
|
23
|
+
const restGetCalls = [];
|
|
24
|
+
const warnings = [];
|
|
25
|
+
const eventPullRequest = {
|
|
26
|
+
auto_merge: null,
|
|
27
|
+
base: { ref: 'main', sha: 'a'.repeat(40) },
|
|
28
|
+
draft: false,
|
|
29
|
+
head: {
|
|
30
|
+
ref: 'dependabot/npm_and_yarn/example-1.5.0',
|
|
31
|
+
repo: { full_name: 'example-owner/example-repo' },
|
|
32
|
+
sha: 'b'.repeat(40),
|
|
33
|
+
},
|
|
34
|
+
node_id: 'PR_node_id',
|
|
35
|
+
number: 123,
|
|
36
|
+
merged: false,
|
|
37
|
+
state: 'open',
|
|
38
|
+
title: 'Bump dependencies',
|
|
39
|
+
user: { login: 'dependabot[bot]' },
|
|
40
|
+
...pullRequestOverrides,
|
|
41
|
+
};
|
|
42
|
+
const github = {
|
|
43
|
+
rest: {
|
|
44
|
+
pulls: {
|
|
45
|
+
async get(args) {
|
|
46
|
+
restGetCalls.push(args);
|
|
47
|
+
if (restGetCalls.length === 1 && initialRefreshError)
|
|
48
|
+
throw initialRefreshError;
|
|
49
|
+
if (restGetCalls.length > 1 && confirmedPullRequestOverrides instanceof Error)
|
|
50
|
+
throw confirmedPullRequestOverrides;
|
|
51
|
+
const overrides = restGetCalls.length === 1 || confirmedPullRequestOverrides instanceof Error
|
|
52
|
+
? freshPullRequestOverrides
|
|
53
|
+
: confirmedPullRequestOverrides;
|
|
54
|
+
return { data: { ...eventPullRequest, ...overrides } };
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const context = {
|
|
60
|
+
payload: { pull_request: eventPullRequest, repository: { default_branch: 'main' } },
|
|
61
|
+
repo: { owner: 'example-owner', repo: 'example-repo' },
|
|
62
|
+
};
|
|
63
|
+
const core = {
|
|
64
|
+
setFailed(message) {
|
|
65
|
+
failures.push(message);
|
|
66
|
+
},
|
|
67
|
+
info(message) {
|
|
68
|
+
infos.push(message);
|
|
69
|
+
},
|
|
70
|
+
warning(message) {
|
|
71
|
+
warnings.push(message);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const environment = {
|
|
75
|
+
DEPENDABOT_DIRECTORY: dependabot.directory,
|
|
76
|
+
DEPENDABOT_ECOSYSTEM: dependabot.ecosystem,
|
|
77
|
+
EXPECTED_BASE_SHA: expectedBase ?? String(eventPullRequest.base.sha),
|
|
78
|
+
EXPECTED_HEAD_SHA: expectedHead ?? String(eventPullRequest.head.sha),
|
|
79
|
+
GRAPHQL_URL: 'https://github.example.test/api/graphql',
|
|
80
|
+
MANUAL_UPDATE_RULES: manualRules,
|
|
81
|
+
};
|
|
82
|
+
if (metadata !== undefined)
|
|
83
|
+
environment.UPDATED_DEPENDENCIES_JSON =
|
|
84
|
+
typeof metadata === 'string' ? metadata : JSON.stringify(metadata);
|
|
85
|
+
if (mergeToken !== undefined)
|
|
86
|
+
environment.AUTOMERGE_TOKEN = mergeToken;
|
|
87
|
+
const fetch = async (url, init) => {
|
|
88
|
+
if (typeof init.body !== 'string')
|
|
89
|
+
throw new TypeError('Dependabot auto-merge mutation body must be a string');
|
|
90
|
+
const body = init.body;
|
|
91
|
+
mutationRequests.push({
|
|
92
|
+
body,
|
|
93
|
+
headers: init.headers,
|
|
94
|
+
method: String(init.method),
|
|
95
|
+
url,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
async json() {
|
|
99
|
+
if (mutationResult.jsonError)
|
|
100
|
+
throw mutationResult.jsonError;
|
|
101
|
+
return (mutationResult.payload ??
|
|
102
|
+
(body.includes('disablePullRequestAutoMerge')
|
|
103
|
+
? { data: { disablePullRequestAutoMerge: { clientMutationId: null } } }
|
|
104
|
+
: { data: { enablePullRequestAutoMerge: { clientMutationId: null } } }));
|
|
105
|
+
},
|
|
106
|
+
ok: (mutationResult.status ?? 200) < 400,
|
|
107
|
+
status: mutationResult.status ?? 200,
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
const AsyncFunction = Object.getPrototypeOf(async () => undefined).constructor;
|
|
111
|
+
await new AsyncFunction('github', 'context', 'core', 'process', 'fetch', script)(github, context, core, { env: environment }, fetch);
|
|
112
|
+
return { failures, infos, mutationRequests, restGetCalls, warnings };
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vouchington-tooling",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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": {
|
|
@@ -71,15 +71,39 @@ download_exact() {
|
|
|
71
71
|
GH_HOST="$github_host" gh run download "$GITHUB_RUN_ID" --repo "$repository" --name "$artifact" --dir "$directory"
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
list_artifact_names_once() {
|
|
75
75
|
GH_HOST="$github_host" gh api \
|
|
76
76
|
--paginate \
|
|
77
77
|
"repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?per_page=100" \
|
|
78
78
|
--jq '.artifacts[] | select(.expired | not) | .name'
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
list_artifact_names() {
|
|
82
|
+
local attempt status=0 delay artifact_names
|
|
83
|
+
for attempt in 1 2 3; do
|
|
84
|
+
if artifact_names=$(list_artifact_names_once); then
|
|
85
|
+
[ -z "$artifact_names" ] || printf '%s\n' "$artifact_names"
|
|
86
|
+
return 0
|
|
87
|
+
else
|
|
88
|
+
status=$?
|
|
89
|
+
fi
|
|
90
|
+
case "$status" in 130|143) return "$status" ;; esac
|
|
91
|
+
if [ "$attempt" -lt 3 ]; then
|
|
92
|
+
delay=2
|
|
93
|
+
[ "$attempt" -eq 2 ] && delay=5
|
|
94
|
+
echo "::warning::Optional same-run artifact listing failed (attempt $attempt/3 exit=$status); retrying in ${delay}s" >&2
|
|
95
|
+
if sleep "$delay"; then :; else return $?; fi
|
|
96
|
+
fi
|
|
97
|
+
done
|
|
98
|
+
echo "[optional-run-artifacts] listing exhausted attempts=3 exit=$status" >&2
|
|
99
|
+
return "$status"
|
|
100
|
+
}
|
|
101
|
+
|
|
81
102
|
download_pattern() {
|
|
82
|
-
artifacts=$(list_artifact_names
|
|
103
|
+
artifacts=$(list_artifact_names) || return $?
|
|
104
|
+
if [ -n "$artifacts" ]; then
|
|
105
|
+
artifacts=$(printf '%s\n' "$artifacts" | awk '!seen[$0]++')
|
|
106
|
+
fi
|
|
83
107
|
selected_artifacts=()
|
|
84
108
|
while IFS= read -r artifact; do
|
|
85
109
|
[ -n "$artifact" ] || continue
|