Skip to content

Commit 5060176

Browse files
committed
Also skip workflow validation for dynamic workflows
1 parent 06fbd89 commit 5060176

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

‎lib/init-action.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/init.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from "path";
44
import test, { ExecutionContext } from "ava";
55
import * as sinon from "sinon";
66

7+
import * as actionsUtil from "./actions-util";
78
import { createStubCodeQL } from "./codeql";
89
import { EnvVar } from "./environment";
910
import {
@@ -28,6 +29,7 @@ test("checkWorkflow - validates workflow if `SKIP_WORKFLOW_VALIDATION` is not se
2829
const messages: LoggedMessage[] = [];
2930
const codeql = createStubCodeQL({});
3031

32+
sinon.stub(actionsUtil, "isDynamicWorkflow").returns(false);
3133
const validateWorkflow = sinon.stub(workflow, "validateWorkflow");
3234
validateWorkflow.resolves(undefined);
3335

@@ -46,6 +48,7 @@ test("checkWorkflow - logs problems with workflow validation", async (t) => {
4648
const messages: LoggedMessage[] = [];
4749
const codeql = createStubCodeQL({});
4850

51+
sinon.stub(actionsUtil, "isDynamicWorkflow").returns(false);
4952
const validateWorkflow = sinon.stub(workflow, "validateWorkflow");
5053
validateWorkflow.resolves("problem");
5154

@@ -66,6 +69,7 @@ test("checkWorkflow - skips validation if `SKIP_WORKFLOW_VALIDATION` is `true`",
6669
const messages: LoggedMessage[] = [];
6770
const codeql = createStubCodeQL({});
6871

72+
sinon.stub(actionsUtil, "isDynamicWorkflow").returns(false);
6973
const validateWorkflow = sinon.stub(workflow, "validateWorkflow");
7074

7175
await checkWorkflow(getRecordingLogger(messages), codeql);
@@ -77,6 +81,25 @@ test("checkWorkflow - skips validation if `SKIP_WORKFLOW_VALIDATION` is `true`",
7781
t.is(messages.length, 0);
7882
});
7983

84+
test("checkWorkflow - skips validation for `dynamic` workflows", async (t) => {
85+
const messages: LoggedMessage[] = [];
86+
const codeql = createStubCodeQL({});
87+
88+
const isDynamicWorkflow = sinon
89+
.stub(actionsUtil, "isDynamicWorkflow")
90+
.returns(true);
91+
const validateWorkflow = sinon.stub(workflow, "validateWorkflow");
92+
93+
await checkWorkflow(getRecordingLogger(messages), codeql);
94+
95+
t.assert(isDynamicWorkflow.calledOnce);
96+
t.assert(
97+
validateWorkflow.notCalled,
98+
"`checkWorkflow` called `validateWorkflow` unexpectedly",
99+
);
100+
t.is(messages.length, 0);
101+
});
102+
80103
test("cleanupDatabaseClusterDirectory cleans up where possible", async (t) => {
81104
await withTmpDir(async (tmpDir: string) => {
82105
const dbLocation = path.resolve(tmpDir, "dbs");

‎src/init.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import * as toolrunner from "@actions/exec/lib/toolrunner";
66
import * as io from "@actions/io";
77
import * as yaml from "js-yaml";
88

9-
import { getOptionalInput, isSelfHostedRunner } from "./actions-util";
9+
import {
10+
getOptionalInput,
11+
isDynamicWorkflow,
12+
isSelfHostedRunner,
13+
} from "./actions-util";
1014
import { GitHubApiDetails } from "./api-client";
1115
import { CodeQL, setupCodeQL } from "./codeql";
1216
import * as configUtils from "./config-utils";
@@ -27,8 +31,12 @@ import { validateWorkflow } from "./workflow";
2731
* @param codeql The CodeQL instance.
2832
*/
2933
export async function checkWorkflow(logger: Logger, codeql: CodeQL) {
30-
// Check the workflow for problems, unless `SKIP_WORKFLOW_VALIDATION` is `true`.
31-
if (process.env[EnvVar.SKIP_WORKFLOW_VALIDATION] !== "true") {
34+
// Check the workflow for problems, unless `SKIP_WORKFLOW_VALIDATION` is `true`
35+
// or the workflow trigger is `dynamic`.
36+
if (
37+
!isDynamicWorkflow() &&
38+
process.env[EnvVar.SKIP_WORKFLOW_VALIDATION] !== "true"
39+
) {
3240
core.startGroup("Validating workflow");
3341
const validateWorkflowResult = await validateWorkflow(codeql, logger);
3442
if (validateWorkflowResult === undefined) {

0 commit comments

Comments
 (0)