Skip to content

Commit 8a38c2e

Browse files
committed
Update wrapper
1 parent b96b6fc commit 8a38c2e

File tree

6 files changed

+1881
-273
lines changed

6 files changed

+1881
-273
lines changed

bundler.js

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,34 @@
1-
import { execSync } from "node:child_process";
2-
import { existsSync as fsExistsSync } from "node:fs";
3-
import { mkdir as fsMkdir, readdir as fsReaddir, readFile as fsReadFile, rm as fsRm, writeFile as fsWriteFile } from "node:fs/promises";
1+
import { mkdir as fsMkdir, readdir as fsReaddir, rm as fsRm, writeFile as fsWriteFile } from "node:fs/promises";
42
import { dirname as pathDirname, join as pathJoin } from "node:path";
53
import { fileURLToPath } from "node:url";
64
import ncc from "@vercel/ncc";
7-
const root = pathDirname(fileURLToPath(import.meta.url));
8-
const packageFileName = "package.json";
9-
const scriptEntryPointFileName = "main.js";
10-
const inputDirectoryPath = pathJoin(root, "temp");
11-
const inputFilePath = pathJoin(inputDirectoryPath, scriptEntryPointFileName);
12-
const outputDirectoryPath = pathJoin(root, "hugoalh.GitHubActionsToolkit", "nodejs-wrapper");
13-
const outputFilePath = pathJoin(outputDirectoryPath, scriptEntryPointFileName);
14-
async function getDirectoryItem(directoryPath, relativeBasePath) {
15-
if (typeof relativeBasePath === "undefined") {
16-
relativeBasePath = directoryPath;
17-
}
18-
try {
19-
let result = [];
20-
for (let item of await fsReaddir(directoryPath, { withFileTypes: true })) {
21-
if (item.isDirectory()) {
22-
result.push(...await getDirectoryItem(pathJoin(directoryPath, item.name), relativeBasePath));
23-
} else {
24-
result.push(pathJoin(directoryPath, item.name).slice(relativeBasePath.length + 1).replace(/\\/gu, "/"));
25-
}
26-
}
27-
return result;
28-
} catch (error) {
29-
return [];
30-
}
31-
}
5+
const workspace = pathDirname(fileURLToPath(import.meta.url));
6+
const directoryInput = pathJoin(workspace, "temp");
7+
const directoryOutput = pathJoin(workspace, "hugoalh.GitHubActionsToolkit", "nodejs-wrapper");
8+
const scripts = new Set([
9+
"main.js"
10+
]);
3211

33-
/* Clean up or initialize output directory (need to await in order to prevent race conditions). */
34-
if (fsExistsSync(outputDirectoryPath)) {
35-
for (let fileName of await getDirectoryItem(outputDirectoryPath)) {
36-
await fsRm(pathJoin(outputDirectoryPath, fileName), { recursive: true });
37-
}
38-
} else {
39-
await fsMkdir(outputDirectoryPath, { recursive: true });
12+
// Initialize output directory.
13+
await fsMkdir(directoryOutput, { recursive: true });
14+
for (const fileName of await fsReaddir(directoryOutput)) {
15+
await fsRm(pathJoin(directoryOutput, fileName), { maxRetries: 4, recursive: true });
4016
}
4117

42-
/* Create bundle. */
43-
console.log(execSync(`"${pathJoin(root, "node_modules", ".bin", process.platform === "win32" ? "tsc.cmd" : "tsc")}" -p "${pathJoin(root, "tsconfig.json")}"`).toString("utf8"));
44-
let { code } = await ncc(inputFilePath, {
45-
assetBuilds: false,
46-
cache: false,
47-
debugLog: false,
48-
license: "",
49-
minify: true,
50-
quiet: false,
51-
sourceMap: false,
52-
sourceMapRegister: false,
53-
target: "es2022",
54-
v8cache: false,
55-
watch: false
56-
});
57-
await fsWriteFile(outputFilePath, code, { encoding: "utf8" });
58-
let packageMeta = JSON.parse(await fsReadFile(pathJoin(root, packageFileName), { encoding: "utf8" }));
59-
delete packageMeta.scripts;
60-
delete packageMeta.dependencies;
61-
delete packageMeta.devDependencies;
62-
await fsWriteFile(pathJoin(outputDirectoryPath, packageFileName), `${JSON.stringify(packageMeta, undefined, "\t")}\n`, { encoding: "utf8" });
18+
// Create bundle.
19+
for (const script of scripts.values()) {
20+
const { code } = await ncc(pathJoin(directoryInput, script), {
21+
assetBuilds: false,
22+
cache: false,
23+
debugLog: false,
24+
license: "",
25+
minify: true,
26+
quiet: false,
27+
sourceMap: false,
28+
sourceMapRegister: false,
29+
target: "es2022",
30+
v8cache: false,
31+
watch: false
32+
});
33+
await fsWriteFile(pathJoin(directoryOutput, script), code, { encoding: "utf8" });
34+
}

hugoalh.GitHubActionsToolkit/nodejs-wrapper/main.js

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

hugoalh.GitHubActionsToolkit/nodejs-wrapper/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hugoalh/ghactions-toolkit-powershell-nodejs-wrapper",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "A PowerShell module to provide a better and easier way for GitHub Actions to communicate with the runner machine, and the toolkit for developing GitHub Actions in PowerShell.",
55
"keywords": [
66
"gh-actions",

nodejs-wrapper-source/main.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { constants as fsConstants } from "node:fs";
22
import { open as fsOpen, type FileHandle } from "node:fs/promises";
3-
import { create as ghactionsArtifact, type DownloadResponse as GitHubActionsArtifactDownloadResponse, type UploadResponse as GitHubActionsArtifactUploadResponse } from "@actions/artifact";
3+
import { DefaultArtifactClient as GitHubActionsArtifactClient, type ListArtifactsResponse as GitHubActionsArtifactListResponse, type DownloadArtifactResponse as GitHubActionsArtifactDownloadResponse, type UploadArtifactResponse as GitHubActionsArtifactUploadResponse, type GetArtifactResponse as GitHubActionsArtifactGetResponse } from "@actions/artifact";
44
import { restoreCache as ghactionsCacheRestoreCache, saveCache as ghactionsCacheSaveCache } from "@actions/cache";
55
import { debug as ghactionsDebug, getIDToken as ghactionsGetOpenIDConnectToken } from "@actions/core";
66
import { cacheDir as ghactionsToolCacheCacheDirectory, cacheFile as ghactionsToolCacheCacheFile, downloadTool as ghactionsToolCacheDownloadTool, extract7z as ghactionsToolCacheExtract7z, extractTar as ghactionsToolCacheExtractTar, extractXar as ghactionsToolCacheExtractXar, extractZip as ghactionsToolCacheExtractZip, find as ghactionsToolCacheFind, findAllVersions as ghactionsToolCacheFindAllVersions } from "@actions/tool-cache";
@@ -42,40 +42,43 @@ switch (input.$name) {
4242
break;
4343
case "artifact/download":
4444
try {
45-
const result: GitHubActionsArtifactDownloadResponse = await ghactionsArtifact().downloadArtifact(input.name, input.destination, { createArtifactFolder: input.createSubDirectory });
45+
const result: GitHubActionsArtifactDownloadResponse = await new GitHubActionsArtifactClient().downloadArtifact(input.id, {
46+
findBy: input.findBy,
47+
path: input.path
48+
});
4649
await resolveSuccess({
47-
name: result.artifactName,
4850
path: result.downloadPath
4951
});
5052
} catch (error) {
5153
await resolveFail(error);
5254
}
5355
break;
54-
case "artifact/download-all":
56+
case "artifact/get":
57+
try {
58+
const result: GitHubActionsArtifactGetResponse = await new GitHubActionsArtifactClient().getArtifact(input.name, { findBy: input.findBy });
59+
await resolveSuccess(result.artifact);
60+
} catch (error) {
61+
await resolveFail(error);
62+
}
63+
break;
64+
case "artifact/list":
5565
try {
56-
const result: GitHubActionsArtifactDownloadResponse[] = await ghactionsArtifact().downloadAllArtifacts(input.destination);
57-
await resolveSuccess(result.map((value: GitHubActionsArtifactDownloadResponse) => {
58-
return {
59-
name: value.artifactName,
60-
path: value.downloadPath
61-
};
62-
}));
66+
const result: GitHubActionsArtifactListResponse = await new GitHubActionsArtifactClient().listArtifacts({
67+
findBy: input.findBy,
68+
latest: true
69+
});
70+
await resolveSuccess(result.artifacts);
6371
} catch (error) {
6472
await resolveFail(error);
6573
}
6674
break;
6775
case "artifact/upload":
6876
try {
69-
const result: GitHubActionsArtifactUploadResponse = await ghactionsArtifact().uploadArtifact(input.name, input.items, input.rootDirectory, {
70-
continueOnError: input.continueOnError,
77+
const result: GitHubActionsArtifactUploadResponse = await new GitHubActionsArtifactClient().uploadArtifact(input.name, input.items, input.rootDirectory, {
78+
compressionLevel: input.compressionLevel,
7179
retentionDays: input.retentionDays
7280
});
73-
await resolveSuccess({
74-
name: result.artifactName,
75-
items: result.artifactItems,
76-
size: result.size,
77-
failedItems: result.failedItems
78-
});
81+
await resolveSuccess(result);
7982
} catch (error) {
8083
await resolveFail(error);
8184
}

0 commit comments

Comments
 (0)