Skip to content

Commit

Permalink
Only report the first CheckoutWrongHead lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Engledew committed Dec 21, 2020
1 parent dc999c5 commit e89a24b
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit e89a24b

Please sign in to comment.