Add view output support
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
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