First iteration on feedback

This commit is contained in:
Simon Engledew 2020-12-01 20:08:41 +00:00
parent 56b1ead679
commit 4d862616ce
No known key found for this signature in database
GPG key ID: 84302E7B02FE8BCE
7 changed files with 50 additions and 41 deletions

10
lib/actions-util.js generated
View file

@ -120,7 +120,7 @@ function considerToken(a, b) {
return { advance: a === b, consume: a === b };
}
}
function tokensMatch(tokensA, tokensB) {
function tokensAreSuperset(tokensA, tokensB) {
let indexA = 0;
let indexB = 0;
let advance;
@ -146,12 +146,12 @@ function tokensMatch(tokensA, tokensB) {
}
return false;
}
function patternsOverlap(patternA, patternB) {
function patternIsSuperset(patternA, patternB) {
const tokensA = tokenize(patternA);
const tokensB = tokenize(patternB);
return tokensMatch(tokensA, tokensB) && tokensMatch(tokensA.reverse(), tokensB.reverse());
return tokensAreSuperset(tokensA, tokensB) && tokensAreSuperset(tokensA.reverse(), tokensB.reverse());
}
exports.patternsOverlap = patternsOverlap;
exports.patternIsSuperset = patternIsSuperset;
function branchesToArray(branches) {
if (typeof branches === "string") {
return [branches];
@ -248,7 +248,7 @@ function validateWorkflow(doc) {
if (push !== "**") {
const pull_request = branchesToArray((_g = doc.on.pull_request) === null || _g === void 0 ? void 0 : _g.branches);
if (pull_request !== "**") {
const difference = pull_request.filter((value) => !push.some((o) => patternsOverlap(o, value)));
const difference = pull_request.filter((value) => !push.some((o) => patternIsSuperset(o, value)));
if (difference.length > 0) {
// there are branches in pull_request that may not have a baseline
// because we are not building them on push

File diff suppressed because one or more lines are too long

View file

@ -213,19 +213,21 @@ ava_1.default("formatWorkflowCause()", (t) => {
t.deepEqual(message, "CheckoutWrongHead,PathsSpecified");
t.deepEqual(actionsutil.formatWorkflowCause([]), undefined);
});
ava_1.default("patternsOverlap()", (t) => {
t.false(actionsutil.patternsOverlap("main-*", "main"));
t.true(actionsutil.patternsOverlap("*", "*"));
t.true(actionsutil.patternsOverlap("*", "main-*"));
t.false(actionsutil.patternsOverlap("main-*", "*"));
t.false(actionsutil.patternsOverlap("main-*", "main"));
t.true(actionsutil.patternsOverlap("main", "main"));
t.false(actionsutil.patternsOverlap("*", "feature/*"));
t.true(actionsutil.patternsOverlap("**", "feature/*"));
t.false(actionsutil.patternsOverlap("feature-*", "**"));
t.false(actionsutil.patternsOverlap("a/**/c", "a/**/d"));
t.false(actionsutil.patternsOverlap("a/**/c", "a/**"));
t.true(actionsutil.patternsOverlap("/robin/*/release/*", "/robin/moose/release/goose"));
t.false(actionsutil.patternsOverlap("/robin/moose/release/goose", "/robin/*/release/*"));
ava_1.default("patternIsSuperset()", (t) => {
t.false(actionsutil.patternIsSuperset("main-*", "main"));
t.true(actionsutil.patternIsSuperset("*", "*"));
t.true(actionsutil.patternIsSuperset("*", "main-*"));
t.false(actionsutil.patternIsSuperset("main-*", "*"));
t.false(actionsutil.patternIsSuperset("main-*", "main"));
t.true(actionsutil.patternIsSuperset("main", "main"));
t.false(actionsutil.patternIsSuperset("*", "feature/*"));
t.true(actionsutil.patternIsSuperset("**", "feature/*"));
t.false(actionsutil.patternIsSuperset("feature-*", "**"));
t.false(actionsutil.patternIsSuperset("a/**/c", "a/**/d"));
t.false(actionsutil.patternIsSuperset("a/**/c", "a/**"));
t.true(actionsutil.patternIsSuperset("a/**/c", "a/main-**/c"));
t.false(actionsutil.patternIsSuperset("a/main-**/c", "a/**/c"));
t.true(actionsutil.patternIsSuperset("/robin/*/release/*", "/robin/moose/release/goose"));
t.false(actionsutil.patternIsSuperset("/robin/moose/release/goose", "/robin/*/release/*"));
});
//# sourceMappingURL=actions-util.test.js.map

File diff suppressed because one or more lines are too long

View file

@ -269,26 +269,28 @@ test("formatWorkflowCause()", (t) => {
t.deepEqual(actionsutil.formatWorkflowCause([]), undefined);
});
test("patternsOverlap()", (t) => {
t.false(actionsutil.patternsOverlap("main-*", "main"));
t.true(actionsutil.patternsOverlap("*", "*"));
t.true(actionsutil.patternsOverlap("*", "main-*"));
t.false(actionsutil.patternsOverlap("main-*", "*"));
t.false(actionsutil.patternsOverlap("main-*", "main"));
t.true(actionsutil.patternsOverlap("main", "main"));
t.false(actionsutil.patternsOverlap("*", "feature/*"));
t.true(actionsutil.patternsOverlap("**", "feature/*"));
t.false(actionsutil.patternsOverlap("feature-*", "**"));
t.false(actionsutil.patternsOverlap("a/**/c", "a/**/d"));
t.false(actionsutil.patternsOverlap("a/**/c", "a/**"));
test("patternIsSuperset()", (t) => {
t.false(actionsutil.patternIsSuperset("main-*", "main"));
t.true(actionsutil.patternIsSuperset("*", "*"));
t.true(actionsutil.patternIsSuperset("*", "main-*"));
t.false(actionsutil.patternIsSuperset("main-*", "*"));
t.false(actionsutil.patternIsSuperset("main-*", "main"));
t.true(actionsutil.patternIsSuperset("main", "main"));
t.false(actionsutil.patternIsSuperset("*", "feature/*"));
t.true(actionsutil.patternIsSuperset("**", "feature/*"));
t.false(actionsutil.patternIsSuperset("feature-*", "**"));
t.false(actionsutil.patternIsSuperset("a/**/c", "a/**/d"));
t.false(actionsutil.patternIsSuperset("a/**/c", "a/**"));
t.true(actionsutil.patternIsSuperset("a/**/c", "a/main-**/c"));
t.false(actionsutil.patternIsSuperset("a/main-**/c", "a/**/c"));
t.true(
actionsutil.patternsOverlap(
actionsutil.patternIsSuperset(
"/robin/*/release/*",
"/robin/moose/release/goose"
)
);
t.false(
actionsutil.patternsOverlap(
actionsutil.patternIsSuperset(
"/robin/moose/release/goose",
"/robin/*/release/*"
)

View file

@ -159,7 +159,7 @@ function considerToken(
}
}
function tokensMatch(tokensA: string[], tokensB: string[]) {
function tokensAreSuperset(tokensA: string[], tokensB: string[]) {
let indexA = 0;
let indexB = 0;
@ -192,11 +192,11 @@ function tokensMatch(tokensA: string[], tokensB: string[]) {
return false;
}
export function patternsOverlap(patternA: string, patternB: string): boolean {
export function patternIsSuperset(patternA: string, patternB: string): boolean {
const tokensA = tokenize(patternA);
const tokensB = tokenize(patternB);
return tokensMatch(tokensA, tokensB) && tokensMatch(tokensA.reverse(), tokensB.reverse());
return tokensAreSuperset(tokensA, tokensB) && tokensAreSuperset(tokensA.reverse(), tokensB.reverse());
}
function branchesToArray(branches?: string | null | string[]): string[] | "**" {
@ -306,7 +306,7 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
if (pull_request !== "**") {
const difference = pull_request.filter(
(value) => !push.some((o) => patternsOverlap(o, value))
(value) => !push.some((o) => patternIsSuperset(o, value))
);
if (difference.length > 0) {
// there are branches in pull_request that may not have a baseline

View file

@ -98,8 +98,13 @@ async function run() {
const workflowErrors = await actionsUtil.getWorkflowErrors();
if (workflowErrors.filter(o => o.code !== 'LintFailed').length > 0) {
core.warning(actionsUtil.formatWorkflowErrors(workflowErrors));
// we do not want to worry users if linting is failing
// but we do want to send a status report containing this error code
// below
const userWorkflowErrors = workflowErrors.filter(o => o.code !== 'LintFailed');
if (userWorkflowErrors.length > 0) {
core.warning(actionsUtil.formatWorkflowErrors(userWorkflowErrors));
}
if (