Skip to content

Commit 697ed97

Browse files
committed
Factor out some code in post-init tests
1 parent 2207a72 commit 697ed97

4 files changed

Lines changed: 63 additions & 88 deletions

File tree

lib/init-action-post-helper.test.js

Lines changed: 28 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post-helper.test.js.map

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-action-post-helper.test.ts

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,48 +86,45 @@ test("post: init action with debug mode on", async (t) => {
8686
});
8787

8888
test("uploads failed SARIF run for typical workflow", async (t) => {
89-
const actionsWorkflow: workflow.Workflow = {
90-
name: "CodeQL",
91-
on: {
92-
push: {
93-
branches: ["main"],
94-
},
95-
pull_request: {
96-
branches: ["main"],
89+
const actionsWorkflow = createTestWorkflow([
90+
{
91+
name: "Checkout repository",
92+
uses: "actions/checkout@v3",
93+
},
94+
{
95+
name: "Initialize CodeQL",
96+
uses: "github/codeql-action/init@v2",
97+
with: {
98+
languages: "javascript",
9799
},
98100
},
99-
jobs: {
100-
analyze: {
101-
name: "CodeQL Analysis",
102-
"runs-on": "ubuntu-latest",
103-
steps: [
104-
{
105-
name: "Checkout repository",
106-
uses: "actions/checkout@v3",
107-
},
108-
{
109-
name: "Initialize CodeQL",
110-
uses: "github/codeql-action/init@v2",
111-
with: {
112-
languages: "javascript",
113-
},
114-
},
115-
{
116-
name: "Perform CodeQL Analysis",
117-
uses: "github/codeql-action/analyze@v2",
118-
with: {
119-
category: "my-category",
120-
},
121-
},
122-
],
101+
{
102+
name: "Perform CodeQL Analysis",
103+
uses: "github/codeql-action/analyze@v2",
104+
with: {
105+
category: "my-category",
123106
},
124107
},
125-
};
108+
]);
126109
await testFailedSarifUpload(t, actionsWorkflow, { category: "my-category" });
127110
});
128111

129112
test("uploading failed SARIF run fails when workflow does not reference github/codeql-action", async (t) => {
130-
const actionsWorkflow: workflow.Workflow = {
113+
const actionsWorkflow = createTestWorkflow([
114+
{
115+
name: "Checkout repository",
116+
uses: "actions/checkout@v3",
117+
},
118+
]);
119+
await t.throwsAsync(
120+
async () => await testFailedSarifUpload(t, actionsWorkflow)
121+
);
122+
});
123+
124+
function createTestWorkflow(
125+
steps: workflow.WorkflowJobStep[]
126+
): workflow.Workflow {
127+
return {
131128
name: "CodeQL",
132129
on: {
133130
push: {
@@ -141,19 +138,11 @@ test("uploading failed SARIF run fails when workflow does not reference github/c
141138
analyze: {
142139
name: "CodeQL Analysis",
143140
"runs-on": "ubuntu-latest",
144-
steps: [
145-
{
146-
name: "Checkout repository",
147-
uses: "actions/checkout@v3",
148-
},
149-
],
141+
steps,
150142
},
151143
},
152144
};
153-
await t.throwsAsync(
154-
async () => await testFailedSarifUpload(t, actionsWorkflow)
155-
);
156-
});
145+
}
157146

158147
async function testFailedSarifUpload(
159148
t: ExecutionContext<unknown>,

src/workflow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as yaml from "js-yaml";
77
import * as api from "./api-client";
88
import { getRequiredEnvParam } from "./util";
99

10-
interface WorkflowJobStep {
10+
export interface WorkflowJobStep {
1111
name?: string;
1212
run?: any;
1313
uses?: string;

0 commit comments

Comments
 (0)