@trebired/git-host 2.2.0 → 3.1.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/CHANGELOG.md +20 -0
- package/README.md +103 -11
- package/dist/api/forge/actions/filters.d.ts +10 -0
- package/dist/api/forge/actions/filters.d.ts.map +1 -0
- package/dist/api/forge/actions/filters.js +63 -0
- package/dist/api/forge/actions/filters.js.map +1 -0
- package/dist/api/forge/actions/run.d.ts +8 -0
- package/dist/api/forge/actions/run.d.ts.map +1 -0
- package/dist/api/forge/actions/run.js +129 -0
- package/dist/api/forge/actions/run.js.map +1 -0
- package/dist/api/forge/actions.d.ts +3 -12
- package/dist/api/forge/actions.d.ts.map +1 -1
- package/dist/api/forge/actions.js +2 -216
- package/dist/api/forge/actions.js.map +1 -1
- package/dist/api/handler/response.d.ts.map +1 -1
- package/dist/api/handler/response.js +55 -1
- package/dist/api/handler/response.js.map +1 -1
- package/dist/core/actions/environment.d.ts +9 -0
- package/dist/core/actions/environment.d.ts.map +1 -0
- package/dist/core/actions/environment.js +64 -0
- package/dist/core/actions/environment.js.map +1 -0
- package/dist/core/actions/expressions/read.d.ts +7 -0
- package/dist/core/actions/expressions/read.d.ts.map +1 -0
- package/dist/core/actions/expressions/read.js +148 -0
- package/dist/core/actions/expressions/read.js.map +1 -0
- package/dist/core/actions/expressions/tokenize.d.ts +4 -0
- package/dist/core/actions/expressions/tokenize.d.ts.map +1 -0
- package/dist/core/actions/expressions/tokenize.js +112 -0
- package/dist/core/actions/expressions/tokenize.js.map +1 -0
- package/dist/core/actions/expressions/types.d.ts +38 -0
- package/dist/core/actions/expressions/types.d.ts.map +1 -0
- package/dist/core/actions/expressions/types.js +2 -0
- package/dist/core/actions/expressions/types.js.map +1 -0
- package/dist/core/actions/expressions.d.ts +2 -9
- package/dist/core/actions/expressions.d.ts.map +1 -1
- package/dist/core/actions/expressions.js +2 -256
- package/dist/core/actions/expressions.js.map +1 -1
- package/dist/core/actions/local_runner.d.ts +5 -0
- package/dist/core/actions/local_runner.d.ts.map +1 -1
- package/dist/core/actions/local_runner.js +70 -18
- package/dist/core/actions/local_runner.js.map +1 -1
- package/dist/core/actions/node_runner.d.ts.map +1 -1
- package/dist/core/actions/node_runner.js +2 -1
- package/dist/core/actions/node_runner.js.map +1 -1
- package/dist/core/actions/normalize/finalize.d.ts +7 -0
- package/dist/core/actions/normalize/finalize.d.ts.map +1 -0
- package/dist/core/actions/normalize/finalize.js +70 -0
- package/dist/core/actions/normalize/finalize.js.map +1 -0
- package/dist/core/actions/normalize/shared.d.ts +19 -0
- package/dist/core/actions/normalize/shared.d.ts.map +1 -0
- package/dist/core/actions/normalize/shared.js +289 -0
- package/dist/core/actions/normalize/shared.js.map +1 -0
- package/dist/core/actions/normalize.d.ts +1 -3
- package/dist/core/actions/normalize.d.ts.map +1 -1
- package/dist/core/actions/normalize.js +2 -354
- package/dist/core/actions/normalize.js.map +1 -1
- package/dist/core/actions/redaction.d.ts +13 -2
- package/dist/core/actions/redaction.d.ts.map +1 -1
- package/dist/core/actions/redaction.js +20 -5
- package/dist/core/actions/redaction.js.map +1 -1
- package/dist/core/actions/release_assets.d.ts.map +1 -1
- package/dist/core/actions/release_assets.js.map +1 -1
- package/dist/core/actions/runner/launch.d.ts.map +1 -1
- package/dist/core/actions/runner/launch.js +12 -8
- package/dist/core/actions/runner/launch.js.map +1 -1
- package/dist/core/actions/sandbox.d.ts +4 -0
- package/dist/core/actions/sandbox.d.ts.map +1 -0
- package/dist/core/actions/sandbox.js +46 -0
- package/dist/core/actions/sandbox.js.map +1 -0
- package/dist/core/archive/commit.d.ts +6 -0
- package/dist/core/archive/commit.d.ts.map +1 -0
- package/dist/core/archive/commit.js +34 -0
- package/dist/core/archive/commit.js.map +1 -0
- package/dist/core/archive/context.d.ts +32 -0
- package/dist/core/archive/context.d.ts.map +1 -0
- package/dist/core/archive/context.js +61 -0
- package/dist/core/archive/context.js.map +1 -0
- package/dist/core/archive/generation.d.ts +11 -0
- package/dist/core/archive/generation.d.ts.map +1 -0
- package/dist/core/archive/generation.js +62 -0
- package/dist/core/archive/generation.js.map +1 -0
- package/dist/core/archive/links.d.ts +5 -0
- package/dist/core/archive/links.d.ts.map +1 -0
- package/dist/core/archive/links.js +62 -0
- package/dist/core/archive/links.js.map +1 -0
- package/dist/core/archive/open.d.ts +15 -0
- package/dist/core/archive/open.d.ts.map +1 -0
- package/dist/core/archive/open.js +159 -0
- package/dist/core/archive/open.js.map +1 -0
- package/dist/core/archive/read.d.ts +19 -0
- package/dist/core/archive/read.d.ts.map +1 -0
- package/dist/core/archive/read.js +62 -0
- package/dist/core/archive/read.js.map +1 -0
- package/dist/core/archive/resolve.d.ts +8 -0
- package/dist/core/archive/resolve.d.ts.map +1 -0
- package/dist/core/archive/resolve.js +67 -0
- package/dist/core/archive/resolve.js.map +1 -0
- package/dist/core/archive/shared.d.ts +50 -0
- package/dist/core/archive/shared.d.ts.map +1 -0
- package/dist/core/archive/shared.js +119 -0
- package/dist/core/archive/shared.js.map +1 -0
- package/dist/core/archive.d.ts +2 -18
- package/dist/core/archive.d.ts.map +1 -1
- package/dist/core/archive.js +16 -556
- package/dist/core/archive.js.map +1 -1
- package/dist/core/create/git/forge/base_methods.d.ts +5 -0
- package/dist/core/create/git/forge/base_methods.d.ts.map +1 -0
- package/dist/core/create/git/forge/base_methods.js +59 -0
- package/dist/core/create/git/forge/base_methods.js.map +1 -0
- package/dist/core/create/git/forge/context.d.ts +38 -0
- package/dist/core/create/git/forge/context.d.ts.map +1 -0
- package/dist/core/create/git/forge/context.js +174 -0
- package/dist/core/create/git/forge/context.js.map +1 -0
- package/dist/core/create/git/forge/fork_methods.d.ts +5 -0
- package/dist/core/create/git/forge/fork_methods.d.ts.map +1 -0
- package/dist/core/create/git/forge/fork_methods.js +133 -0
- package/dist/core/create/git/forge/fork_methods.js.map +1 -0
- package/dist/core/create/git/forge/release_methods.d.ts +5 -0
- package/dist/core/create/git/forge/release_methods.d.ts.map +1 -0
- package/dist/core/create/git/forge/release_methods.js +116 -0
- package/dist/core/create/git/forge/release_methods.js.map +1 -0
- package/dist/core/create/git/forge/shared.d.ts +9 -0
- package/dist/core/create/git/forge/shared.d.ts.map +1 -0
- package/dist/core/create/git/forge/shared.js +80 -0
- package/dist/core/create/git/forge/shared.js.map +1 -0
- package/dist/core/create/git/forge/social_methods.d.ts +5 -0
- package/dist/core/create/git/forge/social_methods.d.ts.map +1 -0
- package/dist/core/create/git/forge/social_methods.js +31 -0
- package/dist/core/create/git/forge/social_methods.js.map +1 -0
- package/dist/core/create/git/forge.d.ts.map +1 -1
- package/dist/core/create/git/forge.js +10 -594
- package/dist/core/create/git/forge.js.map +1 -1
- package/dist/core/create/git/host.d.ts.map +1 -1
- package/dist/core/create/git/host.js +139 -114
- package/dist/core/create/git/host.js.map +1 -1
- package/dist/core/create_git_host/remote_methods.d.ts.map +1 -1
- package/dist/core/create_git_host/remote_methods.js +92 -97
- package/dist/core/create_git_host/remote_methods.js.map +1 -1
- package/dist/core/forge_actions/job/release_asset.d.ts +17 -0
- package/dist/core/forge_actions/job/release_asset.d.ts.map +1 -0
- package/dist/core/forge_actions/job/release_asset.js +62 -0
- package/dist/core/forge_actions/job/release_asset.js.map +1 -0
- package/dist/core/forge_actions/job/steps.d.ts +37 -0
- package/dist/core/forge_actions/job/steps.d.ts.map +1 -0
- package/dist/core/forge_actions/job/steps.js +228 -0
- package/dist/core/forge_actions/job/steps.js.map +1 -0
- package/dist/core/forge_actions/runtime/api.d.ts +26 -0
- package/dist/core/forge_actions/runtime/api.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/api.js +210 -0
- package/dist/core/forge_actions/runtime/api.js.map +1 -0
- package/dist/core/forge_actions/runtime/engine.d.ts +25 -0
- package/dist/core/forge_actions/runtime/engine.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/engine.js +28 -0
- package/dist/core/forge_actions/runtime/engine.js.map +1 -0
- package/dist/core/forge_actions/runtime/job/execute.d.ts +19 -0
- package/dist/core/forge_actions/runtime/job/execute.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/job/execute.js +191 -0
- package/dist/core/forge_actions/runtime/job/execute.js.map +1 -0
- package/dist/core/forge_actions/runtime/job/step/execute.d.ts +7 -0
- package/dist/core/forge_actions/runtime/job/step/execute.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/job/step/execute.js +176 -0
- package/dist/core/forge_actions/runtime/job/step/execute.js.map +1 -0
- package/dist/core/forge_actions/runtime/queue.d.ts +11 -0
- package/dist/core/forge_actions/runtime/queue.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/queue.js +144 -0
- package/dist/core/forge_actions/runtime/queue.js.map +1 -0
- package/dist/core/forge_actions/runtime/run/execute.d.ts +9 -0
- package/dist/core/forge_actions/runtime/run/execute.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/run/execute.js +191 -0
- package/dist/core/forge_actions/runtime/run/execute.js.map +1 -0
- package/dist/core/forge_actions/runtime/types.d.ts +24 -0
- package/dist/core/forge_actions/runtime/types.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime/types.js +2 -0
- package/dist/core/forge_actions/runtime/types.js.map +1 -0
- package/dist/core/forge_actions/runtime_support.d.ts +57 -0
- package/dist/core/forge_actions/runtime_support.d.ts.map +1 -0
- package/dist/core/forge_actions/runtime_support.js +276 -0
- package/dist/core/forge_actions/runtime_support.js.map +1 -0
- package/dist/core/forge_actions/shared.d.ts +92 -0
- package/dist/core/forge_actions/shared.d.ts.map +1 -0
- package/dist/core/forge_actions/shared.js +204 -0
- package/dist/core/forge_actions/shared.js.map +1 -0
- package/dist/core/forge_actions.d.ts +17 -24
- package/dist/core/forge_actions.d.ts.map +1 -1
- package/dist/core/forge_actions.js +33 -1459
- package/dist/core/forge_actions.js.map +1 -1
- package/dist/core/git_forge/storage_memory/actions.d.ts +5 -0
- package/dist/core/git_forge/storage_memory/actions.d.ts.map +1 -0
- package/dist/core/git_forge/storage_memory/actions.js +155 -0
- package/dist/core/git_forge/storage_memory/actions.js.map +1 -0
- package/dist/core/git_forge/storage_memory/adapter.d.ts +4 -0
- package/dist/core/git_forge/storage_memory/adapter.d.ts.map +1 -0
- package/dist/core/git_forge/storage_memory/adapter.js +118 -0
- package/dist/core/git_forge/storage_memory/adapter.js.map +1 -0
- package/dist/core/git_forge/storage_memory/state.d.ts +27 -0
- package/dist/core/git_forge/storage_memory/state.d.ts.map +1 -0
- package/dist/core/git_forge/storage_memory/state.js +53 -0
- package/dist/core/git_forge/storage_memory/state.js.map +1 -0
- package/dist/core/git_forge/storage_memory.d.ts +1 -3
- package/dist/core/git_forge/storage_memory.d.ts.map +1 -1
- package/dist/core/git_forge/storage_memory.js +1 -352
- package/dist/core/git_forge/storage_memory.js.map +1 -1
- package/dist/core/inspect/history.d.ts +13 -0
- package/dist/core/inspect/history.d.ts.map +1 -0
- package/dist/core/inspect/history.js +176 -0
- package/dist/core/inspect/history.js.map +1 -0
- package/dist/core/inspect/linguist.d.ts +12 -0
- package/dist/core/inspect/linguist.d.ts.map +1 -0
- package/dist/core/inspect/linguist.js +128 -0
- package/dist/core/inspect/linguist.js.map +1 -0
- package/dist/core/inspect/search_archive.d.ts +16 -0
- package/dist/core/inspect/search_archive.d.ts.map +1 -0
- package/dist/core/inspect/search_archive.js +88 -0
- package/dist/core/inspect/search_archive.js.map +1 -0
- package/dist/core/inspect/shared.d.ts +5 -0
- package/dist/core/inspect/shared.d.ts.map +1 -0
- package/dist/core/inspect/shared.js +47 -0
- package/dist/core/inspect/shared.js.map +1 -0
- package/dist/core/inspect/tree_blob.d.ts +16 -0
- package/dist/core/inspect/tree_blob.d.ts.map +1 -0
- package/dist/core/inspect/tree_blob.js +80 -0
- package/dist/core/inspect/tree_blob.js.map +1 -0
- package/dist/core/inspect.d.ts +3 -46
- package/dist/core/inspect.d.ts.map +1 -1
- package/dist/core/inspect.js +3 -546
- package/dist/core/inspect.js.map +1 -1
- package/dist/core/inspection/analysis.d.ts +4 -0
- package/dist/core/inspection/analysis.d.ts.map +1 -0
- package/dist/core/inspection/analysis.js +25 -0
- package/dist/core/inspection/analysis.js.map +1 -0
- package/dist/core/inspection/shared.d.ts +18 -0
- package/dist/core/inspection/shared.d.ts.map +1 -0
- package/dist/core/inspection/shared.js +112 -0
- package/dist/core/inspection/shared.js.map +1 -0
- package/dist/core/inspection/snapshots.d.ts +6 -0
- package/dist/core/inspection/snapshots.d.ts.map +1 -0
- package/dist/core/inspection/snapshots.js +270 -0
- package/dist/core/inspection/snapshots.js.map +1 -0
- package/dist/core/inspection/target.d.ts +4 -0
- package/dist/core/inspection/target.d.ts.map +1 -0
- package/dist/core/inspection/target.js +97 -0
- package/dist/core/inspection/target.js.map +1 -0
- package/dist/core/inspection/tree.d.ts +6 -0
- package/dist/core/inspection/tree.d.ts.map +1 -0
- package/dist/core/inspection/tree.js +103 -0
- package/dist/core/inspection/tree.js.map +1 -0
- package/dist/core/inspection.d.ts +6 -10
- package/dist/core/inspection.d.ts.map +1 -1
- package/dist/core/inspection.js +6 -592
- package/dist/core/inspection.js.map +1 -1
- package/dist/http/handler.d.ts.map +1 -1
- package/dist/http/handler.js +157 -133
- package/dist/http/handler.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ssh/server.d.ts.map +1 -1
- package/dist/ssh/server.js +171 -243
- package/dist/ssh/server.js.map +1 -1
- package/dist/types/forge/workflows/actions.d.ts +70 -0
- package/dist/types/forge/workflows/actions.d.ts.map +1 -0
- package/dist/types/forge/workflows/actions.js +3 -0
- package/dist/types/forge/workflows/actions.js.map +1 -0
- package/dist/types/forge/workflows/definition.d.ts +115 -0
- package/dist/types/forge/workflows/definition.d.ts.map +1 -0
- package/dist/types/forge/workflows/definition.js +2 -0
- package/dist/types/forge/workflows/definition.js.map +1 -0
- package/dist/types/forge/workflows/runs.d.ts +184 -0
- package/dist/types/forge/workflows/runs.d.ts.map +1 -0
- package/dist/types/forge/workflows/runs.js +2 -0
- package/dist/types/forge/workflows/runs.js.map +1 -0
- package/dist/types/forge/workflows.d.ts +3 -331
- package/dist/types/forge/workflows.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/{bin → native}/git-host-actions-runner-darwin-arm64 +0 -0
- package/{bin → native}/git-host-actions-runner-darwin-x64 +0 -0
- package/{bin → native}/git-host-actions-runner-linux-arm64-gnu +0 -0
- package/{bin → native}/git-host-actions-runner-linux-x64-gnu +0 -0
- package/package.json +63 -11
- package/dist/frontend/js/utils/text.d.ts +0 -2
- package/dist/frontend/js/utils/text.d.ts.map +0 -1
- package/dist/frontend/js/utils/text.js +0 -4
- package/dist/frontend/js/utils/text.js.map +0 -1
- /package/{bin → native}/.gitkeep +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { GitHostError } from "../../../errors.js";
|
|
2
|
+
import { text } from "../../../utils/text.js";
|
|
3
|
+
const EXPRESSION_WRAPPER = /^\s*\$\{\{\s*([\s\S]*?)\s*\}\}\s*$/;
|
|
4
|
+
function unwrapExpression(input) {
|
|
5
|
+
const raw = text(input);
|
|
6
|
+
const match = raw.match(EXPRESSION_WRAPPER);
|
|
7
|
+
return match ? text(match[1]) : raw;
|
|
8
|
+
}
|
|
9
|
+
function isIdentifierStart(char) {
|
|
10
|
+
return /[A-Za-z_]/.test(char);
|
|
11
|
+
}
|
|
12
|
+
function isIdentifierChar(char) {
|
|
13
|
+
return /[A-Za-z0-9_-]/.test(char);
|
|
14
|
+
}
|
|
15
|
+
function tokenizeQuotedString(source, input, start) {
|
|
16
|
+
const quote = source[start] || "";
|
|
17
|
+
let index = start + 1;
|
|
18
|
+
let value = "";
|
|
19
|
+
while (index < source.length) {
|
|
20
|
+
const current = source[index] || "";
|
|
21
|
+
if (current === "\\") {
|
|
22
|
+
value += source[index + 1] || "";
|
|
23
|
+
index += 2;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (current === quote)
|
|
27
|
+
return { index: index + 1, token: { type: "string", value } };
|
|
28
|
+
value += current;
|
|
29
|
+
index += 1;
|
|
30
|
+
}
|
|
31
|
+
throw new GitHostError("forge_invalid_workflow_definition", "Unterminated workflow expression string literal.", {
|
|
32
|
+
expression: input,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function tokenizeIdentifier(source, start) {
|
|
36
|
+
let value = source[start] || "";
|
|
37
|
+
let index = start + 1;
|
|
38
|
+
while (index < source.length && isIdentifierChar(source[index] || "")) {
|
|
39
|
+
value += source[index] || "";
|
|
40
|
+
index += 1;
|
|
41
|
+
}
|
|
42
|
+
if (value === "true" || value === "false") {
|
|
43
|
+
return {
|
|
44
|
+
index,
|
|
45
|
+
token: { type: "boolean", value: value === "true" },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
index,
|
|
50
|
+
token: { type: "identifier", value },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function readOperatorToken(source, index) {
|
|
54
|
+
const char = source[index] || "";
|
|
55
|
+
if (char === "(")
|
|
56
|
+
return { type: "lparen" };
|
|
57
|
+
if (char === ")")
|
|
58
|
+
return { type: "rparen" };
|
|
59
|
+
if (char === ".")
|
|
60
|
+
return { type: "dot" };
|
|
61
|
+
if (char === "!" && source[index + 1] === "=")
|
|
62
|
+
return { type: "neq" };
|
|
63
|
+
if (char === "=" && source[index + 1] === "=")
|
|
64
|
+
return { type: "eq" };
|
|
65
|
+
if (char === "&" && source[index + 1] === "&")
|
|
66
|
+
return { type: "and" };
|
|
67
|
+
if (char === "|" && source[index + 1] === "|")
|
|
68
|
+
return { type: "or" };
|
|
69
|
+
if (char === "!")
|
|
70
|
+
return { type: "not" };
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
function operatorWidth(token) {
|
|
74
|
+
return token.type === "and" || token.type === "or" || token.type === "eq" || token.type === "neq" ? 2 : 1;
|
|
75
|
+
}
|
|
76
|
+
function tokenizeExpression(input) {
|
|
77
|
+
const source = unwrapExpression(input);
|
|
78
|
+
const tokens = [];
|
|
79
|
+
let index = 0;
|
|
80
|
+
while (index < source.length) {
|
|
81
|
+
const char = source[index] || "";
|
|
82
|
+
if (/\s/.test(char)) {
|
|
83
|
+
index += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const operator = readOperatorToken(source, index);
|
|
87
|
+
if (operator) {
|
|
88
|
+
tokens.push(operator);
|
|
89
|
+
index += operatorWidth(operator);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (char === "'" || char === "\"") {
|
|
93
|
+
const quoted = tokenizeQuotedString(source, input, index);
|
|
94
|
+
tokens.push(quoted.token);
|
|
95
|
+
index = quoted.index;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (isIdentifierStart(char)) {
|
|
99
|
+
const identifier = tokenizeIdentifier(source, index);
|
|
100
|
+
tokens.push(identifier.token);
|
|
101
|
+
index = identifier.index;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
throw new GitHostError("forge_invalid_workflow_definition", `Unsupported token "${char}" in workflow expression.`, {
|
|
105
|
+
expression: input,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
tokens.push({ type: "eof" });
|
|
109
|
+
return tokens;
|
|
110
|
+
}
|
|
111
|
+
export { tokenizeExpression };
|
|
112
|
+
//# sourceMappingURL=tokenize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenize.js","sourceRoot":"","sources":["../../../../src/core/actions/expressions/tokenize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAIrC,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEhE,SAAS,gBAAgB,CAAC,KAAa;IACrC,MAAM,GAAG,GAAG,IAAI,CAAC,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ACtB,KAAK,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;YACjC,SAAS;QACX,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;YAC1D,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YACrB,SAAS;QACX,CAAC;QACD,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACrD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;YAC9B,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;YACzB,SAAS;QACX,CAAC;QACD,MAAM,IAAI,YAAY,CAAC,mCAAmC,EAAE,sBAAsB,IAAI,2BAA2B,EAAE;YACjH,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type WorkflowExpressionContext = {
|
|
2
|
+
env?: Record<string, unknown>;
|
|
3
|
+
github?: Record<string, unknown>;
|
|
4
|
+
job?: Record<string, unknown>;
|
|
5
|
+
matrix?: Record<string, unknown>;
|
|
6
|
+
needs?: Record<string, unknown>;
|
|
7
|
+
secrets?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
type ExpressionToken = {
|
|
10
|
+
type: "boolean";
|
|
11
|
+
value: boolean;
|
|
12
|
+
} | {
|
|
13
|
+
type: "dot";
|
|
14
|
+
} | {
|
|
15
|
+
type: "eof";
|
|
16
|
+
} | {
|
|
17
|
+
type: "identifier";
|
|
18
|
+
value: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "lparen";
|
|
21
|
+
} | {
|
|
22
|
+
type: "neq";
|
|
23
|
+
} | {
|
|
24
|
+
type: "not";
|
|
25
|
+
} | {
|
|
26
|
+
type: "or";
|
|
27
|
+
} | {
|
|
28
|
+
type: "and";
|
|
29
|
+
} | {
|
|
30
|
+
type: "eq";
|
|
31
|
+
} | {
|
|
32
|
+
type: "rparen";
|
|
33
|
+
} | {
|
|
34
|
+
type: "string";
|
|
35
|
+
value: string;
|
|
36
|
+
};
|
|
37
|
+
export type { ExpressionToken, WorkflowExpressionContext };
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/actions/expressions/types.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,GAAG;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,KAAK,eAAe,GAChB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GACd;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,YAAY,EAAE,eAAe,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/actions/expressions/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
github?: Record<string, unknown>;
|
|
4
|
-
job?: Record<string, unknown>;
|
|
5
|
-
matrix?: Record<string, unknown>;
|
|
6
|
-
needs?: Record<string, unknown>;
|
|
7
|
-
secrets?: Record<string, unknown>;
|
|
8
|
-
};
|
|
9
|
-
declare function booleanValue(input: unknown): boolean;
|
|
1
|
+
import { booleanValue } from "./expressions/read.js";
|
|
2
|
+
import type { WorkflowExpressionContext } from "./expressions/types.js";
|
|
10
3
|
declare function resolveWorkflowExpression(input: string, context: WorkflowExpressionContext): unknown;
|
|
11
4
|
declare function resolveWorkflowString(input: string, context: WorkflowExpressionContext): string;
|
|
12
5
|
declare function resolveWorkflowBoolean(input: unknown, context: WorkflowExpressionContext, fallback?: boolean): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../../src/core/actions/expressions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../../../src/core/actions/expressions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA0B,MAAM,uBAAuB,CAAC;AAE7E,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAExE,iBAAS,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAG7F;AAED,iBAAS,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAOxF;AAED,iBAAS,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,QAAQ,UAAO,GAAG,OAAO,CAI5G;AAED,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,GACtB,CAAC;AAEF,YAAY,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1,260 +1,6 @@
|
|
|
1
|
-
import { GitHostError } from "../../errors.js";
|
|
2
1
|
import { text } from "../../utils/text.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function unwrapExpression(input) {
|
|
6
|
-
const raw = text(input);
|
|
7
|
-
const match = raw.match(EXPRESSION_WRAPPER);
|
|
8
|
-
return match ? text(match[1]) : raw;
|
|
9
|
-
}
|
|
10
|
-
function isIdentifierStart(char) {
|
|
11
|
-
return /[A-Za-z_]/.test(char);
|
|
12
|
-
}
|
|
13
|
-
function isIdentifierChar(char) {
|
|
14
|
-
return /[A-Za-z0-9_-]/.test(char);
|
|
15
|
-
}
|
|
16
|
-
function tokenizeExpression(input) {
|
|
17
|
-
const source = unwrapExpression(input);
|
|
18
|
-
const tokens = [];
|
|
19
|
-
let index = 0;
|
|
20
|
-
while (index < source.length) {
|
|
21
|
-
const char = source[index] || "";
|
|
22
|
-
if (/\s/.test(char)) {
|
|
23
|
-
index += 1;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (char === "(") {
|
|
27
|
-
tokens.push({ type: "lparen" });
|
|
28
|
-
index += 1;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (char === ")") {
|
|
32
|
-
tokens.push({ type: "rparen" });
|
|
33
|
-
index += 1;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (char === ".") {
|
|
37
|
-
tokens.push({ type: "dot" });
|
|
38
|
-
index += 1;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (char === "!" && source[index + 1] === "=") {
|
|
42
|
-
tokens.push({ type: "neq" });
|
|
43
|
-
index += 2;
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
if (char === "=" && source[index + 1] === "=") {
|
|
47
|
-
tokens.push({ type: "eq" });
|
|
48
|
-
index += 2;
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (char === "&" && source[index + 1] === "&") {
|
|
52
|
-
tokens.push({ type: "and" });
|
|
53
|
-
index += 2;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (char === "|" && source[index + 1] === "|") {
|
|
57
|
-
tokens.push({ type: "or" });
|
|
58
|
-
index += 2;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (char === "!") {
|
|
62
|
-
tokens.push({ type: "not" });
|
|
63
|
-
index += 1;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (char === "'" || char === "\"") {
|
|
67
|
-
const quote = char;
|
|
68
|
-
let value = "";
|
|
69
|
-
index += 1;
|
|
70
|
-
while (index < source.length) {
|
|
71
|
-
const current = source[index] || "";
|
|
72
|
-
if (current === "\\") {
|
|
73
|
-
value += source[index + 1] || "";
|
|
74
|
-
index += 2;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (current === quote)
|
|
78
|
-
break;
|
|
79
|
-
value += current;
|
|
80
|
-
index += 1;
|
|
81
|
-
}
|
|
82
|
-
if ((source[index] || "") !== quote) {
|
|
83
|
-
throw new GitHostError("forge_invalid_workflow_definition", "Unterminated workflow expression string literal.", {
|
|
84
|
-
expression: input,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
index += 1;
|
|
88
|
-
tokens.push({ type: "string", value });
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (isIdentifierStart(char)) {
|
|
92
|
-
let value = char;
|
|
93
|
-
index += 1;
|
|
94
|
-
while (index < source.length && isIdentifierChar(source[index] || "")) {
|
|
95
|
-
value += source[index] || "";
|
|
96
|
-
index += 1;
|
|
97
|
-
}
|
|
98
|
-
if (value === "true") {
|
|
99
|
-
tokens.push({ type: "boolean", value: true });
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (value === "false") {
|
|
103
|
-
tokens.push({ type: "boolean", value: false });
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
tokens.push({ type: "identifier", value });
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
throw new GitHostError("forge_invalid_workflow_definition", `Unsupported token "${char}" in workflow expression.`, {
|
|
110
|
-
expression: input,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
tokens.push({ type: "eof" });
|
|
114
|
-
return tokens;
|
|
115
|
-
}
|
|
116
|
-
function readPathValue(context, pathSegments) {
|
|
117
|
-
let current = context;
|
|
118
|
-
for (const segment of pathSegments) {
|
|
119
|
-
if (!current || typeof current !== "object")
|
|
120
|
-
return undefined;
|
|
121
|
-
current = current[segment];
|
|
122
|
-
}
|
|
123
|
-
return current;
|
|
124
|
-
}
|
|
125
|
-
function booleanValue(input) {
|
|
126
|
-
if (typeof input === "boolean")
|
|
127
|
-
return input;
|
|
128
|
-
if (typeof input === "number")
|
|
129
|
-
return input !== 0;
|
|
130
|
-
if (typeof input === "string") {
|
|
131
|
-
const value = input.trim().toLowerCase();
|
|
132
|
-
if (!value)
|
|
133
|
-
return false;
|
|
134
|
-
if (value === "false" || value === "0" || value === "null" || value === "undefined")
|
|
135
|
-
return false;
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
return Boolean(input);
|
|
139
|
-
}
|
|
140
|
-
function coerceComparisonValue(input) {
|
|
141
|
-
if (typeof input === "boolean" || typeof input === "number" || typeof input === "string")
|
|
142
|
-
return input;
|
|
143
|
-
if (input == null)
|
|
144
|
-
return "";
|
|
145
|
-
return JSON.stringify(input);
|
|
146
|
-
}
|
|
147
|
-
function createExpressionReader(tokens, context) {
|
|
148
|
-
let index = 0;
|
|
149
|
-
function current() {
|
|
150
|
-
return tokens[index] || { type: "eof" };
|
|
151
|
-
}
|
|
152
|
-
function advance() {
|
|
153
|
-
index += 1;
|
|
154
|
-
}
|
|
155
|
-
function expect(type) {
|
|
156
|
-
if (current().type !== type) {
|
|
157
|
-
throw new GitHostError("forge_invalid_workflow_definition", `Unexpected token "${current().type}" in workflow expression.`, {
|
|
158
|
-
expected: type,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
advance();
|
|
162
|
-
}
|
|
163
|
-
function parseValue() {
|
|
164
|
-
const token = current();
|
|
165
|
-
if (token.type === "boolean") {
|
|
166
|
-
advance();
|
|
167
|
-
return token.value;
|
|
168
|
-
}
|
|
169
|
-
if (token.type === "string") {
|
|
170
|
-
advance();
|
|
171
|
-
return token.value;
|
|
172
|
-
}
|
|
173
|
-
if (token.type === "identifier") {
|
|
174
|
-
const first = token.value;
|
|
175
|
-
advance();
|
|
176
|
-
if (current().type === "lparen") {
|
|
177
|
-
if (!SUPPORTED_FUNCTIONS.has(first)) {
|
|
178
|
-
throw new GitHostError("forge_invalid_workflow_definition", `Unsupported workflow expression function "${first}()".`, {
|
|
179
|
-
function: first,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
advance();
|
|
183
|
-
expect("rparen");
|
|
184
|
-
if (first === "always")
|
|
185
|
-
return true;
|
|
186
|
-
if (first === "success")
|
|
187
|
-
return !booleanValue(readPathValue(context, ["job", "cancelled"])) && text(readPathValue(context, ["job", "status"])) !== "failed";
|
|
188
|
-
if (first === "failure")
|
|
189
|
-
return text(readPathValue(context, ["job", "status"])) === "failed";
|
|
190
|
-
if (first === "cancelled")
|
|
191
|
-
return text(readPathValue(context, ["job", "status"])) === "cancelled";
|
|
192
|
-
}
|
|
193
|
-
const pathSegments = [first];
|
|
194
|
-
while (current().type === "dot") {
|
|
195
|
-
advance();
|
|
196
|
-
const nextToken = current();
|
|
197
|
-
if (nextToken.type !== "identifier") {
|
|
198
|
-
throw new GitHostError("forge_invalid_workflow_definition", "Invalid workflow expression path.", {});
|
|
199
|
-
}
|
|
200
|
-
pathSegments.push(nextToken.value);
|
|
201
|
-
advance();
|
|
202
|
-
}
|
|
203
|
-
return readPathValue(context, pathSegments);
|
|
204
|
-
}
|
|
205
|
-
if (token.type === "lparen") {
|
|
206
|
-
advance();
|
|
207
|
-
const value = parseOr();
|
|
208
|
-
expect("rparen");
|
|
209
|
-
return value;
|
|
210
|
-
}
|
|
211
|
-
throw new GitHostError("forge_invalid_workflow_definition", `Unexpected token "${token.type}" in workflow expression.`, {});
|
|
212
|
-
}
|
|
213
|
-
function parseUnary() {
|
|
214
|
-
if (current().type === "not") {
|
|
215
|
-
advance();
|
|
216
|
-
return !booleanValue(parseUnary());
|
|
217
|
-
}
|
|
218
|
-
return parseValue();
|
|
219
|
-
}
|
|
220
|
-
function parseEquality() {
|
|
221
|
-
let left = parseUnary();
|
|
222
|
-
while (current().type === "eq" || current().type === "neq") {
|
|
223
|
-
const operator = current().type;
|
|
224
|
-
advance();
|
|
225
|
-
const right = parseUnary();
|
|
226
|
-
const leftValue = coerceComparisonValue(left);
|
|
227
|
-
const rightValue = coerceComparisonValue(right);
|
|
228
|
-
left = operator === "eq" ? leftValue === rightValue : leftValue !== rightValue;
|
|
229
|
-
}
|
|
230
|
-
return left;
|
|
231
|
-
}
|
|
232
|
-
function parseAnd() {
|
|
233
|
-
let left = parseEquality();
|
|
234
|
-
while (current().type === "and") {
|
|
235
|
-
advance();
|
|
236
|
-
left = booleanValue(left) && booleanValue(parseEquality());
|
|
237
|
-
}
|
|
238
|
-
return left;
|
|
239
|
-
}
|
|
240
|
-
function parseOr() {
|
|
241
|
-
let left = parseAnd();
|
|
242
|
-
while (current().type === "or") {
|
|
243
|
-
advance();
|
|
244
|
-
left = booleanValue(left) || booleanValue(parseAnd());
|
|
245
|
-
}
|
|
246
|
-
return left;
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
parse() {
|
|
250
|
-
const value = parseOr();
|
|
251
|
-
if (current().type !== "eof") {
|
|
252
|
-
throw new GitHostError("forge_invalid_workflow_definition", `Unexpected trailing token "${current().type}" in workflow expression.`, {});
|
|
253
|
-
}
|
|
254
|
-
return value;
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
}
|
|
2
|
+
import { booleanValue, createExpressionReader } from "./expressions/read.js";
|
|
3
|
+
import { tokenizeExpression } from "./expressions/tokenize.js";
|
|
258
4
|
function resolveWorkflowExpression(input, context) {
|
|
259
5
|
const tokens = tokenizeExpression(input);
|
|
260
6
|
return createExpressionReader(tokens, context).parse();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../../../src/core/actions/expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../../../src/core/actions/expressions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,SAAS,yBAAyB,CAAC,KAAa,EAAE,OAAkC;IAClF,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACzC,OAAO,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,CAAC;AACzD,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAa,EAAE,OAAkC;IAC9E,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAAC,EAAE,UAAkB,EAAE,EAAE;QAClF,MAAM,KAAK,GAAG,yBAAyB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,EAAE,CAAC;QAC7B,IAAI,OAAO,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAChE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAc,EAAE,OAAkC,EAAE,QAAQ,GAAG,IAAI;IACjG,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,IAAI,CAAC,GAAG;QAAE,OAAO,QAAQ,CAAC;IAC1B,OAAO,YAAY,CAAC,yBAAyB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,GACtB,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { type ChildProcess } from "node:child_process";
|
|
2
|
+
import type { GitForgeLocalRunnerOptions } from "../../types.js";
|
|
2
3
|
type RunShellCommandInput = {
|
|
4
|
+
beforeSpawn?: GitForgeLocalRunnerOptions["beforeSpawn"];
|
|
3
5
|
command: string;
|
|
4
6
|
cwd: string;
|
|
5
7
|
env: NodeJS.ProcessEnv;
|
|
8
|
+
execTimeoutMs?: number;
|
|
9
|
+
gid?: number;
|
|
6
10
|
heartbeatIntervalMs: number;
|
|
7
11
|
onHeartbeat: () => void | Promise<void>;
|
|
8
12
|
onOutput: (stream: "stderr" | "stdout", chunk: string) => void | Promise<void>;
|
|
9
13
|
onSpawn?: (child: ChildProcess | null) => void;
|
|
10
14
|
shell: string;
|
|
15
|
+
uid?: number;
|
|
11
16
|
};
|
|
12
17
|
type RunShellCommandResult = {
|
|
13
18
|
exitCode: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local_runner.d.ts","sourceRoot":"","sources":["../../../src/core/actions/local_runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"local_runner.d.ts","sourceRoot":"","sources":["../../../src/core/actions/local_runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAIjF,OAAO,KAAK,EAAgC,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAE9F,KAAK,oBAAoB,GAAG;IAC1B,WAAW,CAAC,EAAE,0BAA0B,CAAC,aAAa,CAAC,CAAC;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,mBAAmB,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAgEF,iBAAe,uBAAuB,CAAC,KAAK,EAAE;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB,iBA0BA;AASD,iBAAe,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA4B1F;AA4CD,iBAAe,YAAY,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM;;;;GAG/D;AAED,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,YAAY,GACb,CAAC"}
|
|
@@ -4,10 +4,62 @@ import { spawn } from "node:child_process";
|
|
|
4
4
|
import { GitHostError } from "../../errors.js";
|
|
5
5
|
import { runGit } from "../run_git.js";
|
|
6
6
|
const OUTPUT_PREVIEW_LIMIT = 4000;
|
|
7
|
+
// Grace period between the SIGTERM and the follow-up SIGKILL for timed-out steps.
|
|
8
|
+
const TIMEOUT_SIGKILL_GRACE_MS = 5000;
|
|
7
9
|
function appendPreview(current, chunk) {
|
|
8
10
|
const next = `${current}${chunk}`;
|
|
9
11
|
return next.length <= OUTPUT_PREVIEW_LIMIT ? next : next.slice(-OUTPUT_PREVIEW_LIMIT);
|
|
10
12
|
}
|
|
13
|
+
// Builds the concrete process to spawn for a step and lets callers wrap it (for
|
|
14
|
+
// example with a sandbox such as bwrap/nsjail) via the `beforeSpawn` hook.
|
|
15
|
+
async function resolveChildSpec(input) {
|
|
16
|
+
const base = {
|
|
17
|
+
args: ["-lc", input.command],
|
|
18
|
+
command: input.shell,
|
|
19
|
+
cwd: input.cwd,
|
|
20
|
+
env: input.env,
|
|
21
|
+
...(input.gid === undefined ? {} : { gid: input.gid }),
|
|
22
|
+
...(input.uid === undefined ? {} : { uid: input.uid }),
|
|
23
|
+
};
|
|
24
|
+
const next = input.beforeSpawn ? await input.beforeSpawn(base) : undefined;
|
|
25
|
+
return next || base;
|
|
26
|
+
}
|
|
27
|
+
function spawnChildSpec(spec) {
|
|
28
|
+
const options = {
|
|
29
|
+
cwd: spec.cwd,
|
|
30
|
+
env: spec.env,
|
|
31
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
32
|
+
...(spec.gid === undefined ? {} : { gid: spec.gid }),
|
|
33
|
+
...(spec.uid === undefined ? {} : { uid: spec.uid }),
|
|
34
|
+
};
|
|
35
|
+
return spawn(spec.command, spec.args, options);
|
|
36
|
+
}
|
|
37
|
+
// Escalates a per-step wall-clock timeout from SIGTERM to SIGKILL. Returns a
|
|
38
|
+
// disposer that cancels the pending signals once the child settles.
|
|
39
|
+
function attachExecTimeout(child, execTimeoutMs) {
|
|
40
|
+
if (!execTimeoutMs || execTimeoutMs <= 0)
|
|
41
|
+
return () => { };
|
|
42
|
+
const term = setTimeout(() => child.kill("SIGTERM"), execTimeoutMs);
|
|
43
|
+
const kill = setTimeout(() => child.kill("SIGKILL"), execTimeoutMs + TIMEOUT_SIGKILL_GRACE_MS);
|
|
44
|
+
term.unref?.();
|
|
45
|
+
kill.unref?.();
|
|
46
|
+
return () => {
|
|
47
|
+
clearTimeout(term);
|
|
48
|
+
clearTimeout(kill);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function wireChildOutput(child, input, preview) {
|
|
52
|
+
child.stdout?.setEncoding("utf8");
|
|
53
|
+
child.stdout?.on("data", (chunk) => {
|
|
54
|
+
preview.value = appendPreview(preview.value, chunk);
|
|
55
|
+
void input.onOutput("stdout", chunk);
|
|
56
|
+
});
|
|
57
|
+
child.stderr?.setEncoding("utf8");
|
|
58
|
+
child.stderr?.on("data", (chunk) => {
|
|
59
|
+
preview.value = appendPreview(preview.value, chunk);
|
|
60
|
+
void input.onOutput("stderr", chunk);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
11
63
|
async function materializeJobWorkspace(input) {
|
|
12
64
|
fs.rmSync(input.workspacePath, { force: true, recursive: true });
|
|
13
65
|
fs.mkdirSync(path.dirname(input.workspacePath), { recursive: true });
|
|
@@ -35,42 +87,42 @@ async function materializeJobWorkspace(input) {
|
|
|
35
87
|
});
|
|
36
88
|
}
|
|
37
89
|
}
|
|
90
|
+
function resolveExitCode(code, signal) {
|
|
91
|
+
if (typeof code === "number")
|
|
92
|
+
return code;
|
|
93
|
+
if (signal === "SIGKILL")
|
|
94
|
+
return 137;
|
|
95
|
+
if (signal === "SIGTERM" || signal === "SIGINT")
|
|
96
|
+
return 130;
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
38
99
|
async function runShellCommand(input) {
|
|
39
|
-
|
|
100
|
+
const preview = { value: "" };
|
|
101
|
+
const spec = await resolveChildSpec(input);
|
|
40
102
|
const exitCode = await new Promise((resolve, reject) => {
|
|
41
|
-
const child =
|
|
42
|
-
cwd: input.cwd,
|
|
43
|
-
env: input.env,
|
|
44
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
45
|
-
});
|
|
103
|
+
const child = spawnChildSpec(spec);
|
|
46
104
|
input.onSpawn?.(child);
|
|
47
105
|
const heartbeat = setInterval(() => {
|
|
48
106
|
void input.onHeartbeat();
|
|
49
107
|
}, Math.max(250, input.heartbeatIntervalMs));
|
|
50
|
-
child.
|
|
51
|
-
child
|
|
52
|
-
outputPreview = appendPreview(outputPreview, chunk);
|
|
53
|
-
void input.onOutput("stdout", chunk);
|
|
54
|
-
});
|
|
55
|
-
child.stderr?.setEncoding("utf8");
|
|
56
|
-
child.stderr?.on("data", (chunk) => {
|
|
57
|
-
outputPreview = appendPreview(outputPreview, chunk);
|
|
58
|
-
void input.onOutput("stderr", chunk);
|
|
59
|
-
});
|
|
108
|
+
const disposeTimeout = attachExecTimeout(child, input.execTimeoutMs);
|
|
109
|
+
wireChildOutput(child, input, preview);
|
|
60
110
|
child.on("error", (error) => {
|
|
61
111
|
clearInterval(heartbeat);
|
|
112
|
+
disposeTimeout();
|
|
62
113
|
input.onSpawn?.(null);
|
|
63
114
|
reject(error);
|
|
64
115
|
});
|
|
65
116
|
child.on("close", (code, signal) => {
|
|
66
117
|
clearInterval(heartbeat);
|
|
118
|
+
disposeTimeout();
|
|
67
119
|
input.onSpawn?.(null);
|
|
68
|
-
resolve(
|
|
120
|
+
resolve(resolveExitCode(code, signal));
|
|
69
121
|
});
|
|
70
122
|
});
|
|
71
123
|
return {
|
|
72
124
|
exitCode,
|
|
73
|
-
outputPreview,
|
|
125
|
+
outputPreview: preview.value,
|
|
74
126
|
};
|
|
75
127
|
}
|
|
76
128
|
async function assertBinaryAvailable(command, cwd) {
|