Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only check the steps of the job currently being run
Simon Engledew committed Jan 4, 2021

Unverified

No user is associated with the committer email.
1 parent e89a24b commit 1511db3
Showing 6 changed files with 37 additions and 16 deletions.
12 changes: 7 additions & 5 deletions 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.

10 changes: 8 additions & 2 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.

12 changes: 10 additions & 2 deletions src/actions-util.test.ts
@@ -336,6 +336,8 @@ test("validateWorkflow() when on.pull_request for mismatched wildcard branches",
});

test("validateWorkflow() when HEAD^2 is checked out", (t) => {
process.env.GITHUB_JOB = "test";

const errors = actionsutil.validateWorkflow({
on: ["push", "pull_request"],
jobs: { test: { steps: [{ run: "git checkout HEAD^2" }] } },
@@ -434,6 +436,8 @@ on:
});

test("validateWorkflow() should only report the first CheckoutWrongHead", (t) => {
process.env.GITHUB_JOB = "test";

const errors = actionsutil.validateWorkflow(
yaml.safeLoad(`
name: "CodeQL"
@@ -447,9 +451,13 @@ jobs:
test:
steps:
- run: "git checkout HEAD^2"
test2:
steps:
- run: "git checkout HEAD^2"
- run: "git checkout HEAD^2"
- run: "git checkout HEAD^2"
test3:
steps:
- run: "git checkout HEAD^2"
`)
);
15 changes: 10 additions & 5 deletions src/actions-util.ts
@@ -211,18 +211,23 @@ export const WorkflowErrors = toCodedErrors({
export function validateWorkflow(doc: Workflow): CodedError[] {
const errors: CodedError[] = [];

// .jobs[key].steps[].run
outer: for (const job of Object.values(doc?.jobs || {})) {
if (Array.isArray(job?.steps)) {
for (const step of job?.steps) {
const jobName = process.env.GITHUB_JOB;

if (jobName) {
const job = doc?.jobs?.[jobName];

const steps = job?.steps;

if (Array.isArray(steps)) {
for (const step of steps) {
// this was advice that we used to give in the README
// we actually want to run the analysis on the merge commit
// to produce results that are more inline with expectations
// (i.e: this is what will happen if you merge this PR)
// and avoid some race conditions
if (step?.run === "git checkout HEAD^2") {
errors.push(WorkflowErrors.CheckoutWrongHead);
break outer;
break;
}
}
}

0 comments on commit 1511db3

Please sign in to comment.