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
|
|
@ -186,17 +186,6 @@ test("validateWorkflow() when on.push is mismatched for pull_request", (t) => {
|
|||
t.deepEqual(errors, [actionsutil.ErrMismatchedBranches]);
|
||||
});
|
||||
|
||||
test("validateWorkflow() when on.pull_request for every branch but push specifies branches", (t) => {
|
||||
const errors = actionsutil.validateWorkflow({
|
||||
on: {
|
||||
push: { branches: ["main"] },
|
||||
pull_request: null,
|
||||
},
|
||||
});
|
||||
|
||||
t.deepEqual(errors, [actionsutil.ErrMismatchedBranches]);
|
||||
});
|
||||
|
||||
test("validateWorkflow() when HEAD^2 is checked out", (t) => {
|
||||
const errors = actionsutil.validateWorkflow({
|
||||
on: ["push", "pull_request"],
|
||||
|
|
|
|||
|
|
@ -190,19 +190,13 @@ export function validateWorkflow(doc: Workflow): string[] {
|
|||
}
|
||||
}
|
||||
|
||||
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 pull_request = doc.on.pull_request.branches || [];
|
||||
|
||||
const intersects = pull_request.filter(
|
||||
(value) => !push.includes(value)
|
||||
);
|
||||
const intersects = pull_request.filter((value) => !push.includes(value));
|
||||
|
||||
if (intersects.length > 0) {
|
||||
errors.push(ErrMismatchedBranches);
|
||||
}
|
||||
} else if (push.length > 0) {
|
||||
if (intersects.length > 0) {
|
||||
errors.push(ErrMismatchedBranches);
|
||||
}
|
||||
}
|
||||
|
|
@ -223,14 +217,37 @@ export function validateWorkflow(doc: Workflow): string[] {
|
|||
return errors;
|
||||
}
|
||||
|
||||
export async function getWorkflow(): Promise<Workflow> {
|
||||
export async function getWorkflowError(): Promise<string | undefined> {
|
||||
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(", ")}`;
|
||||
}
|
||||
|
||||
export async function getWorkflow(): Promise<Workflow | undefined> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -96,19 +96,10 @@ async function run() {
|
|||
try {
|
||||
actionsUtil.prepareLocalRunEnvironment();
|
||||
|
||||
const workflowErrors = actionsUtil.validateWorkflow(
|
||||
await actionsUtil.getWorkflow()
|
||||
);
|
||||
const workflowError = await actionsUtil.getWorkflowError();
|
||||
|
||||
const workflowErrorMessage =
|
||||
workflowErrors.length > 0
|
||||
? `${workflowErrors.length} issue${
|
||||
workflowErrors.length === 1 ? " was" : "s were"
|
||||
} detected with this workflow: ${workflowErrors.join(", ")}`
|
||||
: undefined;
|
||||
|
||||
if (workflowErrorMessage !== undefined) {
|
||||
core.warning(workflowErrorMessage);
|
||||
if (workflowError !== undefined) {
|
||||
core.warning(workflowError);
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
@ -117,7 +108,7 @@ async function run() {
|
|||
"init",
|
||||
"starting",
|
||||
startedAt,
|
||||
workflowErrorMessage
|
||||
workflowError
|
||||
)
|
||||
))
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue