Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67632,29 +67632,37 @@ function run(context) {
console.log("\nREADING WORKFLOW FILES");
workflowFilePaths.forEach((wf) => {
console.log(line);
// A file can be added/modified in one commit of a PR yet deleted by the
// head (e.g. added then removed across commits). getFilesInCommit reports
// it as added/modified from the earlier commit, but the checkout is the
// head ref, so the file is not on disk. Skip it rather than reading it,
// which would throw ENOENT and fail the whole run for a file that no
// longer exists. A workflow deleted outright cannot violate the policy.
if (!fs_1.default.existsSync(wf)) {
console.log("\nSkipping (deleted in this change set): " + wf);
return;
}
Comment on lines +67641 to +67644
let workflow = { filePath: wf, actions: Array() };
workflowFiles.push(workflow);
if (fs_1.default.existsSync(workflow.filePath)) {
console.log("\nReading:" + workflow.filePath);
try {
let yaml = js_yaml_1.default.load(fs_1.default.readFileSync(workflow.filePath, "utf-8"));
let actionStrings = getPropertyValues(yaml, "uses");
actionStrings.forEach((as) => {
workflow.actions.push(new Action(as));
});
console.log("\nReading:" + workflow.filePath);
try {
let yaml = js_yaml_1.default.load(fs_1.default.readFileSync(workflow.filePath, "utf-8"));
let actionStrings = getPropertyValues(yaml, "uses");
actionStrings.forEach((as) => {
workflow.actions.push(new Action(as));
});
}
catch (error) {
if (error instanceof Error) {
core.debug(error.message);
core.setFailed(`Unable to parse workflow file '${workflow.filePath}' - please ensure it's formatted properly.`);
}
catch (error) {
if (error instanceof Error) {
core.debug(error.message);
core.setFailed(`Unable to parse workflow file '${workflow.filePath}' - please ensure it's formatted properly.`);
}
else {
// Handle cases where error is not an Error object
core.debug("An unknown error occurred.");
core.setFailed("An unknown error occurred.");
}
console.log(error);
else {
// Handle cases where error is not an Error object
core.debug("An unknown error occurred.");
core.setFailed("An unknown error occurred.");
}
console.log(error);
}
});
//iterate through all the workflow files found
Expand Down
54 changes: 31 additions & 23 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,33 +207,41 @@ async function run(context: typeof github.context): Promise<void> {
console.log("\nREADING WORKFLOW FILES");
workflowFilePaths.forEach((wf) => {
console.log(line);
// A file can be added/modified in one commit of a PR yet deleted by the
// head (e.g. added then removed across commits). getFilesInCommit reports
// it as added/modified from the earlier commit, but the checkout is the
// head ref, so the file is not on disk. Skip it rather than reading it,
// which would throw ENOENT and fail the whole run for a file that no
// longer exists. A workflow deleted outright cannot violate the policy.
if (!fs.existsSync(wf)) {
console.log("\nSkipping (deleted in this change set): " + wf);
return;
}
Comment on lines +216 to +219
let workflow: Workflow = { filePath: wf, actions: Array<Action>() };
workflowFiles.push(workflow);
if (fs.existsSync(workflow.filePath)) {
console.log("\nReading:" + workflow.filePath);
try {
let yaml: any = yamlParse.load(
fs.readFileSync(workflow.filePath, "utf-8"),
console.log("\nReading:" + workflow.filePath);
try {
let yaml: any = yamlParse.load(
fs.readFileSync(workflow.filePath, "utf-8"),
);
let actionStrings = getPropertyValues(yaml, "uses");

actionStrings.forEach((as) => {
workflow.actions.push(new Action(as));
});
} catch (error: unknown) {
if (error instanceof Error) {
core.debug(error.message);
core.setFailed(
`Unable to parse workflow file '${workflow.filePath}' - please ensure it's formatted properly.`,
);
let actionStrings = getPropertyValues(yaml, "uses");

actionStrings.forEach((as) => {
workflow.actions.push(new Action(as));
});
} catch (error: unknown) {
if (error instanceof Error) {
core.debug(error.message);
core.setFailed(
`Unable to parse workflow file '${workflow.filePath}' - please ensure it's formatted properly.`,
);
} else {
// Handle cases where error is not an Error object
core.debug("An unknown error occurred.");
core.setFailed("An unknown error occurred.");
}
console.log(error);
} else {
// Handle cases where error is not an Error object
core.debug("An unknown error occurred.");
core.setFailed("An unknown error occurred.");
}
}
console.log(error);
}
});

//iterate through all the workflow files found
Expand Down