Skip to content

Commit

Permalink
Updated as per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed Jun 26, 2024
1 parent d78fddf commit 0df5883
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
3 changes: 1 addition & 2 deletions plugins/+ciplugins/+github/BuildSummaryPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 5 additions & 22 deletions src/buildSummary.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,25 +11,12 @@ export interface Task {
duration: string;
}

export interface TaskList {
taskDetails: Task[];
}

export async function readJsonFile(filePath: string): Promise<TaskList> {
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) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions src/buildSummary.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)'],
Expand Down

0 comments on commit 0df5883

Please sign in to comment.