Only report the first CheckoutWrongHead lint error

This commit is contained in:
Simon Engledew 2020-12-21 10:55:55 +00:00
parent dc999c55d0
commit e89a24b8cb
No known key found for this signature in database
GPG key ID: 84302E7B02FE8BCE
6 changed files with 50 additions and 4 deletions

View file

@ -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]);
});

View file

@ -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;
}
}
}