Add view output support

Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
Sanjula Ganepola
2024-11-19 12:51:36 -05:00
parent 860b5101ba
commit 095e8acb62
5 changed files with 86 additions and 21 deletions

24
package-lock.json generated
View File

@@ -10,6 +10,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"child_process": "^1.0.2", "child_process": "^1.0.2",
"sanitize-filename": "^1.6.3",
"yaml": "^2.6.0" "yaml": "^2.6.0"
}, },
"devDependencies": { "devDependencies": {
@@ -2185,6 +2186,14 @@
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true "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": { "node_modules/schema-utils": {
"version": "3.3.0", "version": "3.3.0",
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz",
@@ -2382,6 +2391,14 @@
"node": ">=8.0" "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": { "node_modules/ts-api-utils": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz",
@@ -2484,6 +2501,11 @@
"punycode": "^2.1.0" "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": { "node_modules/watchpack": {
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.2.tgz", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.2.tgz",
@@ -2696,4 +2718,4 @@
} }
} }
} }
} }

View File

@@ -206,7 +206,6 @@
"category": "GitHub Local Actions", "category": "GitHub Local Actions",
"command": "githubLocalActions.viewOutput", "command": "githubLocalActions.viewOutput",
"title": "View Output", "title": "View Output",
"enablement": "viewItem =~ /^githubLocalActions.history_(Success|Failed|Cancelled).*/",
"icon": "$(book)" "icon": "$(book)"
}, },
{ {
@@ -538,6 +537,7 @@
}, },
"dependencies": { "dependencies": {
"child_process": "^1.0.2", "child_process": "^1.0.2",
"sanitize-filename": "^1.6.3",
"yaml": "^2.6.0" "yaml": "^2.6.0"
}, },
"devDependencies": { "devDependencies": {
@@ -551,4 +551,4 @@
"webpack": "^5.96.1", "webpack": "^5.96.1",
"webpack-cli": "^5.1.4" "webpack-cli": "^5.1.4"
} }
} }

View File

@@ -1,4 +1,5 @@
import * as path from "path"; 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 { commands, ExtensionContext, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, Uri, window, workspace, WorkspaceFolder } from "vscode";
import { ComponentsManager } from "./componentsManager"; import { ComponentsManager } from "./componentsManager";
import { componentsTreeDataProvider, historyTreeDataProvider } from './extension'; import { componentsTreeDataProvider, historyTreeDataProvider } from './extension';
@@ -62,6 +63,7 @@ export interface CommandArgs {
export class Act { export class Act {
private static base: string = 'act'; private static base: string = 'act';
context: ExtensionContext;
storageManager: StorageManager; storageManager: StorageManager;
secretManager: SecretManager; secretManager: SecretManager;
componentsManager: ComponentsManager; componentsManager: ComponentsManager;
@@ -72,6 +74,7 @@ export class Act {
prebuiltExecutables: { [architecture: string]: string }; prebuiltExecutables: { [architecture: string]: string };
constructor(context: ExtensionContext) { constructor(context: ExtensionContext) {
this.context = context;
this.storageManager = new StorageManager(context); this.storageManager = new StorageManager(context);
this.secretManager = new SecretManager(context); this.secretManager = new SecretManager(context);
this.componentsManager = new ComponentsManager(); this.componentsManager = new ComponentsManager();
@@ -171,10 +174,11 @@ export class Act {
name: `${commandArgs.name}`, name: `${commandArgs.name}`,
status: HistoryStatus.Running, status: HistoryStatus.Running,
date: { date: {
start: new Date().toString() start: taskDefinition.start.toString()
}, },
taskExecution: e.execution, taskExecution: e.execution,
commandArgs: commandArgs commandArgs: commandArgs,
logPath: taskDefinition.logPath
}); });
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory);
@@ -274,14 +278,6 @@ export class Act {
this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); 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 // Process task count suffix
const historyIndex = this.historyManager.workspaceHistory[commandArgs.fsPath].length; const historyIndex = this.historyManager.workspaceHistory[commandArgs.fsPath].length;
const matchingTasks = this.historyManager.workspaceHistory[commandArgs.fsPath] const matchingTasks = this.historyManager.workspaceHistory[commandArgs.fsPath]
@@ -289,11 +285,42 @@ export class Act {
.sort((a, b) => b.count - a.count); .sort((a, b) => b.count - a.count);
const count = matchingTasks && matchingTasks.length > 0 ? matchingTasks[0].count + 1 : 1; 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 // Execute task
await tasks.executeTask({ await tasks.executeTask({
name: `${commandArgs.name} #${count}`, name: `${commandArgs.name} #${count}`,
detail: `${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', source: 'GitHub Local Actions',
scope: workspaceFolder || TaskScope.Workspace, scope: workspaceFolder || TaskScope.Workspace,
isBackground: true, isBackground: true,

View File

@@ -1,4 +1,4 @@
import { TaskExecution, window, workspace, WorkspaceFolder } from "vscode"; import { TaskExecution, Uri, window, workspace, WorkspaceFolder } from "vscode";
import { CommandArgs } from "./act"; import { CommandArgs } from "./act";
import { act, historyTreeDataProvider } from "./extension"; import { act, historyTreeDataProvider } from "./extension";
import { StorageKey, StorageManager } from "./storageManager"; import { StorageKey, StorageManager } from "./storageManager";
@@ -11,10 +11,10 @@ export interface History {
date: { date: {
start: string, start: string,
end?: string, end?: string,
} },
output?: string,
taskExecution?: TaskExecution, taskExecution?: TaskExecution,
commandArgs: CommandArgs commandArgs: CommandArgs,
logPath: string
} }
export enum HistoryStatus { export enum HistoryStatus {
@@ -44,15 +44,25 @@ export class HistoryManager {
} }
async clearAll(workspaceFolder: WorkspaceFolder) { 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] = []; this.workspaceHistory[workspaceFolder.uri.fsPath] = [];
historyTreeDataProvider.refresh(); historyTreeDataProvider.refresh();
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
} }
async viewOutput(history: History) { 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); await window.showTextDocument(document);
}); } catch (error) {
window.showErrorMessage(`${history.name} #${history.count} log file not found`);
}
} }
async restart(history: History) { async restart(history: History) {
@@ -67,5 +77,9 @@ export class HistoryManager {
const historyIndex = this.workspaceHistory[history.commandArgs.fsPath].findIndex(workspaceHistory => workspaceHistory.index === history.index); const historyIndex = this.workspaceHistory[history.commandArgs.fsPath].findIndex(workspaceHistory => workspaceHistory.index === history.index);
this.workspaceHistory[history.commandArgs.fsPath].splice(historyIndex, 1); this.workspaceHistory[history.commandArgs.fsPath].splice(historyIndex, 1);
this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory);
try {
await workspace.fs.delete(Uri.file(history.logPath));
} catch (error) { }
} }
} }

View File

@@ -1,3 +1,4 @@
import * as path from "path";
import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode";
import { History, HistoryStatus } from "../../historyManager"; import { History, HistoryStatus } from "../../historyManager";
import { Utils } from "../../utils"; import { Utils } from "../../utils";
@@ -38,8 +39,9 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi
break; break;
} }
this.tooltip = `Name: ${history.name} #${history.count}\n` + 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` + `${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` + `Status: ${history.status}\n` +
`Started: ${Utils.getDateString(history.date.start)}\n` + `Started: ${Utils.getDateString(history.date.start)}\n` +
`Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` + `Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` +