-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Summary table under summary section (#33)
* Added Summary plugin * Testing temp folder generation * Testing temp folder generation * Testing temp folder generation * Testing temp folder generation * Testing temp folder generation * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Testing JSON parse * Refactored the JSON strategy * Refactored the JSON strategy * Changed temp foldr for summary json * Added unicode for status * Handdled failure scenarios * Refactored mathods for good readability * Refactored mathods for good readability * Refactored mathods for good readability * Refactored mathods for good readability * Added tests * Added tests * Added tests * Added tests * Added tests * Added tests * Added tests * Added tests * Added tests for json read * Added tests for json read * Added tests for json read * Updated tessts * Updated tessts * Changed the tabe heading * Updated as per review comments * Updated as per review comments * Updated as per review comments * Updated as per review comments * Handdled multiple try catch issue * Handdled multiple try catch issue * Handdled multiple try catch issue * Updated build plugin error message * Changed indenattion * Handdled errors close to the functions * Handdled errors close to the functions * Handdled errors close to the functions * Handdled errors close to the functions * Updating as per review comments * Updating as per review comments * Updating as per review comments
- Loading branch information
Showing
5 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
classdef BuildSummaryPlugin < matlab.buildtool.plugins.BuildRunnerPlugin | ||
|
||
% Copyright 2024 The MathWorks, Inc. | ||
|
||
methods (Access=protected) | ||
|
||
function runTaskGraph(plugin, pluginData) | ||
[email protected](plugin, pluginData); | ||
[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); | ||
else | ||
closeFile = onCleanup(@()fclose(fID)); | ||
taskDetails = struct(); | ||
for idx = 1:numel(pluginData.TaskResults) | ||
taskDetails(idx).name = pluginData.TaskResults(idx).Name; | ||
taskDetails(idx).description = pluginData.TaskGraph.Tasks(idx).Description; | ||
taskDetails(idx).failed = pluginData.TaskResults(idx).Failed; | ||
taskDetails(idx).skipped = pluginData.TaskResults(idx).Skipped; | ||
taskDetails(idx).duration = string(pluginData.TaskResults(idx).Duration); | ||
end | ||
s = jsonencode(taskDetails); | ||
fprintf(fID, "%s",s); | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024 The MathWorks, Inc. | ||
import * as core from "@actions/core"; | ||
import { join } from 'path'; | ||
import { readFileSync } from 'fs'; | ||
|
||
export interface Task { | ||
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; | ||
} | ||
|
||
export function writeSummary(taskSummaryTableRows: string[][]) { | ||
try { | ||
core.summary | ||
.addTable(taskSummaryTableRows) | ||
.write(); | ||
} catch (e) { | ||
console.error('An error occurred while adding the build results table to the summary:', e); | ||
} | ||
} | ||
|
||
export function processAndDisplayBuildSummary() { | ||
const runId = process.env.GITHUB_RUN_ID || ''; | ||
const runnerTemp = process.env.RUNNER_TEMP || ''; | ||
|
||
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; | ||
} | ||
writeSummary(taskSummaryTableRows); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 The MathWorks, Inc. | ||
|
||
import * as buildSummary from './buildSummary'; | ||
import * as core from '@actions/core'; | ||
|
||
|
||
jest.mock('@actions/core', () => ({ | ||
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' } | ||
]; | ||
|
||
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); | ||
|
||
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'], | ||
]; | ||
|
||
buildSummary.writeSummary(mockTableRows); | ||
|
||
expect(core.summary.addTable).toHaveBeenCalledTimes(1); | ||
expect(core.summary.addTable).toHaveBeenCalledWith(mockTableRows); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters