From b96f1c613a673b969f206b5ac72978c9b79b9e0a Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Sat, 30 Nov 2024 00:16:49 -0500 Subject: [PATCH 01/10] Add support for job and step level execution Signed-off-by: Sanjula Ganepola --- package.json | 14 +- src/act.ts | 127 ++++++++++++++++-- src/historyManager.ts | 60 ++++++++- src/views/history/history.ts | 34 ++--- src/views/history/job.ts | 38 ++++++ src/views/history/step.ts | 37 +++++ .../settings/settingsTreeDataProvider.ts | 4 +- 7 files changed, 273 insertions(+), 41 deletions(-) create mode 100644 src/views/history/job.ts create mode 100644 src/views/history/step.ts diff --git a/package.json b/package.json index 5faaf8b..eb776fd 100644 --- a/package.json +++ b/package.json @@ -745,7 +745,7 @@ "colors": [ { "id": "GitHubLocalActions.green", - "description": "Color for green in GitHub Local Actions extension", + "description": "Color for green in the GitHub Local Actions extension", "defaults": { "dark": "#89d185", "light": "#89d185" @@ -753,15 +753,23 @@ }, { "id": "GitHubLocalActions.yellow", - "description": "Color for yellow in GitHub Local Actions extension", + "description": "Color for yellow in the GitHub Local Actions extension", "defaults": { "dark": "#cca700", "light": "#cca700" } }, + { + "id": "GitHubLocalActions.purple", + "description": "Color for purple in the GitHub Local Actions extension", + "defaults": { + "dark": "#d6bcfa", + "light": "#d6bcfa" + } + }, { "id": "GitHubLocalActions.red", - "description": "Color for red in GitHub Local Actions extension", + "description": "Color for red in the GitHub Local Actions extension", "defaults": { "dark": "#f48771", "light": "#f48771" diff --git a/src/act.ts b/src/act.ts index ff4bef6..a5c7658 100644 --- a/src/act.ts +++ b/src/act.ts @@ -214,7 +214,7 @@ export class Act { if (taskDefinition.type === 'GitHub Local Actions') { this.runningTaskCount--; - if (this.refreshInterval && this.runningTaskCount == 0) { + if (this.refreshInterval && this.runningTaskCount === 0) { clearInterval(this.refreshInterval); this.refreshInterval = undefined; } @@ -344,7 +344,7 @@ export class Act { const actCommand = Act.getActCommand(); const settings = await this.settingsManager.getSettings(workspaceFolder, true); const command = - `${actCommand} ${commandArgs.options}` + + `${actCommand} ${Option.Json} ${commandArgs.options}` + (settings.secrets.length > 0 ? ` ${Option.Secret} ${settings.secrets.map(secret => secret.key).join(` ${Option.Secret} `)}` : ``) + (settings.secretFiles.length > 0 ? ` ${Option.SecretFile} "${settings.secretFiles[0].path}"` : ` ${Option.SecretFile} ""`) + (settings.variables.length > 0 ? ` ${Option.Var} ${settings.variables.map(variable => `${variable.key}=${variable.value}`).join(` ${Option.Var} `)}` : ``) + @@ -394,7 +394,8 @@ export class Act { }, taskExecution: taskExecution, commandArgs: commandArgs, - logPath: logPath + logPath: logPath, + jobs: [] }); historyTreeDataProvider.refresh(); this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); @@ -417,11 +418,100 @@ export class Act { }); const handleIO = (data: any) => { - const lines: string[] = data.toString().split('\n').filter((line: string) => line != ''); + const lines: string[] = data.toString().split('\n').filter((line: string) => line !== ''); for (const line of lines) { - writeEmitter.fire(`${line.trimEnd()}\r\n`); + const dateString = new Date().toString(); + + let message: string; + try { + const parsedMessage = JSON.parse(line); + if (parsedMessage.msg) { + message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`; + } else { + message = line; + } + + // Update job and step status in workspace history + if (parsedMessage.jobID) { + let jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs! + .findIndex(job => job.name === parsedMessage.jobID); + if (jobIndex < 0) { + // Add new job with setup step + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.push({ + name: parsedMessage.jobID, + status: HistoryStatus.Running, + date: { + start: dateString + }, + steps: [ + { + id: -1, // Special id for setup job + name: 'Setup Job', + status: HistoryStatus.Running, + date: { + start: dateString + } + } + ] + }); + jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.length - 1; + } + + const isCompleteJobStep = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length > 1; + if (parsedMessage.stepID || isCompleteJobStep) { + let stepName: string; + let stepId: number; + if (!parsedMessage.stepID && isCompleteJobStep) { + stepName = 'Complete Job'; + stepId = -2; // Special Id for complete job + } else { + stepName = parsedMessage.stage !== 'Main' ? `${parsedMessage.stage} ${parsedMessage.step}` : parsedMessage.step; + stepId = parseInt(parsedMessage.stepID[0]); + } + + if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { + // TODO: How to know if setup job step failed? + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status = HistoryStatus.Success; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].date.end = dateString; + } + + let stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps! + .findIndex(step => step.id === stepId && step.name === stepName); + if (stepIndex < 0) { + // Add new step + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.push({ + id: stepId, + name: stepName, + status: HistoryStatus.Running, + date: { + start: dateString + } + }); + stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length - 1; + } + + if (parsedMessage.stepResult) { + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].status = + parsedMessage.stepResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].date.end = dateString; + } + } + + if (parsedMessage.jobResult) { + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].status = + parsedMessage.jobResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = + dateString; + } + } + } catch (error) { + message = line; + } + writeEmitter.fire(`${message.trimEnd()}\r\n`); + historyTreeDataProvider.refresh(); + this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } - } + }; let shell = env.shell; switch (process.platform) { @@ -455,8 +545,28 @@ export class Act { exec.stdout.on('data', handleIO); exec.stderr.on('data', handleIO); exec.on('exit', (code, signal) => { + const dateString = new Date().toString(); + // Set execution status and end time in workspace history if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status === HistoryStatus.Running) { + const jobAndStepStatus = (!code && code !== 0) ? HistoryStatus.Cancelled : HistoryStatus.Unknown; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs?.forEach((job, jobIndex) => { + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps?.forEach((step, stepIndex) => { + if (step.status === HistoryStatus.Running) { + // Update status of all running steps + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].status = jobAndStepStatus; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].date.end = dateString; + } + }); + + if (job.status === HistoryStatus.Running) { + // Update status of all running jobs + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].status = jobAndStepStatus; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = dateString; + } + }); + + // Update history status if (code === 0) { this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status = HistoryStatus.Success; } else if (!code) { @@ -465,7 +575,7 @@ export class Act { this.historyManager.workspaceHistory[commandArgs.path][historyIndex].status = HistoryStatus.Failed; } } - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].date.end = new Date().toString(); + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].date.end = dateString; historyTreeDataProvider.refresh(); this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); @@ -494,7 +604,7 @@ export class Act { exec.stdin.destroy(); exec.stderr.destroy(); } else { - exec.stdin.write(data === '\r' ? '\r\n' : data) + exec.stdin.write(data === '\r' ? '\r\n' : data); } }, close: () => { @@ -506,7 +616,6 @@ export class Act { }; }) }); - this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } async install(packageManager: string) { diff --git a/src/historyManager.ts b/src/historyManager.ts index 1f8e629..8654df2 100644 --- a/src/historyManager.ts +++ b/src/historyManager.ts @@ -1,4 +1,4 @@ -import { TaskExecution, Uri, window, workspace, WorkspaceFolder } from "vscode"; +import { TaskExecution, ThemeColor, ThemeIcon, Uri, window, workspace, WorkspaceFolder } from "vscode"; import { CommandArgs } from "./act"; import { act, historyTreeDataProvider } from "./extension"; import { StorageKey, StorageManager } from "./storageManager"; @@ -12,16 +12,38 @@ export interface History { start: string, end?: string, }, - taskExecution?: TaskExecution, commandArgs: CommandArgs, - logPath: string + logPath: string, + taskExecution?: TaskExecution, + jobs?: Job[], +} + +export interface Job { + name: string, + status: HistoryStatus, + date: { + start: string, + end?: string, + }, + steps?: Step[] +} + +export interface Step { + id: number, + name: string, + status: HistoryStatus, + date: { + start: string, + end?: string, + } } export enum HistoryStatus { Running = 'Running', Success = 'Success', Failed = 'Failed', - Cancelled = 'Cancelled' + Cancelled = 'Cancelled', + Unknown = 'Unknown' } export class HistoryManager { @@ -33,6 +55,21 @@ export class HistoryManager { const workspaceHistory = this.storageManager.get<{ [path: string]: History[] }>(StorageKey.WorkspaceHistory) || {}; for (const [path, historyLogs] of Object.entries(workspaceHistory)) { workspaceHistory[path] = historyLogs.map(history => { + history.jobs?.forEach((job, jobIndex) => { + history.jobs![jobIndex].steps?.forEach((step, stepIndex) => { + // Update status of all running steps + if (step.status === HistoryStatus.Running) { + history.jobs![jobIndex].steps![stepIndex].status = HistoryStatus.Cancelled; + } + }); + + // Update status of all running jobs + if (job.status === HistoryStatus.Running) { + history.jobs![jobIndex].status = HistoryStatus.Cancelled; + } + }); + + // Update history status if (history.status === HistoryStatus.Running) { history.status = HistoryStatus.Cancelled; } @@ -84,4 +121,19 @@ export class HistoryManager { } catch (error: any) { } } } + + static statusToIcon(status: HistoryStatus) { + switch (status) { + case HistoryStatus.Running: + return new ThemeIcon('loading~spin'); + case HistoryStatus.Success: + return new ThemeIcon('pass', new ThemeColor('GitHubLocalActions.green')); + case HistoryStatus.Failed: + return new ThemeIcon('error', new ThemeColor('GitHubLocalActions.red')); + case HistoryStatus.Cancelled: + return new ThemeIcon('circle-slash', new ThemeColor('GitHubLocalActions.yellow')); + case HistoryStatus.Unknown: + return new ThemeIcon('question', new ThemeColor('GitHubLocalActions.purple')); + } + } } \ No newline at end of file diff --git a/src/views/history/history.ts b/src/views/history/history.ts index b4ea819..aaa724d 100644 --- a/src/views/history/history.ts +++ b/src/views/history/history.ts @@ -1,15 +1,16 @@ import * as path from "path"; -import { ThemeColor, ThemeIcon, TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; -import { History, HistoryStatus } from "../../historyManager"; +import { TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; +import { History, HistoryManager, HistoryStatus } from "../../historyManager"; import { Utils } from "../../utils"; import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; +import JobTreeItem from "./job"; export default class HistoryTreeItem extends TreeItem implements GithubLocalActionsTreeItem { static contextValue = 'githubLocalActions.history'; history: History; constructor(public workspaceFolder: WorkspaceFolder, history: History) { - super(`${history.name} #${history.count}`, TreeItemCollapsibleState.None); + super(`${history.name} #${history.count}`, TreeItemCollapsibleState.Collapsed); this.history = history; let endTime: string | undefined; @@ -24,20 +25,7 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi this.description = totalDuration; this.contextValue = `${HistoryTreeItem.contextValue}_${history.status}`; - switch (history.status) { - case HistoryStatus.Running: - this.iconPath = new ThemeIcon('loading~spin'); - break; - case HistoryStatus.Success: - this.iconPath = new ThemeIcon('pass', new ThemeColor('GitHubLocalActions.green')); - break; - case HistoryStatus.Failed: - this.iconPath = new ThemeIcon('error', new ThemeColor('GitHubLocalActions.red')); - break; - case HistoryStatus.Cancelled: - this.iconPath = new ThemeIcon('circle-slash', new ThemeColor('GitHubLocalActions.yellow')); - break; - } + this.iconPath = HistoryManager.statusToIcon(history.status); this.tooltip = `Name: ${history.name} #${history.count}\n` + `${history.commandArgs.extraHeader.map(header => `${header.key}: ${header.value}`).join('\n')}\n` + `Path: ${history.commandArgs.path}\n` + @@ -46,14 +34,14 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi `Started: ${Utils.getDateString(history.date.start)}\n` + `Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` + `Total Duration: ${totalDuration ? totalDuration : 'N/A'}`; - this.command = { - title: 'Focus Task', - command: 'githubLocalActions.focusTask', - arguments: [this] - }; + // this.command = { + // title: 'Focus Task', + // command: 'githubLocalActions.focusTask', + // arguments: [this] + // }; } async getChildren(): Promise { - return []; + return this.history.jobs?.map(job => new JobTreeItem(this.workspaceFolder, job)) || []; } } \ No newline at end of file diff --git a/src/views/history/job.ts b/src/views/history/job.ts new file mode 100644 index 0000000..4698e27 --- /dev/null +++ b/src/views/history/job.ts @@ -0,0 +1,38 @@ +import { TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; +import { HistoryManager, HistoryStatus, Job } from "../../historyManager"; +import { Utils } from "../../utils"; +import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; +import StepTreeItem from "./step"; + +export default class JobTreeItem extends TreeItem implements GithubLocalActionsTreeItem { + static contextValue = 'githubLocalActions.job'; + job: Job; + + constructor(public workspaceFolder: WorkspaceFolder, job: Job) { + super(job.name, TreeItemCollapsibleState.Expanded); + this.job = job; + + let endTime: string | undefined; + let totalDuration: string | undefined; + if (job.date.end) { + endTime = job.date.end; + totalDuration = Utils.getTimeDuration(job.date.start, endTime); + } else if (job.status === HistoryStatus.Running) { + endTime = new Date().toString(); + totalDuration = Utils.getTimeDuration(job.date.start, endTime); + } + + this.description = totalDuration; + this.contextValue = `${JobTreeItem.contextValue}_${job.status}`; + this.iconPath = HistoryManager.statusToIcon(job.status); + this.tooltip = `Name: ${job.name}\n` + + `Status: ${job.status}\n` + + `Started: ${Utils.getDateString(job.date.start)}\n` + + `Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` + + `Total Duration: ${totalDuration ? totalDuration : 'N/A'}`; + } + + async getChildren(): Promise { + return this.job.steps?.map(step => new StepTreeItem(this.workspaceFolder, step)) || []; + } +} \ No newline at end of file diff --git a/src/views/history/step.ts b/src/views/history/step.ts new file mode 100644 index 0000000..d6eb916 --- /dev/null +++ b/src/views/history/step.ts @@ -0,0 +1,37 @@ +import { TreeItem, TreeItemCollapsibleState, WorkspaceFolder } from "vscode"; +import { HistoryManager, HistoryStatus, Step } from "../../historyManager"; +import { Utils } from "../../utils"; +import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem"; + +export default class StepTreeItem extends TreeItem implements GithubLocalActionsTreeItem { + static contextValue = 'githubLocalActions.step'; + step: Step; + + constructor(public workspaceFolder: WorkspaceFolder, step: Step) { + super(step.name, TreeItemCollapsibleState.None); + this.step = step; + + let endTime: string | undefined; + let totalDuration: string | undefined; + if (step.date.end) { + endTime = step.date.end; + totalDuration = Utils.getTimeDuration(step.date.start, endTime); + } else if (step.status === HistoryStatus.Running) { + endTime = new Date().toString(); + totalDuration = Utils.getTimeDuration(step.date.start, endTime); + } + + this.description = totalDuration; + this.contextValue = `${StepTreeItem.contextValue}_${step.status}`; + this.iconPath = HistoryManager.statusToIcon(step.status); + this.tooltip = `Name: ${step.name}\n` + + `Status: ${step.status}\n` + + `Started: ${Utils.getDateString(step.date.start)}\n` + + `Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` + + `Total Duration: ${totalDuration ? totalDuration : 'N/A'}`; + } + + async getChildren(): Promise { + return []; + } +} \ No newline at end of file diff --git a/src/views/settings/settingsTreeDataProvider.ts b/src/views/settings/settingsTreeDataProvider.ts index 95273f9..6b58ed7 100644 --- a/src/views/settings/settingsTreeDataProvider.ts +++ b/src/views/settings/settingsTreeDataProvider.ts @@ -307,9 +307,9 @@ export default class SettingsTreeDataProvider implements TreeDataProvider { - options[index].label = options[index].label.slice(2) + options[index].label = options[index].label.slice(2); options[index].iconPath = new ThemeIcon('symbol-property'); - }) + }); const settings = await act.settingsManager.getSettings(optionsTreeItem.workspaceFolder, false); const optionNames = settings.options.map(option => option.name); From 6631a00fb56c90d47619d3a5899d56130b8ed883 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Sat, 30 Nov 2024 20:03:33 +0100 Subject: [PATCH 02/10] step ids are strings --- src/act.ts | 8 ++++---- src/historyManager.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/act.ts b/src/act.ts index a5c7658..bb25f05 100644 --- a/src/act.ts +++ b/src/act.ts @@ -445,7 +445,7 @@ export class Act { }, steps: [ { - id: -1, // Special id for setup job + id: "--setup-job", // Special id for setup job name: 'Setup Job', status: HistoryStatus.Running, date: { @@ -460,13 +460,13 @@ export class Act { const isCompleteJobStep = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length > 1; if (parsedMessage.stepID || isCompleteJobStep) { let stepName: string; - let stepId: number; + let stepId: string; if (!parsedMessage.stepID && isCompleteJobStep) { stepName = 'Complete Job'; - stepId = -2; // Special Id for complete job + stepId = "--complete-job"; // Special Id for complete job } else { stepName = parsedMessage.stage !== 'Main' ? `${parsedMessage.stage} ${parsedMessage.step}` : parsedMessage.step; - stepId = parseInt(parsedMessage.stepID[0]); + stepId = parsedMessage.stepID[0]; } if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { diff --git a/src/historyManager.ts b/src/historyManager.ts index 8654df2..3bf8f25 100644 --- a/src/historyManager.ts +++ b/src/historyManager.ts @@ -29,7 +29,7 @@ export interface Job { } export interface Step { - id: number, + id: string, name: string, status: HistoryStatus, date: { From c8ee9c2cd9c0953f39d8f659e8c3ee0ab626fb6d Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Sat, 30 Nov 2024 16:05:02 -0500 Subject: [PATCH 03/10] Add focus task action Signed-off-by: Sanjula Ganepola --- package.json | 14 ++++++++++++++ src/views/history/history.ts | 5 ----- src/views/history/historyTreeDataProvider.ts | 7 +++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index eb776fd..ece76bb 100644 --- a/package.json +++ b/package.json @@ -240,6 +240,11 @@ "enablement": "viewItem =~ /^githubLocalActions.history_(Success|Failed|Cancelled).*/", "icon": "$(close)" }, + { + "category": "GitHub Local Actions", + "command": "githubLocalActions.focusTask", + "title": "Focus Task" + }, { "category": "GitHub Local Actions", "command": "githubLocalActions.refreshSettings", @@ -436,6 +441,10 @@ "command": "githubLocalActions.remove", "when": "never" }, + { + "command": "githubLocalActions.focusTask", + "when": "never" + }, { "command": "githubLocalActions.refreshSettings", "when": "never" @@ -640,6 +649,11 @@ "when": "view == history && viewItem =~ /^githubLocalActions.history.*/", "group": "inline@3" }, + { + "command": "githubLocalActions.focusTask", + "when": "view == history && viewItem =~ /^githubLocalActions.history.*/", + "group": "0_focus@0" + }, { "command": "githubLocalActions.createSecretFile", "when": "view == settings && viewItem =~ /^githubLocalActions.secrets.*/", diff --git a/src/views/history/history.ts b/src/views/history/history.ts index aaa724d..f722bf3 100644 --- a/src/views/history/history.ts +++ b/src/views/history/history.ts @@ -34,11 +34,6 @@ export default class HistoryTreeItem extends TreeItem implements GithubLocalActi `Started: ${Utils.getDateString(history.date.start)}\n` + `Ended: ${endTime ? Utils.getDateString(endTime) : 'N/A'}\n` + `Total Duration: ${totalDuration ? totalDuration : 'N/A'}`; - // this.command = { - // title: 'Focus Task', - // command: 'githubLocalActions.focusTask', - // arguments: [this] - // }; } async getChildren(): Promise { diff --git a/src/views/history/historyTreeDataProvider.ts b/src/views/history/historyTreeDataProvider.ts index 683abb4..a10dcc1 100644 --- a/src/views/history/historyTreeDataProvider.ts +++ b/src/views/history/historyTreeDataProvider.ts @@ -31,8 +31,15 @@ export default class HistoryTreeDataProvider implements TreeDataProvider { + if (value === 'View Output') { + await commands.executeCommand('githubLocalActions.viewOutput', historyTreeItem); + } + }); }), commands.registerCommand('githubLocalActions.viewOutput', async (historyTreeItem: HistoryTreeItem) => { await act.historyManager.viewOutput(historyTreeItem.history); From c0ebf56ada003b11c4af14e054d9b8a64c72635a Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Sat, 30 Nov 2024 17:15:52 -0500 Subject: [PATCH 04/10] Make run event trigger individual tasks and add fix for when user uses json flag Signed-off-by: Sanjula Ganepola --- src/act.ts | 113 ++++++++++++++++++++++++----------------- src/historyManager.ts | 4 +- src/settingsManager.ts | 8 +-- 3 files changed, 72 insertions(+), 53 deletions(-) diff --git a/src/act.ts b/src/act.ts index bb25f05..a1a5e09 100644 --- a/src/act.ts +++ b/src/act.ts @@ -114,7 +114,7 @@ export enum Option { export interface CommandArgs { path: string, - options: string, + options: string[], name: string, extraHeader: { key: string, value: string }[] } @@ -253,7 +253,7 @@ export class Act { async runAllWorkflows(workspaceFolder: WorkspaceFolder) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, - options: ``, + options: [], name: workspaceFolder.name, extraHeader: [] }); @@ -262,7 +262,9 @@ export class Act { async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, - options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`, + options: [ + `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"` + ], name: workflow.name, extraHeader: [ { key: 'Workflow', value: workflow.name } @@ -273,7 +275,10 @@ export class Act { async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, - options: `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}" ${Option.Job} "${job.id}"`, + options: [ + `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`, + `${Option.Job} "${job.id}"` + ], name: `${workflow.name}/${job.name}`, extraHeader: [ { key: 'Workflow', value: workflow.name }, @@ -283,14 +288,19 @@ export class Act { } async runEvent(workspaceFolder: WorkspaceFolder, event: Event) { - return await this.runCommand({ - path: workspaceFolder.uri.fsPath, - options: event, - name: event, - extraHeader: [ - { key: 'Event', value: event } - ] - }); + let eventExists: boolean = false; + + const workflows = await this.workflowsManager.getWorkflows(workspaceFolder); + for (const workflow of workflows) { + if (event in workflow.yaml.on) { + eventExists = true; + await this.runWorkflow(workspaceFolder, workflow); + } + } + + if (!eventExists) { + window.showErrorMessage(`No workflows triggered by the ${event} event.`) + } } async runCommand(commandArgs: CommandArgs) { @@ -315,7 +325,7 @@ export class Act { // Initialize history for workspace if (!this.historyManager.workspaceHistory[commandArgs.path]) { this.historyManager.workspaceHistory[commandArgs.path] = []; - this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); + await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } // Process task count suffix @@ -343,17 +353,21 @@ export class Act { // Build command with settings const actCommand = Act.getActCommand(); const settings = await this.settingsManager.getSettings(workspaceFolder, true); - const command = - `${actCommand} ${Option.Json} ${commandArgs.options}` + - (settings.secrets.length > 0 ? ` ${Option.Secret} ${settings.secrets.map(secret => secret.key).join(` ${Option.Secret} `)}` : ``) + - (settings.secretFiles.length > 0 ? ` ${Option.SecretFile} "${settings.secretFiles[0].path}"` : ` ${Option.SecretFile} ""`) + - (settings.variables.length > 0 ? ` ${Option.Var} ${settings.variables.map(variable => `${variable.key}=${variable.value}`).join(` ${Option.Var} `)}` : ``) + - (settings.variableFiles.length > 0 ? ` ${Option.VarFile} "${settings.variableFiles[0].path}"` : ` ${Option.VarFile} ""`) + - (settings.inputs.length > 0 ? ` ${Option.Input} ${settings.inputs.map(input => `${input.key}=${input.value}`).join(` ${Option.Input} `)}` : ``) + - (settings.inputFiles.length > 0 ? ` ${Option.InputFile} "${settings.inputFiles[0].path}"` : ` ${Option.InputFile} ""`) + - (settings.runners.length > 0 ? ` ${Option.Platform} ${settings.runners.map(runner => `${runner.key}=${runner.value}`).join(` ${Option.Platform} `)}` : ``) + - (settings.payloadFiles.length > 0 ? ` ${Option.EventPath} "${settings.payloadFiles[0].path}"` : ` ${Option.EventPath} ""`) + - (settings.options.map(option => option.path ? ` --${option.name} ${option.path}` : ` --${option.name}`).join('')); + + const userOptions: string[] = [ + ...settings.secrets.map(secret => `${Option.Secret} ${secret.key}`), + (settings.secretFiles.length > 0 ? `${Option.SecretFile} "${settings.secretFiles[0].path}"` : `${Option.SecretFile} ""`), + ...settings.variables.map(variable => `${Option.Var} ${variable.key}=${variable.value}`), + (settings.variableFiles.length > 0 ? `${Option.VarFile} "${settings.variableFiles[0].path}"` : `${Option.VarFile} ""`), + ...settings.inputs.map(input => `${Option.Input} ${input.key}=${input.value}`), + (settings.inputFiles.length > 0 ? `${Option.InputFile} "${settings.inputFiles[0].path}"` : `${Option.InputFile} ""`), + ...settings.runners.map(runner => `${Option.Platform} ${runner.key}=${runner.value}`), + (settings.payloadFiles.length > 0 ? `${Option.EventPath} "${settings.payloadFiles[0].path}"` : `${Option.EventPath} ""`), + ...settings.options.map(option => option.path ? `--${option.name} ${option.path}` : `--${option.name}`) + ]; + + const command = `${actCommand} ${Option.Json} ${commandArgs.options.join(' ')} ${userOptions.join(' ')}`; + const displayCommand = `${actCommand} ${commandArgs.options.join(' ')} ${userOptions.join(' ')}`; // Execute task const taskExecution = await tasks.executeTask({ @@ -383,23 +397,6 @@ export class Act { runOptions: {}, group: TaskGroup.Build, execution: new CustomExecution(async (resolvedDefinition: TaskDefinition): Promise => { - // Add new entry to workspace history - this.historyManager.workspaceHistory[commandArgs.path].push({ - index: historyIndex, - count: count, - name: `${commandArgs.name}`, - status: HistoryStatus.Running, - date: { - start: start.toString() - }, - taskExecution: taskExecution, - commandArgs: commandArgs, - logPath: logPath, - jobs: [] - }); - historyTreeDataProvider.refresh(); - this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); - const writeEmitter = new EventEmitter(); const closeEmitter = new EventEmitter(); @@ -417,9 +414,9 @@ export class Act { } catch (error) { } }); - const handleIO = (data: any) => { + const handleIO = async (data: any) => { const lines: string[] = data.toString().split('\n').filter((line: string) => line !== ''); - for (const line of lines) { + for await (const line of lines) { const dateString = new Date().toString(); let message: string; @@ -507,9 +504,14 @@ export class Act { } catch (error) { message = line; } + + if (userOptions.includes(Option.Json)) { + message = line; + } + writeEmitter.fire(`${message.trimEnd()}\r\n`); historyTreeDataProvider.refresh(); - this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); + await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } }; @@ -544,7 +546,7 @@ export class Act { ); exec.stdout.on('data', handleIO); exec.stderr.on('data', handleIO); - exec.on('exit', (code, signal) => { + exec.on('exit', async (code, signal) => { const dateString = new Date().toString(); // Set execution status and end time in workspace history @@ -577,7 +579,7 @@ export class Act { } this.historyManager.workspaceHistory[commandArgs.path][historyIndex].date.end = dateString; historyTreeDataProvider.refresh(); - this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); + await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); if (signal === 'SIGINT') { writeEmitter.fire(`\r\nTask interrupted.\r\n`); @@ -595,7 +597,7 @@ export class Act { onDidWrite: writeEmitter.event, onDidClose: closeEmitter.event, open: async (initialDimensions: TerminalDimensions | undefined): Promise => { - writeEmitter.fire(`${command}\r\n\r\n`); + writeEmitter.fire(`${displayCommand}\r\n\r\n`); }, handleInput: (data: string) => { if (data === '\x03') { @@ -616,6 +618,23 @@ export class Act { }; }) }); + + // Add new entry to workspace history + this.historyManager.workspaceHistory[commandArgs.path].push({ + index: historyIndex, + count: count, + name: `${commandArgs.name}`, + status: HistoryStatus.Running, + date: { + start: start.toString() + }, + taskExecution: taskExecution, + commandArgs: commandArgs, + logPath: logPath, + jobs: [] + }); + historyTreeDataProvider.refresh(); + await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } async install(packageManager: string) { diff --git a/src/historyManager.ts b/src/historyManager.ts index 3bf8f25..6c38843 100644 --- a/src/historyManager.ts +++ b/src/historyManager.ts @@ -90,7 +90,7 @@ export class HistoryManager { this.workspaceHistory[workspaceFolder.uri.fsPath] = []; historyTreeDataProvider.refresh(); - this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); + await this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); } async viewOutput(history: History) { @@ -114,7 +114,7 @@ export class HistoryManager { const historyIndex = this.workspaceHistory[history.commandArgs.path].findIndex(workspaceHistory => workspaceHistory.index === history.index); if (historyIndex > -1) { this.workspaceHistory[history.commandArgs.path].splice(historyIndex, 1); - this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); + await this.storageManager.update(StorageKey.WorkspaceHistory, this.workspaceHistory); try { await workspace.fs.delete(Uri.file(history.logPath)); diff --git a/src/settingsManager.ts b/src/settingsManager.ts index e0ce85c..24d7286 100644 --- a/src/settingsManager.ts +++ b/src/settingsManager.ts @@ -15,7 +15,7 @@ export interface Settings { runners: Setting[]; payloadFiles: CustomSetting[]; options: CustomSetting[]; - environments: Setting[]; + // environments: Setting[]; } export interface Setting { @@ -74,7 +74,7 @@ export class SettingsManager { const runners = (await this.getSetting(workspaceFolder, SettingsManager.runnersRegExp, StorageKey.Runners, false, Visibility.show)).filter(runner => !isUserSelected || (runner.selected && runner.value)); const payloadFiles = (await this.getCustomSettings(workspaceFolder, StorageKey.PayloadFiles)).filter(payloadFile => !isUserSelected || payloadFile.selected); const options = (await this.getCustomSettings(workspaceFolder, StorageKey.Options)).filter(option => !isUserSelected || (option.selected && (option.path || option.notEditable))); - const environments = await this.getEnvironments(workspaceFolder); + // const environments = await this.getEnvironments(workspaceFolder); return { secrets: secrets, @@ -86,7 +86,7 @@ export class SettingsManager { runners: runners, payloadFiles: payloadFiles, options: options, - environments: environments + // environments: environments }; } @@ -131,7 +131,7 @@ export class SettingsManager { } } existingSettings[workspaceFolder.uri.fsPath] = settings; - this.storageManager.update(storageKey, existingSettings); + await this.storageManager.update(storageKey, existingSettings); return settings; } From db3400cde66e83e0eb2629807590142b3ca324bc Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Sat, 30 Nov 2024 17:37:27 -0500 Subject: [PATCH 05/10] Fix job name to show instead of ID Signed-off-by: Sanjula Ganepola --- src/act.ts | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/act.ts b/src/act.ts index a1a5e09..22f8dad 100644 --- a/src/act.ts +++ b/src/act.ts @@ -114,6 +114,7 @@ export enum Option { export interface CommandArgs { path: string, + workflow: Workflow, options: string[], name: string, extraHeader: { key: string, value: string }[] @@ -251,17 +252,20 @@ export class Act { } async runAllWorkflows(workspaceFolder: WorkspaceFolder) { - return await this.runCommand({ - path: workspaceFolder.uri.fsPath, - options: [], - name: workspaceFolder.name, - extraHeader: [] - }); + const workflows = await this.workflowsManager.getWorkflows(workspaceFolder); + if (workflows.length > 0) { + for (const workflow of workflows) { + await this.runWorkflow(workspaceFolder, workflow); + } + } else { + window.showErrorMessage('No workflows found.'); + } } async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, + workflow: workflow, options: [ `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"` ], @@ -275,6 +279,7 @@ export class Act { async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, + workflow: workflow, options: [ `${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`, `${Option.Job} "${job.id}"` @@ -291,15 +296,19 @@ export class Act { let eventExists: boolean = false; const workflows = await this.workflowsManager.getWorkflows(workspaceFolder); - for (const workflow of workflows) { - if (event in workflow.yaml.on) { - eventExists = true; - await this.runWorkflow(workspaceFolder, workflow); + if (workflows.length > 0) { + for (const workflow of workflows) { + if (event in workflow.yaml.on) { + eventExists = true; + await this.runWorkflow(workspaceFolder, workflow); + } } - } - if (!eventExists) { - window.showErrorMessage(`No workflows triggered by the ${event} event.`) + if (!eventExists) { + window.showErrorMessage(`No workflows triggered by the ${event} event.`) + } + } else { + window.showErrorMessage('No workflows found.'); } } @@ -411,7 +420,7 @@ export class Act { // Append data to log file await fs.appendFile(logPath, data); - } catch (error) { } + } catch (error: any) { } }); const handleIO = async (data: any) => { @@ -430,12 +439,20 @@ export class Act { // Update job and step status in workspace history if (parsedMessage.jobID) { + let jobName: string = parsedMessage.jobID; + try { + if (parsedMessage.jobID in commandArgs.workflow.yaml.jobs && commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name) { + jobName = commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name; + } + } catch (error: any) { } + let jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs! - .findIndex(job => job.name === parsedMessage.jobID); + .findIndex(job => job.name === jobName); if (jobIndex < 0) { + // Add new job with setup step this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.push({ - name: parsedMessage.jobID, + name: jobName, status: HistoryStatus.Running, date: { start: dateString @@ -501,7 +518,7 @@ export class Act { dateString; } } - } catch (error) { + } catch (error: any) { message = line; } From 303ba421b8fe699ac33de6870c0fb911d0de7342 Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Sat, 30 Nov 2024 20:55:59 -0500 Subject: [PATCH 06/10] Update history after all lines are handled Signed-off-by: Sanjula Ganepola --- src/act.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/act.ts b/src/act.ts index 22f8dad..4f38968 100644 --- a/src/act.ts +++ b/src/act.ts @@ -528,8 +528,8 @@ export class Act { writeEmitter.fire(`${message.trimEnd()}\r\n`); historyTreeDataProvider.refresh(); - await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } + await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); }; let shell = env.shell; From d78e1c19febaf4bc6ff33cee19d7d9f8c09436e8 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Sun, 1 Dec 2024 11:41:36 +0100 Subject: [PATCH 07/10] buffer last line without new line end --- src/act.ts | 199 ++++++++++++++++++++++++++++------------------------- 1 file changed, 105 insertions(+), 94 deletions(-) diff --git a/src/act.ts b/src/act.ts index 4f38968..98dfe58 100644 --- a/src/act.ts +++ b/src/act.ts @@ -423,113 +423,124 @@ export class Act { } catch (error: any) { } }); - const handleIO = async (data: any) => { - const lines: string[] = data.toString().split('\n').filter((line: string) => line !== ''); - for await (const line of lines) { - const dateString = new Date().toString(); - - let message: string; - try { - const parsedMessage = JSON.parse(line); - if (parsedMessage.msg) { - message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`; - } else { - message = line; - } - - // Update job and step status in workspace history - if (parsedMessage.jobID) { - let jobName: string = parsedMessage.jobID; - try { - if (parsedMessage.jobID in commandArgs.workflow.yaml.jobs && commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name) { - jobName = commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name; - } - } catch (error: any) { } - - let jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs! - .findIndex(job => job.name === jobName); - if (jobIndex < 0) { - - // Add new job with setup step - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.push({ - name: jobName, - status: HistoryStatus.Running, - date: { - start: dateString - }, - steps: [ - { - id: "--setup-job", // Special id for setup job - name: 'Setup Job', - status: HistoryStatus.Running, - date: { - start: dateString - } - } - ] - }); - jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.length - 1; + const handleIO = () => { + let lastline: string = ""; + return async (data: any) => { + let xdata: string = data.toString(); + let lines: string[] = xdata.split('\n').filter((line: string) => line !== ''); + if (lastline?.length > 0) { + lines[0] = lastline + lines[0]; + lastline = ""; + } + if (!xdata.endsWith("\n")) { + lastline = lines.pop() || ""; + } + for await (const line of lines) { + const dateString = new Date().toString(); + + let message: string; + try { + const parsedMessage = JSON.parse(line); + if (typeof parsedMessage.msg === 'string') { + message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`; + } else { + message = line; } - const isCompleteJobStep = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length > 1; - if (parsedMessage.stepID || isCompleteJobStep) { - let stepName: string; - let stepId: string; - if (!parsedMessage.stepID && isCompleteJobStep) { - stepName = 'Complete Job'; - stepId = "--complete-job"; // Special Id for complete job - } else { - stepName = parsedMessage.stage !== 'Main' ? `${parsedMessage.stage} ${parsedMessage.step}` : parsedMessage.step; - stepId = parsedMessage.stepID[0]; - } - - if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { - // TODO: How to know if setup job step failed? - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status = HistoryStatus.Success; - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].date.end = dateString; - } - - let stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps! - .findIndex(step => step.id === stepId && step.name === stepName); - if (stepIndex < 0) { - // Add new step - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.push({ - id: stepId, - name: stepName, + // Update job and step status in workspace history + if (parsedMessage.jobID) { + let jobName: string = parsedMessage.jobID; + try { + if (parsedMessage.jobID in commandArgs.workflow.yaml.jobs && commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name) { + jobName = commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name; + } + } catch (error: any) { } + + let jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs! + .findIndex(job => job.name === jobName); + if (jobIndex < 0) { + + // Add new job with setup step + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.push({ + name: jobName, status: HistoryStatus.Running, date: { start: dateString - } + }, + steps: [ + { + id: "--setup-job", // Special id for setup job + name: 'Setup Job', + status: HistoryStatus.Running, + date: { + start: dateString + } + } + ] }); - stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length - 1; + jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.length - 1; } - if (parsedMessage.stepResult) { - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].status = - parsedMessage.stepResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].date.end = dateString; + const isCompleteJobStep = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length > 1; + if (parsedMessage.stepID || isCompleteJobStep) { + let stepName: string; + let stepId: string; + if (!parsedMessage.stepID && isCompleteJobStep) { + stepName = 'Complete Job'; + stepId = "--complete-job"; // Special Id for complete job + } else { + stepName = parsedMessage.stage !== 'Main' ? `${parsedMessage.stage} ${parsedMessage.step}` : parsedMessage.step; + stepId = parsedMessage.stepID[0]; + } + + if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { + // TODO: How to know if setup job step failed? + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status = HistoryStatus.Success; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].date.end = dateString; + } + + let stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps! + .findIndex(step => step.id === stepId && step.name === stepName); + if (stepIndex < 0) { + // Add new step + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.push({ + id: stepId, + name: stepName, + status: HistoryStatus.Running, + date: { + start: dateString + } + }); + stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length - 1; + } + + if (parsedMessage.stepResult) { + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].status = + parsedMessage.stepResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].date.end = dateString; + } } - } - if (parsedMessage.jobResult) { - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].status = - parsedMessage.jobResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = - dateString; + if (parsedMessage.jobResult) { + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].status = + parsedMessage.jobResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = + dateString; + } } + } catch (error: any) { + message = line; } - } catch (error: any) { - message = line; - } - if (userOptions.includes(Option.Json)) { - message = line; - } + if (userOptions.includes(Option.Json)) { + message = line; + } - writeEmitter.fire(`${message.trimEnd()}\r\n`); - historyTreeDataProvider.refresh(); + writeEmitter.fire(`${message.trimEnd()}\r\n`); + historyTreeDataProvider.refresh(); + } + await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); } - await this.storageManager.update(StorageKey.WorkspaceHistory, this.historyManager.workspaceHistory); }; let shell = env.shell; @@ -561,8 +572,8 @@ export class Act { } } ); - exec.stdout.on('data', handleIO); - exec.stderr.on('data', handleIO); + exec.stdout.on('data', handleIO()); + exec.stderr.on('data', handleIO()); exec.on('exit', async (code, signal) => { const dateString = new Date().toString(); From f60cb2a95535eb294108f5db7a0c0485573b374c Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Wed, 4 Dec 2024 23:25:00 -0500 Subject: [PATCH 08/10] Forcefully set pre stage and setup job status to success, remove complete job Signed-off-by: Sanjula Ganepola --- src/act.ts | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/act.ts b/src/act.ts index 98dfe58..1074411 100644 --- a/src/act.ts +++ b/src/act.ts @@ -459,7 +459,6 @@ export class Act { let jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs! .findIndex(job => job.name === jobName); if (jobIndex < 0) { - // Add new job with setup step this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.push({ name: jobName, @@ -481,20 +480,40 @@ export class Act { jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.length - 1; } - const isCompleteJobStep = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length > 1; - if (parsedMessage.stepID || isCompleteJobStep) { + // TODO: Add complete job step. To be fixed with https://github.com/nektos/act/issues/2551 + // const isCompleteJobStep = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps!.length > 1; + // if (parsedMessage.stepID || isCompleteJobStep) { + // let stepName: string; + // let stepId: string; + // if (!parsedMessage.stepID && isCompleteJobStep) { + // stepName = 'Complete Job'; + // stepId = "--complete-job"; // Special Id for complete job + // } else { + // stepName = parsedMessage.stage !== 'Main' ? `${parsedMessage.stage} ${parsedMessage.step}` : parsedMessage.step; + // stepId = parsedMessage.stepID[0]; + // } + + if (parsedMessage.stepID) { let stepName: string; - let stepId: string; - if (!parsedMessage.stepID && isCompleteJobStep) { - stepName = 'Complete Job'; - stepId = "--complete-job"; // Special Id for complete job + const stepId: string = parsedMessage.stepID[0]; + if (parsedMessage.stage !== 'Main') { + stepName = `${parsedMessage.stage} ${parsedMessage.step}`; } else { - stepName = parsedMessage.stage !== 'Main' ? `${parsedMessage.stage} ${parsedMessage.step}` : parsedMessage.step; - stepId = parsedMessage.stepID[0]; + stepName = parsedMessage.step; + + // TODO: This forcefully sets any pre step to success. To be fixed with https://github.com/nektos/act/issues/2551 + const preStepName = `Pre ${parsedMessage.step}`; + let preStepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps! + .findIndex(step => step.id === stepId && step.name === preStepName); + if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].status === HistoryStatus.Running) { + + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].status = HistoryStatus.Success; + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].date.end = dateString; + } } if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { - // TODO: How to know if setup job step failed? + // TODO: This forcefully sets the setup job step to success. To be fixed with https://github.com/nektos/act/issues/2551 this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status = HistoryStatus.Success; this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].date.end = dateString; } From eb73f95d686b48a0055e3bc095d48e5364748d5c Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Thu, 5 Dec 2024 22:22:12 -0500 Subject: [PATCH 09/10] Fix preStepIndex Signed-off-by: Sanjula Ganepola --- src/act.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/act.ts b/src/act.ts index 1074411..e7e589f 100644 --- a/src/act.ts +++ b/src/act.ts @@ -505,7 +505,7 @@ export class Act { const preStepName = `Pre ${parsedMessage.step}`; let preStepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps! .findIndex(step => step.id === stepId && step.name === preStepName); - if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].status === HistoryStatus.Running) { + if (preStepIndex > -1 && this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].status === HistoryStatus.Running) { this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].status = HistoryStatus.Success; this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![preStepIndex].date.end = dateString; From 726049c2c16401f7ea1ae75b8c05eb0b58a1efc7 Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Thu, 5 Dec 2024 23:51:48 -0500 Subject: [PATCH 10/10] Remove setup job until act issues are resolved Signed-off-by: Sanjula Ganepola --- src/act.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/act.ts b/src/act.ts index e7e589f..be3322a 100644 --- a/src/act.ts +++ b/src/act.ts @@ -467,14 +467,15 @@ export class Act { start: dateString }, steps: [ - { - id: "--setup-job", // Special id for setup job - name: 'Setup Job', - status: HistoryStatus.Running, - date: { - start: dateString - } - } + // TODO: Add setup job step. To be fixed with https://github.com/nektos/act/issues/2551 + // { + // id: "--setup-job", // Special id for setup job + // name: 'Setup Job', + // status: HistoryStatus.Running, + // date: { + // start: dateString + // } + // } ] }); jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.length - 1; @@ -512,11 +513,12 @@ export class Act { } } - if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { - // TODO: This forcefully sets the setup job step to success. To be fixed with https://github.com/nektos/act/issues/2551 - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status = HistoryStatus.Success; - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].date.end = dateString; - } + // TODO: Add setup job status check. To be fixed with https://github.com/nektos/act/issues/2551 + // if (this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status === HistoryStatus.Running) { + // // TODO: This forcefully sets the setup job step to success. To be fixed with https://github.com/nektos/act/issues/2551 + // this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].status = HistoryStatus.Success; + // this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![0].date.end = dateString; + // } let stepIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps! .findIndex(step => step.id === stepId && step.name === stepName);