Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only report the first CheckoutWrongHead lint error
Simon Engledew committed Dec 21, 2020

Unverified

No user is associated with the committer email.
1 parent dc999c5 commit e89a24b
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions lib/actions-util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js.map

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/actions-util.test.ts
@@ -432,3 +432,27 @@ on:

t.deepEqual(errors, []);
});

test("validateWorkflow() should only report the first CheckoutWrongHead", (t) => {
const errors = actionsutil.validateWorkflow(
yaml.safeLoad(`
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
jobs:
test:
steps:
- run: "git checkout HEAD^2"
- run: "git checkout HEAD^2"
- run: "git checkout HEAD^2"
- run: "git checkout HEAD^2"
- run: "git checkout HEAD^2"
`)
);

t.deepEqual(errors, [actionsutil.WorkflowErrors.CheckoutWrongHead]);
});
3 changes: 2 additions & 1 deletion src/actions-util.ts
@@ -212,7 +212,7 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
const errors: CodedError[] = [];

// .jobs[key].steps[].run
for (const job of Object.values(doc?.jobs || {})) {
outer: for (const job of Object.values(doc?.jobs || {})) {
if (Array.isArray(job?.steps)) {
for (const step of job?.steps) {
// this was advice that we used to give in the README
@@ -222,6 +222,7 @@ export function validateWorkflow(doc: Workflow): CodedError[] {
// and avoid some race conditions
if (step?.run === "git checkout HEAD^2") {
errors.push(WorkflowErrors.CheckoutWrongHead);
break outer;
}
}
}

0 comments on commit e89a24b

Please sign in to comment.