Skip to content

Commit 1d1558f

Browse files
committed
add github-test.js
1 parent d5f0ce0 commit 1d1558f

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { readdir } from "fs/promises";
2+
import { basename, join, normalize, sep } from "path";
3+
import { pathToFileURL } from "url";
4+
import { inspect } from "util";
5+
6+
/**
7+
* @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments
8+
*/
9+
export default async function importAllModules({ core }) {
10+
const workspace = process.env.GITHUB_WORKSPACE;
11+
if (!workspace) {
12+
throw new Error("Env var GITHUB_WORKSPACE must be set");
13+
}
14+
15+
const githubDir = join(workspace, ".github");
16+
17+
// find all files matching "**/src/**/*.js", sorted for readability
18+
const scriptFiles = (await readdir(githubDir, { recursive: true }))
19+
.filter((f) => normalize(f).split(sep).includes("src") && basename(f).endsWith(".js"))
20+
.sort();
21+
22+
core.info("Script Files:");
23+
scriptFiles.map(core.info);
24+
core.info("");
25+
26+
for (const file of scriptFiles) {
27+
core.info(`Importing ${file}`);
28+
29+
const fullPath = join(githubDir, file);
30+
const fileUrl = pathToFileURL(fullPath).href;
31+
32+
// if import fails, throws error which causes step to fail
33+
const module = /** @type {unknown} */ (await import(fileUrl));
34+
35+
core.info(inspect(module));
36+
core.info("");
37+
}
38+
39+
core.info("All script files are importable");
40+
}

0 commit comments

Comments
 (0)