Skip to content

Commit

Permalink
Refactored mathods for good readability
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed May 22, 2024
1 parent 057b32b commit 4471cb3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/buildSummary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2024 The MathWorks, Inc.
import * as core from "@actions/core";
import { join } from 'path';
import { readFile } from 'fs';
import { promisify } from 'util';

Expand Down Expand Up @@ -28,7 +29,7 @@ export async function readJsonFile(filePath: string): Promise<TaskList> {
}
}

export function addBuildSummaryTable(tasks: TaskList): void {
export function getBuildSummaryTable(tasks: TaskList): string[][] {
const header: string[] = ['Task Name', 'Status', 'Description', 'Duration (HH:MM:SS)'];
let taskSummaryTableRows: string[][] = [header];

Expand All @@ -48,10 +49,14 @@ export function addBuildSummaryTable(tasks: TaskList): void {
taskSummaryTableRows.push(taskDetails);
});

core.summary
.addHeading('MATLAB Build Results')
.addTable(taskSummaryTableRows)
.write();
return taskSummaryTableRows;
}

export function writeSummary(taskSummaryTableRows: string[][]) {
core.summary
.addHeading('MATLAB Build Results')
.addTable(taskSummaryTableRows)
.write();
}

export async function processAndDisplayBuildSummary() {
Expand All @@ -64,9 +69,10 @@ export async function processAndDisplayBuildSummary() {

try {
const runnerTemp = process.env.RUNNER_TEMP;
const filePath = runnerTemp + `/buildSummary_${runId}.json`;
const filePath = join(runnerTemp, `buildSummary_${runId}.json`);

Check failure on line 72 in src/buildSummary.ts

View workflow job for this annotation

GitHub Actions / Build and Test

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
const data = await readJsonFile(filePath);
addBuildSummaryTable(data);
const taskSummaryTableRows = getBuildSummaryTable(data);
writeSummary(taskSummaryTableRows);
} catch (error) {
console.error('An error occurred while reading the build summary file or adding the build summary table:', error);
}
Expand Down

0 comments on commit 4471cb3

Please sign in to comment.