Skip to content

Commit

Permalink
Rework input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMayes committed Apr 2, 2024
1 parent 92d30aa commit ebec5ce
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 deletions.
33 changes: 22 additions & 11 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

51 changes: 35 additions & 16 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,43 @@ const ASSETS = ASSETS_JSON as Record<string, Record<string, Record<string, strin

export interface Options {
version: string;
arch?: string;
forceUrl?: string;
directory: string;
arch: string | null;
forceUrl: string | null;
directory: string | null;
cached: boolean;
mirrorUrl?: string;
auth?: string;
mirrorUrl: string | null;
auth: string | null;
env: boolean;
}

function getRequiredInput(name: string): string {
const value = core.getInput(name).trim();
if (value !== "") {
return value;
} else {
throw new Error(`'${name}' input must be provided as a non-empty string`);
}
}

function getOptionalInput(name: string): string | null {
const value = core.getInput(name).trim();
if (value !== "") {
return value;
} else {
return null;
}
}

export function getOptions(): Options {
return {
version: core.getInput("version"),
arch: core.getInput("arch"),
forceUrl: core.getInput("force-url"),
directory: core.getInput("directory"),
cached: (core.getInput("cached") ?? "").toLowerCase() === "true",
mirrorUrl: core.getInput("mirror-url"),
auth: core.getInput("auth"),
env: (core.getInput("env") ?? "").toLowerCase() === "true",
version: getRequiredInput("version"),
arch: getOptionalInput("arch"),
forceUrl: getOptionalInput("force-url"),
directory: getOptionalInput("directory"),
cached: core.getBooleanInput("cached"),
mirrorUrl: getOptionalInput("mirror-url"),
auth: getOptionalInput("auth"),
env: core.getBooleanInput("env"),
};
}

Expand Down Expand Up @@ -105,14 +123,15 @@ async function install(options: Options): Promise<void> {

console.log(`Installing LLVM and Clang ${options.version} (${specificVersion})...`);
console.log(`Downloading and extracting '${url}'...`);
const archive = await tc.downloadTool(url, "", options.auth);
const archive = await tc.downloadTool(url, "", options.auth ?? undefined);

let exit;
if (os === "win32") {
exit = await exec.exec("7z", ["x", archive, `-o${options.directory}`, "-y"]);
} else {
await io.mkdirP(options.directory);
exit = await exec.exec("tar", ["xf", archive, "-C", options.directory, "--strip-components=1"]);
const directory = options.directory ?? "";
await io.mkdirP(directory);
exit = await exec.exec("tar", ["xf", archive, "-C", directory, "--strip-components=1"]);
}

if (exit !== 0) {
Expand Down

0 comments on commit ebec5ce

Please sign in to comment.