mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 09:14:58 +00:00
Auto-generate entry points
This commit is contained in:
65
build.mjs
65
build.mjs
@@ -1,4 +1,4 @@
|
||||
import { copyFile, rm, writeFile } from "node:fs/promises";
|
||||
import { copyFile, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
@@ -62,19 +62,70 @@ const onEndPlugin = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Emit a tiny stub file for each Action entrypoint. Each stub imports the shared bundle
|
||||
* and calls the respective entry point.
|
||||
*
|
||||
* @type {esbuild.Plugin}
|
||||
*/
|
||||
const entryPointsPlugin = {
|
||||
name: "entry-points",
|
||||
setup(build) {
|
||||
const actions = [];
|
||||
|
||||
const toPascal = (s) =>
|
||||
s.replace(/(^|-)([a-z0-9])/gi, (_, __, c) => c.toUpperCase());
|
||||
|
||||
// Find the source files containing action entry points.
|
||||
build.onStart(() => {
|
||||
const actionFiles = globSync("src/*-action{,-post}.ts");
|
||||
for (const actionFile of actionFiles) {
|
||||
const match = actionFile.match(/src\/(.*)-action(-post)?.ts/);
|
||||
const actionName = match[1];
|
||||
const isPost = match[2] !== undefined;
|
||||
|
||||
actions.push({
|
||||
path: actionFile,
|
||||
name: actionName,
|
||||
isPost,
|
||||
pascalCaseName: `${toPascal(actionName)}${isPost ? "Post" : ""}Action`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Emit entry point stubs for each action using the entry template.
|
||||
build.onEnd(async (result) => {
|
||||
// Read the entry point template.
|
||||
const templatePath = "action-entry.js.tpl";
|
||||
const template = await readFile(join(SRC_DIR, templatePath), "utf-8");
|
||||
|
||||
const makeHeader = (sourceFile) =>
|
||||
`// Automatically generated from '${templatePath}' for '${sourceFile}'.\n\n`;
|
||||
|
||||
// Write entry point stubs for each action.
|
||||
for (const action of actions) {
|
||||
await writeFile(
|
||||
join(
|
||||
OUT_DIR,
|
||||
`${action.name}${action.isPost ? "-post" : ""}-entry.js`,
|
||||
),
|
||||
makeHeader(action.path) +
|
||||
template.replaceAll("__ACTION__", action.pascalCaseName),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const context = await esbuild.context({
|
||||
// Include upload-lib.ts as an entry point for use in testing environments.
|
||||
entryPoints: globSync([
|
||||
`${SRC_DIR}/*-entry.ts`,
|
||||
"src/entry-points.ts",
|
||||
"src/upload-lib.ts",
|
||||
]),
|
||||
entryPoints: globSync(["src/entry-points.ts", "src/upload-lib.ts"]),
|
||||
bundle: true,
|
||||
format: "cjs",
|
||||
outdir: OUT_DIR,
|
||||
platform: "node",
|
||||
external: ["./entry-points"],
|
||||
plugins: [cleanPlugin, copyDefaultsPlugin, onEndPlugin],
|
||||
plugins: [cleanPlugin, copyDefaultsPlugin, entryPointsPlugin, onEndPlugin],
|
||||
target: ["node20"],
|
||||
define: {
|
||||
__CODEQL_ACTION_VERSION__: JSON.stringify(pkg.version),
|
||||
|
||||
5
lib/analyze-entry.js
generated
5
lib/analyze-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/analyze-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/analyze-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runAnalyzeAction)();
|
||||
|
||||
5
lib/analyze-post-entry.js
generated
5
lib/analyze-post-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/analyze-action-post.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/analyze-post-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runAnalyzePostAction)();
|
||||
|
||||
5
lib/autobuild-entry.js
generated
5
lib/autobuild-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/autobuild-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/autobuild-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runAutobuildAction)();
|
||||
|
||||
5
lib/init-entry.js
generated
5
lib/init-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/init-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/init-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runInitAction)();
|
||||
|
||||
5
lib/init-post-entry.js
generated
5
lib/init-post-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/init-action-post.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/init-post-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runInitPostAction)();
|
||||
|
||||
5
lib/resolve-environment-entry.js
generated
5
lib/resolve-environment-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/resolve-environment-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/resolve-environment-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runResolveEnvironmentAction)();
|
||||
|
||||
5
lib/setup-codeql-entry.js
generated
5
lib/setup-codeql-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/setup-codeql-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/setup-codeql-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runSetupCodeqlAction)();
|
||||
|
||||
5
lib/start-proxy-entry.js
generated
5
lib/start-proxy-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/start-proxy-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/start-proxy-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runStartProxyAction)();
|
||||
|
||||
5
lib/start-proxy-post-entry.js
generated
5
lib/start-proxy-post-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/start-proxy-action-post.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/start-proxy-post-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runStartProxyPostAction)();
|
||||
|
||||
5
lib/upload-sarif-entry.js
generated
5
lib/upload-sarif-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/upload-sarif-action.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/upload-sarif-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runUploadSarifAction)();
|
||||
|
||||
5
lib/upload-sarif-post-entry.js
generated
5
lib/upload-sarif-post-entry.js
generated
@@ -1,5 +1,6 @@
|
||||
// Automatically generated from 'action-entry.js.tpl' for 'src/upload-sarif-action-post.ts'.
|
||||
|
||||
"use strict";
|
||||
|
||||
// src/upload-sarif-post-entry.ts
|
||||
var import_entry_points = require("./entry-points");
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.runUploadSarifPostAction)();
|
||||
|
||||
4
src/action-entry.js.tpl
Normal file
4
src/action-entry.js.tpl
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
const import_entry_points = require("./entry-points");
|
||||
void (0, import_entry_points.run__ACTION__)();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runAnalyzeAction } from "./entry-points";
|
||||
|
||||
void runAnalyzeAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runAnalyzePostAction } from "./entry-points";
|
||||
|
||||
void runAnalyzePostAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runAutobuildAction } from "./entry-points";
|
||||
|
||||
void runAutobuildAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runInitAction } from "./entry-points";
|
||||
|
||||
void runInitAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runInitPostAction } from "./entry-points";
|
||||
|
||||
void runInitPostAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runResolveEnvironmentAction } from "./entry-points";
|
||||
|
||||
void runResolveEnvironmentAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runSetupCodeqlAction } from "./entry-points";
|
||||
|
||||
void runSetupCodeqlAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runStartProxyAction } from "./entry-points";
|
||||
|
||||
void runStartProxyAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runStartProxyPostAction } from "./entry-points";
|
||||
|
||||
void runStartProxyPostAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runUploadSarifAction } from "./entry-points";
|
||||
|
||||
void runUploadSarifAction();
|
||||
@@ -1,3 +0,0 @@
|
||||
import { runUploadSarifPostAction } from "./entry-points";
|
||||
|
||||
void runUploadSarifPostAction();
|
||||
Reference in New Issue
Block a user