Workflow triggers are null if unspecified
This commit is contained in:
parent
c0bd7b0b2b
commit
754f502a84
6 changed files with 45 additions and 14 deletions
15
lib/actions-util.js
generated
15
lib/actions-util.js
generated
|
|
@ -108,7 +108,7 @@ var MissingTriggers;
|
|||
MissingTriggers[MissingTriggers["PULL_REQUEST"] = 2] = "PULL_REQUEST";
|
||||
})(MissingTriggers || (MissingTriggers = {}));
|
||||
exports.ErrCheckoutWrongHead = `Git checkout HEAD^2 is no longer necessary. Please remove this line.`;
|
||||
exports.ErrMismatchedBranches = `Please make sure that any branches in on.pull_request are also in on.push so that CodeQL can establish a baseline.`;
|
||||
exports.ErrMismatchedBranches = `Please make sure that every branch in on.pull_request is also in on.push so that CodeQL can establish a baseline.`;
|
||||
exports.ErrMissingHooks = `Please specify on.push and on.pull_request hooks.`;
|
||||
exports.ErrMissingPushHook = `Please specify an on.push hook so CodeQL can establish a baseline.`;
|
||||
exports.ErrMissingPullRequestHook = `Please specify an on.pull_request hook so CodeQL is run against new pull requests.`;
|
||||
|
|
@ -162,11 +162,16 @@ function validateWorkflow(doc) {
|
|||
errors.push(exports.ErrPathsSpecified);
|
||||
}
|
||||
}
|
||||
if (doc.on.pull_request !== undefined && doc.on.push !== undefined) {
|
||||
if (doc.on.push) {
|
||||
const push = doc.on.push.branches || [];
|
||||
const pull_request = doc.on.pull_request.branches || [];
|
||||
const intersects = pull_request.filter((value) => !push.includes(value));
|
||||
if (intersects.length > 0) {
|
||||
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) {
|
||||
errors.push(exports.ErrMismatchedBranches);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
9
lib/actions-util.test.js
generated
9
lib/actions-util.test.js
generated
|
|
@ -146,6 +146,15 @@ ava_1.default("validateWorkflow() when on.push is mismatched for pull_request",
|
|||
});
|
||||
t.deepEqual(errors, [actionsutil.ErrMismatchedBranches]);
|
||||
});
|
||||
ava_1.default("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]);
|
||||
});
|
||||
ava_1.default("validateWorkflow() when HEAD^2 is checked out", (t) => {
|
||||
const errors = actionsutil.validateWorkflow({
|
||||
on: ["push", "pull_request"],
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -186,6 +186,17 @@ 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"],
|
||||
|
|
|
|||
|
|
@ -116,8 +116,8 @@ interface WorkflowTrigger {
|
|||
}
|
||||
|
||||
interface WorkflowTriggers {
|
||||
push?: WorkflowTrigger;
|
||||
pull_request?: WorkflowTrigger;
|
||||
push?: WorkflowTrigger | null;
|
||||
pull_request?: WorkflowTrigger | null;
|
||||
}
|
||||
|
||||
interface Workflow {
|
||||
|
|
@ -136,7 +136,7 @@ enum MissingTriggers {
|
|||
}
|
||||
|
||||
export const ErrCheckoutWrongHead = `Git checkout HEAD^2 is no longer necessary. Please remove this line.`;
|
||||
export const ErrMismatchedBranches = `Please make sure that any branches in on.pull_request are also in on.push so that CodeQL can establish a baseline.`;
|
||||
export const ErrMismatchedBranches = `Please make sure that every branch in on.pull_request is also in on.push so that CodeQL can establish a baseline.`;
|
||||
export const ErrMissingHooks = `Please specify on.push and on.pull_request hooks.`;
|
||||
export const ErrMissingPushHook = `Please specify an on.push hook so CodeQL can establish a baseline.`;
|
||||
export const ErrMissingPullRequestHook = `Please specify an on.pull_request hook so CodeQL is run against new pull requests.`;
|
||||
|
|
@ -190,13 +190,19 @@ export function validateWorkflow(doc: Workflow): string[] {
|
|||
}
|
||||
}
|
||||
|
||||
if (doc.on.pull_request !== undefined && doc.on.push !== undefined) {
|
||||
if (doc.on.push) {
|
||||
const push = doc.on.push.branches || [];
|
||||
const pull_request = doc.on.pull_request.branches || [];
|
||||
if (doc.on.pull_request) {
|
||||
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) {
|
||||
if (intersects.length > 0) {
|
||||
errors.push(ErrMismatchedBranches);
|
||||
}
|
||||
} else if (push.length > 0) {
|
||||
errors.push(ErrMismatchedBranches);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue