From db4f9d4055c640adaa763a766618e543592f757d Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:07:17 +0530 Subject: [PATCH] Bash bug fixes (#37) * Fixed issue #35 * Fixed issue #36 * Updated method names --- src/buildSummary.ts | 53 ++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/buildSummary.ts b/src/buildSummary.ts index 95c02b9..2a05215 100644 --- a/src/buildSummary.ts +++ b/src/buildSummary.ts @@ -1,7 +1,7 @@ // Copyright 2024 The MathWorks, Inc. import * as core from "@actions/core"; import { join } from 'path'; -import { readFileSync } from 'fs'; +import { readFileSync, unlinkSync} from 'fs'; export interface Task { name: string; @@ -16,21 +16,13 @@ export function getBuildSummaryTable(tasks: Task[]): string[][] { const header: string[] = ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)']; let taskSummaryTableRows: string[][] = [header]; - tasks.forEach((task, index) => { - let taskDetails: string[] = []; - taskDetails.push(task.name); - if (task.failed) { - taskDetails.push('🔴 FAILED'); - } else if (task.skipped) { - taskDetails.push('🔵 SKIPPED'); - } else { - taskDetails.push('🟢 SUCCESS'); - } - taskDetails.push(task.description); - taskDetails.push(task.duration); - - taskSummaryTableRows.push(taskDetails); - }); + if(!Array.isArray(tasks)){ + taskSummaryTableRows = getTaskSummaryRows(tasks, taskSummaryTableRows); + } else { + tasks.forEach((task, index) => { + taskSummaryTableRows = getTaskSummaryRows(task, taskSummaryTableRows); + }); + } return taskSummaryTableRows; } @@ -49,15 +41,42 @@ export function processAndDisplayBuildSummary() { const runId = process.env.GITHUB_RUN_ID || ''; const runnerTemp = process.env.RUNNER_TEMP || ''; + const filePath: string = join(runnerTemp, `buildSummary${runId}.json`); let taskSummaryTableRows; try { - const filePath: string = join(runnerTemp, `buildSummary${runId}.json`); const data = JSON.parse(readFileSync(filePath, { encoding: 'utf8' })); taskSummaryTableRows = getBuildSummaryTable(data); } catch (e) { console.error('An error occurred while reading the build summary file:', e); return; + } finally { + try { + unlinkSync(filePath); + } catch (e) { + console.error(`An error occurred while trying to delete the build summary file ${filePath}:`, e); + } } writeSummary(taskSummaryTableRows); } +export function getTaskDetails(tasks: Task): string[] { + let taskDetails: string[] = []; + taskDetails.push(tasks.name); + if (tasks.failed) { + taskDetails.push('🔴 FAILED'); + } else if (tasks.skipped) { + taskDetails.push('🔵 SKIPPED'); + } else { + taskDetails.push('🟢 SUCCESS'); + } + taskDetails.push(tasks.description); + taskDetails.push(tasks.duration); + return taskDetails; +} + +export function getTaskSummaryRows(task: Task, taskSummaryTableRows: string[][]): string[][] { + let taskDetails: string[] = []; + taskDetails = getTaskDetails(task); + taskSummaryTableRows.push(taskDetails); + return taskSummaryTableRows; +}