Skip to content

Commit bbef5ff

Browse files
authored
Merge pull request #3904 from github/mbg/esbuild/split-follow-up
Address review comments for #3899
2 parents 7187b6e + 064674d commit bbef5ff

4 files changed

Lines changed: 149 additions & 175 deletions

File tree

build.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const onEndPlugin = {
6666
const SHARED_ENTRYPOINT = "entry-points";
6767

6868
/**
69-
* This plugin finds all source files that contain action entry points.
70-
* It then generates the virtual `entry-points` module which imports all identifies files,
69+
* This plugin finds all source files that contain Action entry points.
70+
* It then generates the virtual `entry-points` module which imports all identified files,
7171
* and re-exports their `runWrapper` functions with suitable aliases.
7272
* A tiny stub file is emitted for each Action entrypoint. Each stub imports the shared bundle
7373
* and calls the respective entry point.
@@ -83,7 +83,7 @@ const entryPointsPlugin = {
8383
const toPascal = (s) =>
8484
s.replace(/(^|-)([a-z0-9])/gi, (_, __, c) => c.toUpperCase());
8585

86-
// Find the source files containing action entry points.
86+
// Find the source files containing Action entry points.
8787
build.onStart(() => {
8888
const actionFiles = globSync("src/*-action{,-post}.ts");
8989
for (const actionFile of actionFiles) {
@@ -112,7 +112,7 @@ const entryPointsPlugin = {
112112
return { path: SHARED_ENTRYPOINT, namespace };
113113
});
114114

115-
// Generate the virtual `entry-points` file based on the actions we discovered.
115+
// Generate the virtual `entry-points` file based on the Actions we discovered.
116116
// Restrict using the namespace. The path filter does not need to discriminate any further.
117117
build.onLoad({ filter: /.*/, namespace }, async () => {
118118
const wrapperTemplatePath = "entry-wrapper.js.tpl";
@@ -127,7 +127,7 @@ const entryPointsPlugin = {
127127
const imports = actionsSorted
128128
.map(
129129
(action) =>
130-
`import * as ${action.pascalCaseName} from "./src/${basename(action.path)}"`,
130+
`import * as ${action.pascalCaseName} from "./src/${basename(action.path)}";`,
131131
)
132132
.join("\n");
133133
const wrappers = actionsSorted
@@ -143,7 +143,7 @@ const entryPointsPlugin = {
143143
};
144144
});
145145

146-
// Emit entry point stubs for each action using the entry template.
146+
// Emit entry point stubs for each Action using the entry template.
147147
build.onEnd(async (result) => {
148148
// Read the entry point template.
149149
const templatePath = "action-entry.js.tpl";
@@ -152,7 +152,7 @@ const entryPointsPlugin = {
152152
const makeHeader = (sourceFile) =>
153153
`// Automatically generated from '${templatePath}' for 'src/${basename(sourceFile)}'.\n\n`;
154154

155-
// Write entry point stubs for each action.
155+
// Write entry point stubs for each Action.
156156
for (const action of actions) {
157157
await writeFile(
158158
join(

src/analyze-action-env.test.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/analyze-action-input.test.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/analyze-action.test.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import test from "ava";
2+
import * as sinon from "sinon";
3+
4+
import * as actionsUtil from "./actions-util";
5+
import * as analyze from "./analyze";
6+
import { runWrapper } from "./analyze-action";
7+
import * as api from "./api-client";
8+
import * as configUtils from "./config-utils";
9+
import * as gitUtils from "./git-utils";
10+
import * as statusReport from "./status-report";
11+
import {
12+
setupTests,
13+
setupActionsVars,
14+
mockFeatureFlagApiEndpoint,
15+
} from "./testing-utils";
16+
import * as util from "./util";
17+
18+
setupTests(test);
19+
20+
test.serial(
21+
"analyze action with RAM & threads from environment variables",
22+
async (t) => {
23+
// This test frequently times out on Windows with the default timeout, so we bump
24+
// it a bit to 20s.
25+
t.timeout(1000 * 20);
26+
await util.withTmpDir(async (tmpDir) => {
27+
setupActionsVars(tmpDir, tmpDir);
28+
sinon
29+
.stub(statusReport, "createStatusReportBase")
30+
.resolves({} as statusReport.StatusReportBase);
31+
sinon.stub(statusReport, "sendStatusReport").resolves();
32+
sinon.stub(gitUtils, "isAnalyzingDefaultBranch").resolves(true);
33+
34+
const gitHubVersion: util.GitHubVersion = {
35+
type: util.GitHubVariant.DOTCOM,
36+
};
37+
sinon.stub(configUtils, "getConfig").resolves({
38+
gitHubVersion,
39+
augmentationProperties: {},
40+
languages: [],
41+
packs: [],
42+
trapCaches: {},
43+
} as unknown as configUtils.Config);
44+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
45+
requiredInputStub.withArgs("token").returns("fake-token");
46+
requiredInputStub.withArgs("upload-database").returns("false");
47+
requiredInputStub.withArgs("output").returns("out");
48+
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
49+
optionalInputStub.withArgs("expect-error").returns("false");
50+
sinon.stub(api, "getGitHubVersion").resolves(gitHubVersion);
51+
mockFeatureFlagApiEndpoint(200, {});
52+
53+
// When there are no action inputs for RAM and threads, the action uses
54+
// environment variables (passed down from the init action) to set RAM and
55+
// threads usage.
56+
process.env["CODEQL_THREADS"] = "-1";
57+
process.env["CODEQL_RAM"] = "4992";
58+
59+
const runFinalizeStub = sinon.stub(analyze, "runFinalize");
60+
const runQueriesStub = sinon.stub(analyze, "runQueries");
61+
62+
await runWrapper();
63+
64+
t.assert(
65+
runFinalizeStub.calledOnceWith(
66+
sinon.match.any,
67+
sinon.match.any,
68+
"--threads=-1",
69+
"--ram=4992",
70+
),
71+
);
72+
t.assert(
73+
runQueriesStub.calledOnceWith(
74+
sinon.match.any,
75+
"--ram=4992",
76+
"--threads=-1",
77+
),
78+
);
79+
});
80+
},
81+
);
82+
83+
test.serial(
84+
"analyze action with RAM & threads from action inputs",
85+
async (t) => {
86+
t.timeout(1000 * 20);
87+
await util.withTmpDir(async (tmpDir) => {
88+
setupActionsVars(tmpDir, tmpDir);
89+
sinon
90+
.stub(statusReport, "createStatusReportBase")
91+
.resolves({} as statusReport.StatusReportBase);
92+
sinon.stub(statusReport, "sendStatusReport").resolves();
93+
const gitHubVersion: util.GitHubVersion = {
94+
type: util.GitHubVariant.DOTCOM,
95+
};
96+
sinon.stub(configUtils, "getConfig").resolves({
97+
gitHubVersion,
98+
augmentationProperties: {},
99+
languages: [],
100+
packs: [],
101+
trapCaches: {},
102+
} as unknown as configUtils.Config);
103+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
104+
requiredInputStub.withArgs("token").returns("fake-token");
105+
requiredInputStub.withArgs("upload-database").returns("false");
106+
requiredInputStub.withArgs("output").returns("out");
107+
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
108+
optionalInputStub.withArgs("expect-error").returns("false");
109+
sinon.stub(api, "getGitHubVersion").resolves(gitHubVersion);
110+
sinon.stub(gitUtils, "isAnalyzingDefaultBranch").resolves(true);
111+
mockFeatureFlagApiEndpoint(200, {});
112+
113+
process.env["CODEQL_THREADS"] = "1";
114+
process.env["CODEQL_RAM"] = "4992";
115+
116+
// Action inputs have precedence over environment variables.
117+
optionalInputStub.withArgs("threads").returns("-1");
118+
optionalInputStub.withArgs("ram").returns("3012");
119+
120+
const runFinalizeStub = sinon.stub(analyze, "runFinalize");
121+
const runQueriesStub = sinon.stub(analyze, "runQueries");
122+
123+
await runWrapper();
124+
125+
t.assert(
126+
runFinalizeStub.calledOnceWith(
127+
sinon.match.any,
128+
sinon.match.any,
129+
"--threads=-1",
130+
"--ram=3012",
131+
),
132+
);
133+
t.assert(
134+
runQueriesStub.calledOnceWith(
135+
sinon.match.any,
136+
"--ram=3012",
137+
"--threads=-1",
138+
),
139+
);
140+
});
141+
},
142+
);

0 commit comments

Comments
 (0)