From 781cc0474f5e0f1e051472e465e722a0b4e84388 Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Tue, 10 Dec 2024 01:03:04 -0500 Subject: [PATCH 1/3] Add support for skipped job and step status Signed-off-by: Sanjula Ganepola --- package.json | 24 ++++++++++++++++-------- src/act.ts | 13 ++++++++++--- src/historyManager.ts | 14 ++++++++++++++ src/views/history/job.ts | 2 +- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index ece76bb..a092e9b 100644 --- a/package.json +++ b/package.json @@ -765,6 +765,14 @@ "light": "#89d185" } }, + { + "id": "GitHubLocalActions.red", + "description": "Color for red in the GitHub Local Actions extension", + "defaults": { + "dark": "#f48771", + "light": "#f48771" + } + }, { "id": "GitHubLocalActions.yellow", "description": "Color for yellow in the GitHub Local Actions extension", @@ -773,6 +781,14 @@ "light": "#cca700" } }, + { + "id": "GitHubLocalActions.grey", + "description": "Color for grey in the GitHub Local Actions extension", + "defaults": { + "dark": "#808080", + "light": "#808080" + } + }, { "id": "GitHubLocalActions.purple", "description": "Color for purple in the GitHub Local Actions extension", @@ -780,14 +796,6 @@ "dark": "#d6bcfa", "light": "#d6bcfa" } - }, - { - "id": "GitHubLocalActions.red", - "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 ba4e6c2..7b820a6 100644 --- a/src/act.ts +++ b/src/act.ts @@ -375,7 +375,7 @@ export class Act { ...settings.options.map(option => option.path ? `--${option.name} ${option.path}` : `--${option.name}`) ]; - const command = `${actCommand} ${Option.Json} ${commandArgs.options.join(' ')} ${userOptions.join(' ')}`; + const command = `${actCommand} ${Option.Json} ${Option.Verbose} ${commandArgs.options.join(' ')} ${userOptions.join(' ')}`; const displayCommand = `${actCommand} ${commandArgs.options.join(' ')} ${userOptions.join(' ')}`; // Execute task @@ -442,6 +442,13 @@ export class Act { let message: string; try { const parsedMessage = JSON.parse(line); + + // Filter all debug and trace messages except for skipped jobs and steps + if (parsedMessage.level && ['debug', 'trace'].includes(parsedMessage.level) && parsedMessage.jobResult !== 'skipped' && parsedMessage.stepResult !== 'skipped') { + continue; + } + + // Prepend job name to message if (typeof parsedMessage.msg === 'string') { message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`; } else { @@ -516,14 +523,14 @@ export class Act { if (parsedMessage.stepResult) { this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].status = - parsedMessage.stepResult === 'success' ? HistoryStatus.Success : HistoryStatus.Failed; + HistoryManager.stepResultToHistoryStatus(parsedMessage.stepResult); 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; + HistoryManager.stepResultToHistoryStatus(parsedMessage.jobResult); this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = dateString; } diff --git a/src/historyManager.ts b/src/historyManager.ts index 6c38843..47b52d6 100644 --- a/src/historyManager.ts +++ b/src/historyManager.ts @@ -42,6 +42,7 @@ export enum HistoryStatus { Running = 'Running', Success = 'Success', Failed = 'Failed', + Skipped = 'Skipped', Cancelled = 'Cancelled', Unknown = 'Unknown' } @@ -132,8 +133,21 @@ export class HistoryManager { return new ThemeIcon('error', new ThemeColor('GitHubLocalActions.red')); case HistoryStatus.Cancelled: return new ThemeIcon('circle-slash', new ThemeColor('GitHubLocalActions.yellow')); + case HistoryStatus.Skipped: + return new ThemeIcon('issues', new ThemeColor('GitHubLocalActions.grey')); case HistoryStatus.Unknown: return new ThemeIcon('question', new ThemeColor('GitHubLocalActions.purple')); } } + + static stepResultToHistoryStatus(stepResult: string) { + switch (stepResult) { + case 'success': + return HistoryStatus.Success; + case 'skipped': + return HistoryStatus.Skipped; + default: + return HistoryStatus.Failed; + } + } } \ No newline at end of file diff --git a/src/views/history/job.ts b/src/views/history/job.ts index 4698e27..d4bc840 100644 --- a/src/views/history/job.ts +++ b/src/views/history/job.ts @@ -9,7 +9,7 @@ export default class JobTreeItem extends TreeItem implements GithubLocalActionsT job: Job; constructor(public workspaceFolder: WorkspaceFolder, job: Job) { - super(job.name, TreeItemCollapsibleState.Expanded); + super(job.name, job.status === HistoryStatus.Skipped ? TreeItemCollapsibleState.None : TreeItemCollapsibleState.Expanded); this.job = job; let endTime: string | undefined; From a50b44b152d191ced31dedb69956f64a52c7a4dc Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Tue, 10 Dec 2024 17:41:47 -0500 Subject: [PATCH 2/3] Filter all skipped pre and post stage steps Signed-off-by: Sanjula Ganepola --- src/act.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/act.ts b/src/act.ts index 7b820a6..f533d6f 100644 --- a/src/act.ts +++ b/src/act.ts @@ -448,6 +448,11 @@ export class Act { continue; } + // Filter all skipped pre and post stage steps + if ((parsedMessage.jobResult === 'skipped' || parsedMessage.stepResult === 'skipped') && parsedMessage.stage !== 'Main') { + continue; + } + // Prepend job name to message if (typeof parsedMessage.msg === 'string') { message = `${parsedMessage.job ? `[${parsedMessage.job}] ` : ``}${parsedMessage.msg}`; From fd6dc386f9dcfd29726ffeaa7c9bd76fd9143229 Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Tue, 10 Dec 2024 19:48:38 -0500 Subject: [PATCH 3/3] Fix handling of user manually selecting verbose logging Signed-off-by: Sanjula Ganepola --- src/act.ts | 156 +++++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 76 deletions(-) diff --git a/src/act.ts b/src/act.ts index f533d6f..06337f7 100644 --- a/src/act.ts +++ b/src/act.ts @@ -443,14 +443,16 @@ export class Act { try { const parsedMessage = JSON.parse(line); - // Filter all debug and trace messages except for skipped jobs and steps - if (parsedMessage.level && ['debug', 'trace'].includes(parsedMessage.level) && parsedMessage.jobResult !== 'skipped' && parsedMessage.stepResult !== 'skipped') { - continue; - } - - // Filter all skipped pre and post stage steps - if ((parsedMessage.jobResult === 'skipped' || parsedMessage.stepResult === 'skipped') && parsedMessage.stage !== 'Main') { - continue; + let updateHistory: boolean = true; + // 1. Filter all debug and trace messages except for skipped jobs and steps + // 2. Filter all skipped pre and post stage steps + if ((parsedMessage.level && ['debug', 'trace'].includes(parsedMessage.level) && parsedMessage.jobResult !== 'skipped' && parsedMessage.stepResult !== 'skipped') || + (parsedMessage.stepResult === 'skipped' && parsedMessage.stage !== 'Main')) { + if (userOptions.includes(Option.Verbose)) { + updateHistory = false; + } else { + continue; + } } // Prepend job name to message @@ -460,84 +462,86 @@ export class Act { message = line; } - // Update job 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) { - // Use the name set for the job by the user - jobName = commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name; - } - } catch (error: any) { } - - // Update name if it is a matrix - if (parsedMessage.matrix && Object.keys(parsedMessage.matrix).length > 0) { - const matrixValues = Object.values(parsedMessage.matrix).join(", "); - jobName = `${jobName} (${matrixValues})`; - } - - 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: [] - }); - jobIndex = this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs!.length - 1; - } - - // Update step status in workspace history - if (parsedMessage.stepID) { - let stepName: string; - const stepId: string = parsedMessage.stepID[0]; - if (parsedMessage.stage !== 'Main') { - stepName = `${parsedMessage.stage} ${parsedMessage.step}`; - } else { - 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 (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; + if (updateHistory) { + // Update job 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) { + // Use the name set for the job by the user + jobName = commandArgs.workflow.yaml.jobs[parsedMessage.jobID].name; } + } catch (error: any) { } + + // Update name if it is a matrix + if (parsedMessage.matrix && Object.keys(parsedMessage.matrix).length > 0) { + const matrixValues = Object.values(parsedMessage.matrix).join(", "); + jobName = `${jobName} (${matrixValues})`; } - 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, + 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: [] }); - 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 = - HistoryManager.stepResultToHistoryStatus(parsedMessage.stepResult); - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].steps![stepIndex].date.end = dateString; - } - } + // Update step status in workspace history + if (parsedMessage.stepID) { + let stepName: string; + const stepId: string = parsedMessage.stepID[0]; + if (parsedMessage.stage !== 'Main') { + stepName = `${parsedMessage.stage} ${parsedMessage.step}`; + } else { + stepName = parsedMessage.step; - if (parsedMessage.jobResult) { - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].status = - HistoryManager.stepResultToHistoryStatus(parsedMessage.jobResult); - this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = - dateString; + // 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 (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; + } + } + + 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 = + HistoryManager.stepResultToHistoryStatus(parsedMessage.stepResult); + 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 = + HistoryManager.stepResultToHistoryStatus(parsedMessage.jobResult); + this.historyManager.workspaceHistory[commandArgs.path][historyIndex].jobs![jobIndex].date.end = + dateString; + } } } } catch (error: any) {