From 0df5883259e0008ff1c97c15ca7f06bb7fc7d8e8 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com> Date: Wed, 26 Jun 2024 22:24:26 +0530 Subject: [PATCH] Updated as per review comments --- .../+ciplugins/+github/BuildSummaryPlugin.m | 3 +-- src/buildSummary.ts | 27 ++++--------------- src/buildSummary.unit.test.ts | 8 +++--- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/plugins/+ciplugins/+github/BuildSummaryPlugin.m b/plugins/+ciplugins/+github/BuildSummaryPlugin.m index 6582fca..e26dfd7 100644 --- a/plugins/+ciplugins/+github/BuildSummaryPlugin.m +++ b/plugins/+ciplugins/+github/BuildSummaryPlugin.m @@ -20,8 +20,7 @@ function runTaskGraph(plugin, pluginData) taskDetails(idx).skipped = pluginData.TaskResults(idx).Skipped; taskDetails(idx).duration = string(pluginData.TaskResults(idx).Duration); end - a = struct("taskDetails",taskDetails); - s = jsonencode(a); + s = jsonencode(taskDetails); fprintf(fID, "%s",s); end end diff --git a/src/buildSummary.ts b/src/buildSummary.ts index 51de54d..c78df21 100644 --- a/src/buildSummary.ts +++ b/src/buildSummary.ts @@ -1,11 +1,7 @@ // Copyright 2024 The MathWorks, Inc. import * as core from "@actions/core"; import { join } from 'path'; -import { readFile } from 'fs'; -import { promisify } from 'util'; - -// Promisify the readFile function to use it with async/await -const readFileAsync = promisify(readFile); +import { readFileSync } from 'fs'; export interface Task { name: string; @@ -15,25 +11,12 @@ export interface Task { duration: string; } -export interface TaskList { - taskDetails: Task[]; -} - -export async function readJsonFile(filePath: string): Promise { - try { - const data = await readFileAsync(filePath, { encoding: 'utf8' }); - return JSON.parse(data); - } catch (error) { - console.error('Error reading the buildSummary file:', error); - throw error; - } -} -export function getBuildSummaryTable(tasks: TaskList): string[][] { +export function getBuildSummaryTable(tasks: Task[]): string[][] { const header: string[] = ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)']; let taskSummaryTableRows: string[][] = [header]; - tasks.taskDetails.forEach((task, index) => { + tasks.forEach((task, index) => { let taskDetails: string[] = []; taskDetails.push(task.name); if (task.failed) { @@ -58,7 +41,7 @@ export function writeSummary(taskSummaryTableRows: string[][]) { .write(); } -export async function processAndDisplayBuildSummary() { +export function processAndDisplayBuildSummary() { const runId = process.env.GITHUB_RUN_ID; const runnerTemp = process.env.RUNNER_TEMP; let filePath: string; @@ -71,7 +54,7 @@ export async function processAndDisplayBuildSummary() { filePath = join(runnerTemp as string, `buildSummary_${runId as string}.json`); } - const data = await readJsonFile(filePath); + const data =JSON.parse(readFileSync(filePath, { encoding: 'utf8' })); const taskSummaryTableRows = getBuildSummaryTable(data); writeSummary(taskSummaryTableRows); } catch (error) { diff --git a/src/buildSummary.unit.test.ts b/src/buildSummary.unit.test.ts index 1877612..ad31d11 100644 --- a/src/buildSummary.unit.test.ts +++ b/src/buildSummary.unit.test.ts @@ -13,11 +13,9 @@ jest.mock('@actions/core', () => ({ describe('summaryGeneration', () => { it('generates a summary table correctly', () => { - const mockTasks = { - taskDetails: [ - { name: 'Test Task', description: 'A test task', failed: true, skipped: false, duration: '00:00:10' }, - ], - }; + const mockTasks: buildSummary.Task[] = [ + { name: 'Test Task', description: 'A test task', failed: true, skipped: false, duration: '00:00:10' } + ]; const expectedTable = [ ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)'],