Skip to content

Commit

Permalink
Fixed issues #40 & #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed Jul 18, 2024
1 parent 4b4b57f commit 2cd45b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/bat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,20 @@ 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 "Build summary not created" console.log
! grep "while reading the build summary file:" console.log
! grep "trying to delete the build summary" console.log
rm console.log
37 changes: 26 additions & 11 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, accessSync} from 'fs';

export interface Task {
name: string;
Expand Down Expand Up @@ -43,20 +43,26 @@ 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 (checkFileExists(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 file ${filePath} does not exist.`);
}
writeSummary(taskSummaryTableRows);

}

export function getTaskDetails(tasks: Task): string[] {
Expand All @@ -80,3 +86,12 @@ export function getTaskSummaryRows(task: Task, taskSummaryTableRows: string[][])
taskSummaryTableRows.push(taskDetails);
return taskSummaryTableRows;
}

function checkFileExists(filePath: string): boolean {
try {
accessSync(filePath);
return true;
} catch (err) {
return false;
}
}

0 comments on commit 2cd45b7

Please sign in to comment.