Do not fail if the workflow has been deleted
This commit is contained in:
parent
754f502a84
commit
6df1fc5e38
9 changed files with 63 additions and 65 deletions
33
lib/actions-util.js
generated
33
lib/actions-util.js
generated
|
|
@ -162,16 +162,11 @@ function validateWorkflow(doc) {
|
|||
errors.push(exports.ErrPathsSpecified);
|
||||
}
|
||||
}
|
||||
if (doc.on.push) {
|
||||
if (doc.on.push && doc.on.pull_request) {
|
||||
const push = doc.on.push.branches || [];
|
||||
if (doc.on.pull_request) {
|
||||
const pull_request = doc.on.pull_request.branches || [];
|
||||
const intersects = pull_request.filter((value) => !push.includes(value));
|
||||
if (intersects.length > 0) {
|
||||
errors.push(exports.ErrMismatchedBranches);
|
||||
}
|
||||
}
|
||||
else if (push.length > 0) {
|
||||
const pull_request = doc.on.pull_request.branches || [];
|
||||
const intersects = pull_request.filter((value) => !push.includes(value));
|
||||
if (intersects.length > 0) {
|
||||
errors.push(exports.ErrMismatchedBranches);
|
||||
}
|
||||
}
|
||||
|
|
@ -190,10 +185,28 @@ function validateWorkflow(doc) {
|
|||
return errors;
|
||||
}
|
||||
exports.validateWorkflow = validateWorkflow;
|
||||
async function getWorkflowError() {
|
||||
const workflow = await getWorkflow();
|
||||
if (workflow === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
const workflowErrors = validateWorkflow(workflow);
|
||||
if (workflowErrors.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return `${workflowErrors.length} issue${workflowErrors.length === 1 ? " was" : "s were"} detected with this workflow: ${workflowErrors.join(", ")}`;
|
||||
}
|
||||
exports.getWorkflowError = getWorkflowError;
|
||||
async function getWorkflow() {
|
||||
const relativePath = await getWorkflowPath();
|
||||
const absolutePath = path.join(getRequiredEnvParam("GITHUB_WORKSPACE"), relativePath);
|
||||
return yaml.safeLoad(fs.readFileSync(absolutePath, "utf-8"));
|
||||
try {
|
||||
return yaml.safeLoad(fs.readFileSync(absolutePath, "utf-8"));
|
||||
}
|
||||
catch (e) {
|
||||
core.warning(`Could not read workflow: ${e.toString()}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
exports.getWorkflow = getWorkflow;
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue