diff --git a/.github/workflows/bat.yml b/.github/workflows/bat.yml index 8518446..a823f60 100644 --- a/.github/workflows/bat.yml +++ b/.github/workflows/bat.yml @@ -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 \ No newline at end of file diff --git a/src/buildSummary.ts b/src/buildSummary.ts index 2a05215..ac05a87 100644 --- a/src/buildSummary.ts +++ b/src/buildSummary.ts @@ -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; @@ -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)){ @@ -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); diff --git a/src/buildSummary.unit.test.ts b/src/buildSummary.unit.test.ts index 0586f9f..9b8d1ee 100644 --- a/src/buildSummary.unit.test.ts +++ b/src/buildSummary.unit.test.ts @@ -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); @@ -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);