Skip to content

Commit

Permalink
Merge pull request #47 from matlab-actions/bash_issue_fix
Browse files Browse the repository at this point in the history
Bash issue fix
  • Loading branch information
nbhoski authored Jul 22, 2024
2 parents 4b4b57f + 4b9efb5 commit eaee4e4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/bat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,19 @@ jobs:
run: |
grep "::group::deploy" console.log
grep "::error::error task failed" console.log
rm console.log
- name: Run build with invalid task
continue-on-error: true
uses: ./
with:
tasks: badTask
build-options: -continueOnFailure
startup-options: -logfile console.log

- name: Verify summary exception for invalid task
run: |
set -e
! grep "while reading the build summary file:" console.log
! grep "trying to delete the build summary" console.log
rm console.log
35 changes: 20 additions & 15 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, unlinkSync} from 'fs';
import { readFileSync, unlinkSync, existsSync} from 'fs';

export interface Task {
name: string;
Expand All @@ -13,7 +13,7 @@ export interface Task {


export function getBuildSummaryTable(tasks: Task[]): string[][] {
const header: string[] = ['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)'];
const header: string[] = ['MATLAB Build Task', 'Status', 'Description', 'Duration (hh:mm:ss)'];
let taskSummaryTableRows: string[][] = [header];

if(!Array.isArray(tasks)){
Expand Down Expand Up @@ -43,31 +43,36 @@ export function processAndDisplayBuildSummary() {

const filePath: string = join(runnerTemp, `buildSummary${runId}.json`);
let taskSummaryTableRows;
try {
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 {
if (existsSync(filePath)) {
try {
unlinkSync(filePath);
const data = JSON.parse(readFileSync(filePath, { encoding: 'utf8' }));
taskSummaryTableRows = getBuildSummaryTable(data);
} catch (e) {
console.error(`An error occurred while trying to delete the build summary file ${filePath}:`, 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);
} else {
core.info(`Build summary data not created.`);
}
writeSummary(taskSummaryTableRows);

}

export function getTaskDetails(tasks: Task): string[] {
let taskDetails: string[] = [];
taskDetails.push(tasks.name);
if (tasks.failed) {
taskDetails.push('πŸ”΄ FAILED');
taskDetails.push('πŸ”΄ Failed');
} else if (tasks.skipped) {
taskDetails.push('πŸ”΅ SKIPPED');
taskDetails.push('πŸ”΅ Skipped');
} else {
taskDetails.push('🟒 SUCCESS');
taskDetails.push('🟒 Success');
}
taskDetails.push(tasks.description);
taskDetails.push(tasks.duration);
Expand Down
8 changes: 4 additions & 4 deletions src/buildSummary.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('summaryGeneration', () => {
];

const expectedTable = [
['MATLAB Build Task', 'Status', 'Description', 'Duration (HH:MM:SS)'],
['Test Task', 'πŸ”΄ FAILED', 'A test task', '00:00:10'],
['MATLAB Build Task', 'Status', 'Description', 'Duration (hh:mm:ss)'],
['Test Task', 'πŸ”΄ Failed', 'A test task', '00:00:10'],
];

const table = buildSummary.getBuildSummaryTable(mockTasks);
Expand All @@ -29,8 +29,8 @@ describe('summaryGeneration', () => {

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'],
['MATLAB Build Task', 'Status', 'Description', 'Duration (hh:mm:ss)'],
['Test Task', 'πŸ”΄ Failed', 'A test task', '00:00:10'],
];

buildSummary.writeSummary(mockTableRows);
Expand Down

0 comments on commit eaee4e4

Please sign in to comment.