@arkts/sdk-downloader
Version:
Download and extract the ArkTS SDK.
54 lines (52 loc) • 2.18 kB
JavaScript
import { SdkArch, SdkOS } from "./download-Dayz2MQC.js";
import { logSdkDirStructure, runCommandLineDownload } from "./command-line-9KXYMiBC.js";
import path from "node:path";
import P from "pino";
import pretty from "pino-pretty";
import * as cache from "@actions/cache";
import * as core from "@actions/core";
//#region src/github-action.ts
async function run() {
const version = core.getInput("version", { required: true });
const archInput = core.getInput("arch", { required: false }) || "X86";
const osInput = core.getInput("os", { required: false }) || "Linux";
const cacheDir = core.getInput("cache_dir", { required: false }) || ".cache/sdk";
const targetDir = core.getInput("target_dir", { required: false }) || "sdk";
const logType = core.getInput("log_type", { required: false }) || "explicit";
const logTimeout = Number.parseInt(core.getInput("log_timeout", { required: false }) || "5000", 10);
const isCache = core.getBooleanInput("cache", { required: false });
const logger = P(pretty({
colorize: true,
colorizeObjects: true,
singleLine: true
}));
const arch = archInput.toLowerCase() === "arm" ? SdkArch.ARM : SdkArch.X86;
const os = osInput.toLowerCase() === "macos" ? SdkOS.MacOS : osInput.toLowerCase() === "windows" ? SdkOS.Windows : SdkOS.Linux;
const cacheKey = `ohos-sdk-${version}-${arch}-${os}`;
const cacheHit = await cache.restoreCache([path.resolve(targetDir)], cacheKey);
if (cacheHit) {
logger.warn(`Cache hit: ${cacheHit}, skipping download...`);
await logSdkDirStructure(logger, targetDir);
core.setOutput("sdkPath", path.resolve(targetDir));
return;
} else logger.warn(`Cache miss, starting to download...`);
await runCommandLineDownload({
apiVersion: version,
arch: SdkArch[arch],
os: SdkOS[os],
cacheDir,
targetDir,
logType,
logTimeout,
logger
});
if (isCache) {
logger.info(`Download & extract successfully, saving cache to ${cacheKey}...`);
const cacheId = await cache.saveCache([path.resolve(targetDir)], cacheKey);
logger.info(`Cache saved with id: ${cacheId}.`);
}
core.setOutput("sdkPath", path.resolve(targetDir));
}
run();
//#endregion
//# sourceMappingURL=github-action.js.map