Skip to content

Commit

Permalink
Bash bug fixes (#37)
Browse files Browse the repository at this point in the history
* Fixed issue #35

* Fixed issue #36

* Updated method names
  • Loading branch information
nbhoski authored Jul 9, 2024
1 parent fabba39 commit db4f9d4
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions src/buildSummary.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}

0 comments on commit db4f9d4

Please sign in to comment.