Skip to content

Commit 9ef389d

Browse files
authored
Merge pull request #25 from Contrast-Security-OSS/patch-file-exists
Update main.ts
2 parents 988a608 + 2cc677d commit 9ef389d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/main.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,29 +209,31 @@ async function run(context: typeof github.context): Promise<void> {
209209
console.log(line);
210210
let workflow: Workflow = { filePath: wf, actions: Array<Action>() };
211211
workflowFiles.push(workflow);
212-
console.log("\nReading:" + workflow.filePath);
213-
try {
214-
let yaml: any = yamlParse.load(
215-
fs.readFileSync(workflow.filePath, "utf-8"),
216-
);
217-
let actionStrings = getPropertyValues(yaml, "uses");
218-
219-
actionStrings.forEach((as) => {
220-
workflow.actions.push(new Action(as));
221-
});
222-
} catch (error: unknown) {
223-
if (error instanceof Error) {
224-
core.debug(error.message);
225-
core.setFailed(
226-
`Unable to parse workflow file '${workflow.filePath}' - please ensure it's formatted properly.`,
212+
if (fs.existsSync(workflow.filePath)) {
213+
console.log("\nReading:" + workflow.filePath);
214+
try {
215+
let yaml: any = yamlParse.load(
216+
fs.readFileSync(workflow.filePath, "utf-8"),
227217
);
228-
} else {
229-
// Handle cases where error is not an Error object
230-
core.debug("An unknown error occurred.");
231-
core.setFailed("An unknown error occurred.");
218+
let actionStrings = getPropertyValues(yaml, "uses");
219+
220+
actionStrings.forEach((as) => {
221+
workflow.actions.push(new Action(as));
222+
});
223+
} catch (error: unknown) {
224+
if (error instanceof Error) {
225+
core.debug(error.message);
226+
core.setFailed(
227+
`Unable to parse workflow file '${workflow.filePath}' - please ensure it's formatted properly.`,
228+
);
229+
} else {
230+
// Handle cases where error is not an Error object
231+
core.debug("An unknown error occurred.");
232+
core.setFailed("An unknown error occurred.");
233+
}
234+
console.log(error);
232235
}
233-
console.log(error);
234-
}
236+
}
235237
});
236238

237239
//iterate through all the workflow files found

0 commit comments

Comments
 (0)