Skip to content

Commit

Permalink
Changed indenattion
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed Jul 1, 2024
1 parent 510af9b commit 2c6b789
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 65 deletions.
2 changes: 1 addition & 1 deletion plugins/+ciplugins/+github/BuildSummaryPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

function runTaskGraph(plugin, pluginData)
[email protected](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);
Expand Down
82 changes: 41 additions & 41 deletions src/buildSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

46 changes: 23 additions & 23 deletions src/buildSummary.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 2c6b789

Please sign in to comment.