From 2c6b789cdb80e7c40ffd2ef427201e14ef612fa7 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski <47204011+nbhoski@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:06:17 +0530 Subject: [PATCH] Changed indenattion --- .../+ciplugins/+github/BuildSummaryPlugin.m | 2 +- src/buildSummary.ts | 82 +++++++++---------- src/buildSummary.unit.test.ts | 46 +++++------ 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/plugins/+ciplugins/+github/BuildSummaryPlugin.m b/plugins/+ciplugins/+github/BuildSummaryPlugin.m index cf0059b..1eed7a1 100644 --- a/plugins/+ciplugins/+github/BuildSummaryPlugin.m +++ b/plugins/+ciplugins/+github/BuildSummaryPlugin.m @@ -6,7 +6,7 @@ function runTaskGraph(plugin, pluginData) runTaskGraph@matlab.buildtool.plugins.BuildRunnerPlugin(plugin, pluginData); - [fID, msg] = fopen(fullfile(getenv("RUNNER_TEMP") ,"buildSummary_" + getenv("GITHUB_RUN_ID") + ".json"), "w"); + [fID, msg] = fopen(fullfile(getenv("RUNNER_TEMP") ,"buildSummary" + getenv("GITHUB_RUN_ID") + ".json"), "w"); if fID == -1 warning("ciplugins:github:BuildSummaryPlugin:UnableToOpenFile","Unable to open a file required to create the MATLAB build summary table: %s", msg); diff --git a/src/buildSummary.ts b/src/buildSummary.ts index 31d705e..b48d474 100644 --- a/src/buildSummary.ts +++ b/src/buildSummary.ts @@ -4,56 +4,56 @@ import { join } from 'path'; import { readFileSync } from 'fs'; export interface Task { - name: string; - description: string; - failed: boolean; - skipped: boolean; - duration: string; + name: string; + description: string; + failed: boolean; + skipped: boolean; + duration: string; } 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); - }); - - return taskSummaryTableRows; + 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); + }); + + return taskSummaryTableRows; } export function writeSummary(taskSummaryTableRows: string[][]) { - core.summary - .addTable(taskSummaryTableRows) - .write(); + core.summary + .addTable(taskSummaryTableRows) + .write(); } export function processAndDisplayBuildSummary() { - const runId = process.env.GITHUB_RUN_ID; - const runnerTemp = process.env.RUNNER_TEMP; - let filePath: string; - - if (!runId) { - filePath = join(runnerTemp as string, `buildSummary.json`); - } else { - filePath = join(runnerTemp as string, `buildSummary_${runId as string}.json`); - } - - const data = JSON.parse(readFileSync(filePath, { encoding: 'utf8' })); - const taskSummaryTableRows = getBuildSummaryTable(data); - writeSummary(taskSummaryTableRows); + const runId = process.env.GITHUB_RUN_ID; + const runnerTemp = process.env.RUNNER_TEMP; + let filePath: string; + + if (!runId) { + filePath = join(runnerTemp as string, `buildSummary.json`); + } else { + filePath = join(runnerTemp as string, `buildSummary${runId as string}.json`); + } + + const data = JSON.parse(readFileSync(filePath, { encoding: 'utf8' })); + const taskSummaryTableRows = getBuildSummaryTable(data); + writeSummary(taskSummaryTableRows); } diff --git a/src/buildSummary.unit.test.ts b/src/buildSummary.unit.test.ts index ad31d11..0586f9f 100644 --- a/src/buildSummary.unit.test.ts +++ b/src/buildSummary.unit.test.ts @@ -5,37 +5,37 @@ import * as core from '@actions/core'; jest.mock('@actions/core', () => ({ - summary: { - addTable: jest.fn().mockReturnThis(), - write: jest.fn().mockReturnThis(), - }, + summary: { + addTable: jest.fn().mockReturnThis(), + write: jest.fn().mockReturnThis(), + }, })); describe('summaryGeneration', () => { - it('generates a summary table correctly', () => { - const mockTasks: buildSummary.Task[] = [ - { name: 'Test Task', description: 'A test task', failed: true, skipped: false, duration: '00:00:10' } + it('generates a summary table correctly', () => { + 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)'], - ['Test Task', '🔴 FAILED', 'A test task', '00:00:10'], - ]; + const expectedTable = [ + ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)'], + ['Test Task', '🔴 FAILED', 'A test task', '00:00:10'], + ]; - const table = buildSummary.getBuildSummaryTable(mockTasks); + const table = buildSummary.getBuildSummaryTable(mockTasks); - expect(table).toEqual(expectedTable); - }); + expect(table).toEqual(expectedTable); + }); - it('writes the summary correctly', () => { - const mockTableRows = [ - ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)'], - ['Test Task', '🔴 FAILED', 'A test task', '00:00:10'], - ]; + it('writes the summary correctly', () => { + const mockTableRows = [ + ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)'], + ['Test Task', '🔴 FAILED', 'A test task', '00:00:10'], + ]; - buildSummary.writeSummary(mockTableRows); + buildSummary.writeSummary(mockTableRows); - expect(core.summary.addTable).toHaveBeenCalledTimes(1); - expect(core.summary.addTable).toHaveBeenCalledWith(mockTableRows); - }); + expect(core.summary.addTable).toHaveBeenCalledTimes(1); + expect(core.summary.addTable).toHaveBeenCalledWith(mockTableRows); + }); });