Add view output support
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
22
package-lock.json
generated
22
package-lock.json
generated
@@ -10,6 +10,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"child_process": "^1.0.2",
|
||||
"sanitize-filename": "^1.6.3",
|
||||
"yaml": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -2185,6 +2186,14 @@
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/sanitize-filename": {
|
||||
"version": "1.6.3",
|
||||
"resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz",
|
||||
"integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==",
|
||||
"dependencies": {
|
||||
"truncate-utf8-bytes": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/schema-utils": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz",
|
||||
@@ -2382,6 +2391,14 @@
|
||||
"node": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/truncate-utf8-bytes": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
|
||||
"integrity": "sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ==",
|
||||
"dependencies": {
|
||||
"utf8-byte-length": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ts-api-utils": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz",
|
||||
@@ -2484,6 +2501,11 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/utf8-byte-length": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.5.tgz",
|
||||
"integrity": "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA=="
|
||||
},
|
||||
"node_modules/watchpack": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.2.tgz",
|
||||
|
||||
@@ -206,7 +206,6 @@
|
||||
"category": "GitHub Local Actions",
|
||||
"command": "githubLocalActions.viewOutput",
|
||||
"title": "View Output",
|
||||
"enablement": "viewItem =~ /^githubLocalActions.history_(Success|Failed|Cancelled).*/",
|
||||
"icon": "$(book)"
|
||||
},
|
||||
{
|
||||
@@ -538,6 +537,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"child_process": "^1.0.2",
|
||||
"sanitize-filename": "^1.6.3",
|
||||
"yaml": "^2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
49
src/act.ts
49
src/act.ts
@@ -1,4 +1,5 @@
|
||||
import * as path from "path";
|
||||
import sanitize from "sanitize-filename";
|
||||
import { commands, ExtensionContext, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, Uri, window, workspace, WorkspaceFolder } from "vscode";
|
||||
import { ComponentsManager } from "./componentsManager";
|
||||
import { componentsTreeDataProvider, historyTreeDataProvider } from './extension';
|
||||
@@ -62,6 +63,7 @@ export interface CommandArgs {
|
||||
|
||||
export class Act {
|
||||
private static base: string = 'act';
|
||||
context: ExtensionContext;
|
||||
storageManager: StorageManager;
|
||||
secretManager: SecretManager;
|
||||
componentsManager: ComponentsManager;
|
||||
@@ -72,6 +74,7 @@ export class Act {
|
||||
prebuiltExecutables: { [architecture: string]: string };
|
||||
|
||||
constructor(context: ExtensionContext) {
|
||||
this.context = context;
|
||||
this.storageManager = new StorageManager(context);
|
||||
this.secretManager = new SecretManager(context);
|
||||
this.componentsManager = new ComponentsManager();
|
||||
@@ -171,10 +174,11 @@ export class Act {
|
||||
name: `${commandArgs.name}`,
|
||||
status: HistoryStatus.Running,
|
||||
date: {
|
||||
start: new Date().toString()
|
||||
start: taskDefinition.start.toString()
|
||||
},
|
||||
taskExecution: e.execution,
|
||||
commandArgs: commandArgs
|
||||
commandArgs: commandArgs,
|
||||
logPath: taskDefinition.logPath
|
||||
});
|
||||
historyTreeDataProvider.refresh();
|
||||
this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory);
|
||||
@@ -274,14 +278,6 @@ export class Act {
|
||||
this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory);
|
||||
}
|
||||
|
||||
// Build command with settings
|
||||
const settings = await this.settingsManager.getSettings(workspaceFolder, true);
|
||||
const command = `${Act.base} ${commandArgs.options}` +
|
||||
(settings.secrets.length > 0 ? ` ${Option.Secret} ${settings.secrets.map(secret => (secret.value ? `${secret.key}=${secret.value}` : secret.key)).join(` ${Option.Secret} `)}` : ``) +
|
||||
(settings.variables.length > 0 ? ` ${Option.Variable} ${settings.variables.map(variable => (variable.value ? `${variable.key}=${variable.value}` : variable.key)).join(` ${Option.Variable} `)}` : ``) +
|
||||
(settings.inputs.length > 0 ? ` ${Option.Input} ${settings.inputs.map(input => `${input.key}=${input.value}`).join(` ${Option.Input} `)}` : ``) +
|
||||
(settings.runners.length > 0 ? ` ${Option.Platform} ${settings.runners.map(runner => `${runner.key}=${runner.value}`).join(` ${Option.Platform} `)}` : ``);
|
||||
|
||||
// Process task count suffix
|
||||
const historyIndex = this.historyManager.workspaceHistory[commandArgs.fsPath].length;
|
||||
const matchingTasks = this.historyManager.workspaceHistory[commandArgs.fsPath]
|
||||
@@ -289,11 +285,42 @@ export class Act {
|
||||
.sort((a, b) => b.count - a.count);
|
||||
const count = matchingTasks && matchingTasks.length > 0 ? matchingTasks[0].count + 1 : 1;
|
||||
|
||||
// Process log file and path
|
||||
const start = new Date();
|
||||
const year = start.getFullYear();
|
||||
const month = (start.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = start.getDate().toString().padStart(2, '0');
|
||||
const hours = start.getHours().toString().padStart(2, '0');
|
||||
const minutes = start.getMinutes().toString().padStart(2, '0');
|
||||
const seconds = start.getSeconds().toString().padStart(2, '0');
|
||||
const logFileName = sanitize(`${commandArgs.name} #${count} - ${year}${month}${day}_${hours}${minutes}${seconds}.log`, { replacement: '_' });
|
||||
const logPath = path.join(this.context.globalStorageUri.fsPath, logFileName);
|
||||
|
||||
try {
|
||||
await workspace.fs.createDirectory(this.context.globalStorageUri);
|
||||
} catch (error) { }
|
||||
|
||||
// Build command with settings
|
||||
const settings = await this.settingsManager.getSettings(workspaceFolder, true);
|
||||
const command = `${Act.base} ${commandArgs.options}` +
|
||||
(settings.secrets.length > 0 ? ` ${Option.Secret} ${settings.secrets.map(secret => (secret.value ? `${secret.key}=${secret.value}` : secret.key)).join(` ${Option.Secret} `)}` : ``) +
|
||||
(settings.variables.length > 0 ? ` ${Option.Variable} ${settings.variables.map(variable => (variable.value ? `${variable.key}=${variable.value}` : variable.key)).join(` ${Option.Variable} `)}` : ``) +
|
||||
(settings.inputs.length > 0 ? ` ${Option.Input} ${settings.inputs.map(input => `${input.key}=${input.value}`).join(` ${Option.Input} `)}` : ``) +
|
||||
(settings.runners.length > 0 ? ` ${Option.Platform} ${settings.runners.map(runner => `${runner.key}=${runner.value}`).join(` ${Option.Platform} `)}` : ``) +
|
||||
`| tee "${logPath}"`;
|
||||
|
||||
// Execute task
|
||||
await tasks.executeTask({
|
||||
name: `${commandArgs.name} #${count}`,
|
||||
detail: `${commandArgs.name} #${count}`,
|
||||
definition: { type: 'GitHub Local Actions', commandArgs: commandArgs, historyIndex: historyIndex, count: count },
|
||||
definition: {
|
||||
type: 'GitHub Local Actions',
|
||||
commandArgs: commandArgs,
|
||||
historyIndex: historyIndex,
|
||||
count: count,
|
||||
start: start,
|
||||
logPath: logPath
|
||||
},
|
||||
source: 'GitHub Local Actions',
|
||||
scope: workspaceFolder || TaskScope.Workspace,
|
||||
isBackground: true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TaskExecution, window, workspace, WorkspaceFolder } from "vscode";
|
||||
import { TaskExecution, Uri, window, workspace, WorkspaceFolder } from "vscode";
|
||||
import { CommandArgs } from "./act";
|
||||
import { act, historyTreeDataProvider } from "./extension";
|
||||
import { StorageKey, StorageManager } from "./storageManager";
|
||||
@@ -11,10 +11,10 @@ export interface History {
|
||||
date: {
|
||||
start: string,
|
||||
end?: string,
|
||||
}
|
||||
output?: string,
|
||||
},
|
||||
taskExecution?: TaskExecution,
|
||||
commandArgs: CommandArgs
|
||||
commandArgs: CommandArgs,
|
||||
logPath: string
|
||||
}
|
||||
|
||||
export enum HistoryStatus {
|
||||
@@ -44,15 +44,25 @@ export class HistoryManager {
|
||||
}
|
||||
|
||||
async clearAll(workspaceFolder: WorkspaceFolder) {
|
||||
const existingHistory = this.workspaceHistory[workspaceFolder.uri.fsPath];
|
||||
for (const history of existingHistory) {
|
||||
try {
|
||||
await workspace.fs.delete(Uri.file(history.logPath));
|
||||
} catch (error) { }
|
||||
}
|
||||
|
||||
this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
|
||||
historyTreeDataProvider.refresh();
|
||||
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
|
||||
}
|
||||
|
||||
async viewOutput(history: History) {
|
||||
await workspace.openTextDocument({ content: history.output }).then(async document => {
|
||||
try {
|
||||
const document = await workspace.openTextDocument(history.logPath)
|
||||
await window.showTextDocument(document);
|
||||
});
|
||||
} catch (error) {
|
||||
window.showErrorMessage(`${history.name} #${history.count} log file not found`);
|
||||
}
|
||||
}
|
||||
|
||||
async restart(history: History) {
|
||||
@@ -67,5 +77,9 @@ export class HistoryManager {
|
||||
const historyIndex = this.workspaceHistory[history.commandArgs.fsPath].findIndex(workspaceHistory => workspaceHistory.index === history.index);
|
||||
this.workspaceHistory[history.commandArgs.fsPath].splice(historyIndex, 1);
|
||||
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
|
||||
|
||||
try {
|
||||
await workspace.fs.delete(Uri.file(history.logPath));
|
||||
} catch (error) { }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as path from "path";
|
||||
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
|
||||
import { History, HistoryStatus } from "../../historyManager";
|
||||
import { Utils } from "../../utils";
|
||||
@@ -38,8 +39,9 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
|
||||
break;
|
||||
}
|
||||
this.tooltip = `Name: ${history.name} #${history.count}\n` +
|
||||
`Path: ${history.commandArgs.fsPath}\n` +
|
||||
`${history.commandArgs.extraHeader.map(header => `${header.key}: ${header.value}`).join('\n')}\n` +
|
||||
`Path: ${history.commandArgs.fsPath}\n` +
|
||||
`Log File: ${path.parse(history.logPath).base}\n` +
|
||||
`Status: ${history.status}\n` +
|
||||
`Started: ${Utils.getDateString(history.date.start)}\n` +
|
||||
`Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` +
|
||||
|
||||
Reference in New Issue
Block a user