forked from actions/runner
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
index.ts
271 lines (241 loc) · 8.93 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import { commands, window, ExtensionContext, Uri, ViewColumn, env, workspace, languages, TreeItem, TextEditor, WebviewPanel } from 'vscode';
import { LanguageClient, TransportKind } from 'vscode-languageclient/node';
import { join } from 'path';
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { RSTreeDataProvider } from './treeItemProvider';
import {LogScheme} from "./logs/constants";
import {WorkflowStepLogProvider} from "./logs/fileProvider";
import {WorkflowStepLogFoldingProvider} from "./logs/foldingProvider";
import {WorkflowStepLogSymbolProvider} from "./logs/symbolProvider";
import { getLogInfo } from './logs/logInfo';
import { updateDecorations } from './logs/formatProvider';
import { buildLogURI } from './logs/scheme';
var startRunner : ChildProcessWithoutNullStreams | null = null;
var finishPromise : Promise<void> | null = null;
function activate(context : ExtensionContext) {
// Log providers
context.subscriptions.push(
languages.registerFoldingRangeProvider({scheme: LogScheme}, new WorkflowStepLogFoldingProvider())
);
context.subscriptions.push(
languages.registerDocumentSymbolProvider(
{
scheme: LogScheme
},
new WorkflowStepLogSymbolProvider()
)
);
context.subscriptions.push(
window.onDidChangeActiveTextEditor((editor : TextEditor) => {
if (editor.document.uri?.scheme === LogScheme) {
const logInfo = getLogInfo(editor.document.uri);
if (logInfo) {
updateDecorations(editor, logInfo);
}
}
}));
context.subscriptions.push(
commands.registerCommand("runner.server.workflow.logs", async (obj : TreeItem) => {
var jobId = obj.command.arguments[1]; //await window.showInputBox({ prompt: "JobId", ignoreFocusOut: true, title: "Provide jobid" })
const uri = buildLogURI(
`${obj.label}`,
"Unknown",
"Unknown",
jobId
);
const doc = await workspace.openTextDocument(uri);
const editor = await window.showTextDocument(doc, {
preview: false
});
const logInfo = getLogInfo(uri);
if (!logInfo) {
throw new Error("Could not get log info");
}
// Custom formatting after the editor has been opened
updateDecorations(editor, logInfo);
})
);
(async() => {
console.log("Aquire Dotnet!")
// App requires .NET 8.0
const commandRes = await commands.executeCommand('dotnet.acquire', { version: '8.0', requestingExtensionId: `${context.extension.packageJSON.publisher}.${context.extension.packageJSON.name}`, mode: "aspnetcore" }) as any;
const dotnetPath = commandRes.dotnetPath;
console.log("Dotnet " + dotnetPath)
if (!dotnetPath) {
throw new Error('Could not resolve the dotnet path!');
}
console.log("Starting Language Server")
var client = new LanguageClient(
'Runner.Server',
'Runner.Server Language Server',
{
run: {
transport: TransportKind.stdio,
command: dotnetPath,
args: [ join(context.extensionPath, 'native', 'Runner.Language.Server.dll') ]
},
debug: {
transport: TransportKind.stdio,
command: dotnetPath,
args: [ join(context.extensionPath, 'native', 'Runner.Language.Server.dll') ]
}
},
{
documentSelector: [ { language: "yaml" }, { language: "azure-pipelines" } ],
}
);
var stopServer = new AbortController();
var serverproc = spawn(dotnetPath, [ join(context.extensionPath, 'native', 'Runner.Server.dll'), '--urls', 'http://*:0' ], { killSignal: 'SIGINT', signal: stopServer.signal, windowsHide: true, stdio: 'pipe', shell: false });
context.subscriptions.push({ dispose: () => stopServer.abort() })
serverproc.addListener('exit', code => {
console.log(code);
});
var address : string | null = null;
serverproc.stdout.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
var i = sdata.indexOf("http://");
if(i !== -1) {
var end = sdata.indexOf('\n', i + 1);
address = sdata.substring(i, end).replace("[::]", "localhost").replace("0.0.0.0", "localhost").trim();
window.registerTreeDataProvider("workflow-view", new RSTreeDataProvider(context, address));
context.subscriptions.push(
workspace.registerTextDocumentContentProvider(LogScheme, new WorkflowStepLogProvider(address))
);
if(address) {
var args = [ join(context.extensionPath, 'native', 'Runner.Client.dll'), 'startrunner', '--parallel', '4' ];
args.push('--server', address)
}
finishPromise = new Promise<void>(onexit => {
startRunner = spawn(dotnetPath, args, { windowsHide: true, stdio: 'pipe', shell: false, env: { ...process.env, RUNNER_CLIENT_EXIT_AFTER_ENTER: "1" } });
startRunner.stdout.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
});
startRunner.addListener('exit', code => {
console.log(code);
onexit();
});
})
var panel: WebviewPanel;
var getPanel = async () => {
if(panel) {
return panel;
}
panel = window.createWebviewPanel(
"runner.server",
"Runner Server",
ViewColumn.One,
{
enableScripts: true,
// Without this we loose your webview position when the webview is in background
retainContextWhenHidden: true
}
);
context.subscriptions.push(panel);
panel.onDidDispose(() => {
panel = null;
})
return panel;
}
var openPanel = async(name: string, url : string) => {
await getPanel();
panel.title = name;
const fullWebServerUri = address && await env.asExternalUri(
Uri.parse(address)
);
const cspSource = panel.webview.cspSource;
// Get the content Uri
const style = panel.webview.asWebviewUri(
Uri.joinPath(context.extensionUri, 'style.css')
);
panel.webview.html = `<!DOCTYPE html>
<html>
<head>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; frame-src ${fullWebServerUri} ${cspSource} https:; img-src ${cspSource} https:; script-src ${cspSource}; style-src ${cspSource};"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="${style}">
</head>
<body>
<iframe src="${fullWebServerUri}${url}"></iframe>
</body>
</html>`;
panel.reveal(ViewColumn.One, false);
};
commands.registerCommand("runner.server.openjob", (runId, id, name) => {
openPanel(name, `?view=allworkflows#/0/${runId}/0/${id}`);
});
commands.registerCommand("runner.server.openworkflowrun", runId => {
openPanel(`#${runId}`, `?view=allworkflows#/0/${runId}`);
});
}
});
serverproc.stderr.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
});
commands.registerCommand("runner.server.start-client", () => {
var args = [ join(context.extensionPath, 'native', 'Runner.Client.dll'), '--interactive' ];
if(address) {
args.push('--server', address)
}
context.subscriptions.push(window.createTerminal("runner.client", dotnetPath, args))
});
commands.registerCommand("runner.server.runworkflow", async (workflow, events) => {
console.log(`runner.server.runjob {workflow}`)
var sel : string = events.length === 1 ? events : await window.showQuickPick(events, { canPickMany: false })
var args = [ join(context.extensionPath, 'native', 'Runner.Client.dll'), '--event', sel || 'push', '-W', Uri.parse(workflow).fsPath ];
if(address) {
args.push('--server', address)
}
let startproc = spawn(dotnetPath, args, { windowsHide: true, stdio: 'pipe', shell: false, env: { ...process.env } });
startproc.stdout.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
});
startproc.stderr.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
});
startproc.addListener('exit', code => {
console.log(code);
});
});
commands.registerCommand("runner.server.runjob", async (workflow, job, events) => {
console.log(`runner.server.runjob {workflow}.{job}`)
var sel : string = events.length === 1 ? events : await window.showQuickPick(events, { canPickMany: false })
var args = [ join(context.extensionPath, 'native', 'Runner.Client.dll'), '--event', sel || 'push', '-W', Uri.parse(workflow).fsPath, '-j', job ];
if(address) {
args.push('--server', address)
}
let startproc = spawn(dotnetPath, args, { windowsHide: true, stdio: 'pipe', shell: false, env: { ...process.env } });
startproc.stdout.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
});
startproc.stderr.on('data', async (data) => {
var sdata = data.asciiSlice();
console.log(sdata)
});
startproc.addListener('exit', code => {
console.log(code);
});
});
context.subscriptions.push(client);
client.start();
})();
}
// this method is called when your extension is deactivated
async function deactivate() {
if(finishPromise !== null && startRunner !== null) {
startRunner.stdin.write("\n");
await finishPromise;
}
}
module.exports = {
activate,
deactivate
}