Skip to content

Commit

Permalink
fix: bad format
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed May 6, 2024
1 parent b2bd9b3 commit 318209a
Showing 1 changed file with 70 additions and 72 deletions.
142 changes: 70 additions & 72 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81702,7 +81702,7 @@ const fs = __importStar(__nccwpck_require__(3292));
const node_fetch_1 = __importDefault(__nccwpck_require__(467));
const crypto_1 = __importDefault(__nccwpck_require__(6113));
// TODO: auto-manage these versions
const DENO_VERSION = "1.42.4";
const DENO_VERSION = '1.42.4';
async function latestGhjkVersion() {
const resp = await (0, node_fetch_1.default)(`https://api.github.com/repos/metatypedev/ghjk/releases/latest`);
if (!resp.ok) {
Expand All @@ -81717,48 +81717,48 @@ async function latestGhjkVersion() {
*/
async function main() {
try {
const inputVersion = core.getInput("version");
const inputInstallerUrl = core.getInput("installer-url");
const inputCook = core.getInput("cook");
const inputSkipDenoInstall = core.getInput("skip-deno-install");
const inputCacheDisable = core.getInput("cache-disable");
const inputCacheKeyPrefix = core.getInput("cache-key-prefix");
const inputCacheSaveIf = core.getInput("cache-save-if");
const inputCacheKeyEnvVars = core.getInput("cache-key-env-vars");
process.env.GHJK_LOG = "debug";
const denoCache = path.resolve(os.homedir(), ".cache", "deno");
const inputVersion = core.getInput('version');
const inputInstallerUrl = core.getInput('installer-url');
const inputCook = core.getInput('cook');
const inputSkipDenoInstall = core.getInput('skip-deno-install');
const inputCacheDisable = core.getInput('cache-disable');
const inputCacheKeyPrefix = core.getInput('cache-key-prefix');
const inputCacheSaveIf = core.getInput('cache-save-if');
const inputCacheKeyEnvVars = core.getInput('cache-key-env-vars');
process.env.GHJK_LOG = 'debug';
const denoCache = path.resolve(os.homedir(), '.cache', 'deno');
process.env.DENO_DIR = denoCache;
process.env.GHJK_INSTALL_DENO_DIR = denoCache;
const version = inputVersion.length > 0
? inputVersion
: process.env["GHJK_VERSION"] ?? (await latestGhjkVersion());
: process.env['GHJK_VERSION'] ?? (await latestGhjkVersion());
const installerUrl = inputInstallerUrl.length > 0
? inputInstallerUrl
: `https://raw.github.com/metatypedev/ghjk/${version}/install.ts`;
const execDir = await installGhjk(version, installerUrl, inputSkipDenoInstall === "true");
const execDir = await installGhjk(version, installerUrl, inputSkipDenoInstall === 'true');
core.addPath(execDir);
const configStr = (await exec.getExecOutput("ghjk", ["print", "config"]))
const configStr = (await exec.getExecOutput('ghjk', ['print', 'config']))
.stdout;
const shareDir = (await exec.getExecOutput("ghjk", ["print", "share-dir-path"], {
silent: true,
const shareDir = (await exec.getExecOutput('ghjk', ['print', 'share-dir-path'], {
silent: true
})).stdout.trim();
if (inputCacheDisable === "false" && cache.isFeatureAvailable()) {
const ghjkVersion = (await exec.getExecOutput("ghjk", ["--version"], { silent: true })).stdout.trim();
const configPath = (await exec.getExecOutput("ghjk", ["print", "ghjkfile-path"], {
silent: true,
if (inputCacheDisable === 'false' && cache.isFeatureAvailable()) {
const ghjkVersion = (await exec.getExecOutput('ghjk', ['--version'], { silent: true })).stdout.trim();
const configPath = (await exec.getExecOutput('ghjk', ['print', 'ghjkfile-path'], {
silent: true
})).stdout.trim();
const ghjkDirPath = (await exec.getExecOutput("ghjk", ["print", "ghjkfile-path"], {
silent: true,
const ghjkDirPath = (await exec.getExecOutput('ghjk', ['print', 'ghjkfile-path'], {
silent: true
})).stdout.trim();
const lockfilePath = path.resolve(ghjkDirPath, "lock.json");
const lockfilePath = path.resolve(ghjkDirPath, 'lock.json');
let lockJson = undefined;
try {
lockJson = await fs.readFile(lockfilePath, { encoding: "utf8" });
lockJson = await fs.readFile(lockfilePath, { encoding: 'utf8' });
}
catch (_err) {
/* FILE was not found*/
}
const hasher = crypto_1.default.createHash("sha1");
const hasher = crypto_1.default.createHash('sha1');
hasher.update(ghjkVersion);
hasher.update(configPath);
// TODO: consider ignoring config to avoid misses just for one dep change
Expand All @@ -81767,43 +81767,41 @@ async function main() {
hasher.update(lockJson);
}
const hashedEnvs = [
"GHJK",
"DENO",
'GHJK',
'DENO',
...inputCacheKeyEnvVars
.split(",")
.filter((str) => str.length > 0)
.map((str) => str.trim()),
.split(',')
.filter(str => str.length > 0)
.map(str => str.trim())
];
for (const [key, val] of Object.entries(process.env)) {
if (hashedEnvs.some((pfix) => key.startsWith(pfix))) {
if (hashedEnvs.some(pfix => key.startsWith(pfix))) {
hasher.update(`${key}=${val}`);
}
}
const hash = hasher.digest("hex");
const keyPrefix = inputCacheKeyPrefix.length > 0
? inputCacheKeyPrefix
: "v0-ghjk";
const hash = hasher.digest('hex');
const keyPrefix = inputCacheKeyPrefix.length > 0 ? inputCacheKeyPrefix : 'v0-ghjk';
const key = `${keyPrefix}-${hash}`;
const portsDir = core.toPlatformPath(path.resolve(shareDir, "ports"));
const portsDir = core.toPlatformPath(path.resolve(shareDir, 'ports'));
const cacheDirs = [portsDir, denoCache];
core.info(JSON.stringify({ cacheDirs, portsDir }));
// NOTE: restoreCache modifies the array it's given for some reason
await cache.restoreCache([...cacheDirs], key);
if (inputCacheSaveIf === "true") {
if (inputCacheSaveIf === 'true') {
core.info(`enabling cache with key ${key}: [${cacheDirs}]`);
core.saveState("ghjk-cache-save", true);
core.saveState("ghjk-post-args", {
core.saveState('ghjk-cache-save', true);
core.saveState('ghjk-post-args', {
key,
cacheDirs,
cacheDirs
});
}
}
if (inputCook === "true") {
await exec.exec("ghjk", ["envs", "cook"]);
if (inputCook === 'true') {
await exec.exec('ghjk', ['envs', 'cook']);
}
core.exportVariable("BASH_ENV", `${shareDir}/env.bash`);
core.exportVariable("GHJK_SHARE_DIR", shareDir);
core.exportVariable("GHJK_DENO_DIR", denoCache);
core.exportVariable('BASH_ENV', `${shareDir}/env.bash`);
core.exportVariable('GHJK_SHARE_DIR', shareDir);
core.exportVariable('GHJK_DENO_DIR', denoCache);
}
catch (error) {
// Fail the workflow run if an error occurs
Expand All @@ -81813,18 +81811,18 @@ async function main() {
}
exports.main = main;
async function installGhjk(version, installerUrl, skipDenoInstall) {
let denoExec = "deno";
if (skipDenoInstall && !process.env["GHJK_INSTALL_DENO_EXEC"]) {
const denoOut = await exec.getExecOutput("deno", ["--version"]);
let denoExec = 'deno';
if (skipDenoInstall && !process.env['GHJK_INSTALL_DENO_EXEC']) {
const denoOut = await exec.getExecOutput('deno', ['--version']);
if (denoOut.exitCode !== 0) {
throw new Error("skip-deno-install set but no deno binary found");
throw new Error('skip-deno-install set but no deno binary found');
}
core.debug(`skipping deno install & using found "deno" bin`);
}
else {
denoExec = await installDeno(process.env["DENO_VERSION"] ?? DENO_VERSION);
denoExec = await installDeno(process.env['DENO_VERSION'] ?? DENO_VERSION);
}
const foundExecDir = tc.find("ghjk", version);
const foundExecDir = tc.find('ghjk', version);
if (foundExecDir.length !== 0) {
core.debug(`found cached ghjk tool under version ${version}: ${foundExecDir}`);
return foundExecDir;
Expand All @@ -81833,20 +81831,20 @@ async function installGhjk(version, installerUrl, skipDenoInstall) {
core.debug(`unable to find cached ghjk tool under version ${version}`);
}
core.debug(`installing ghjk using install.ts`);
const installDir = process.env["GHJK_INSTALL_EXE_DIR"] ??
core.toPlatformPath(path.resolve(os.homedir(), ".local", "bin"));
const installDir = process.env['GHJK_INSTALL_EXE_DIR'] ??
core.toPlatformPath(path.resolve(os.homedir(), '.local', 'bin'));
const env = {
...process.env,
GHJK_INSTALL_EXE_DIR: installDir,
SHELL: "bash",
SHELL: 'bash'
};
// NOTE: we make the ghjk bin use whichver deno is avail in path
// to avoid it hardcoding the current deno bin path
// which won't be the same after tool cache restore
env["GHJK_INSTALL_DENO_EXEC"] = "deno";
core.debug(JSON.stringify({ denoExec, env }, undefined, " "));
env['GHJK_INSTALL_DENO_EXEC'] = 'deno';
core.debug(JSON.stringify({ denoExec, env }, undefined, ' '));
await exec.exec(`"${denoExec}" run -A`, [installerUrl], { env });
return await tc.cacheDir(installDir, "ghjk", version);
return await tc.cacheDir(installDir, 'ghjk', version);
}
exports.installGhjk = installGhjk;
async function installDeno(version) {
Expand All @@ -81857,32 +81855,32 @@ async function installDeno(version) {
function zipName() {
let arch;
switch (process.arch) {
case "arm64":
arch = "aarch64";
case 'arm64':
arch = 'aarch64';
break;
case "x64":
arch = "x86_64";
case 'x64':
arch = 'x86_64';
break;
default:
throw new Error(`Unsupported architechture ${process.arch}.`);
}
let platform;
switch (process.platform) {
case "linux":
platform = "unknown-linux-gnu";
case 'linux':
platform = 'unknown-linux-gnu';
break;
case "darwin":
platform = "apple-darwin";
case 'darwin':
platform = 'apple-darwin';
break;
case "win32":
platform = "pc-windows-msvc";
case 'win32':
platform = 'pc-windows-msvc';
break;
default:
throw new Error(`Unsupported platform ${process.platform}.`);
}
return `deno-${arch}-${platform}.zip`;
}
const cachedPath = tc.find("ghjk-deno", version);
const cachedPath = tc.find('ghjk-deno', version);
if (cachedPath) {
core.info(`Using cached Deno installation from ${cachedPath}.`);
core.addPath(cachedPath);
Expand All @@ -81893,7 +81891,7 @@ async function installDeno(version) {
core.info(`Downloading Deno from ${url}.`);
const zipPath = await tc.downloadTool(url);
const extractedFolder = await tc.extractZip(zipPath);
const newCachedPath = await tc.cacheDir(extractedFolder, "ghjk-deno", version);
const newCachedPath = await tc.cacheDir(extractedFolder, 'ghjk-deno', version);
core.info(`Cached Deno to ${newCachedPath}.`);
core.addPath(newCachedPath);
return `${newCachedPath}/deno`;
Expand All @@ -81906,15 +81904,15 @@ exports.installDeno = installDeno;
async function post() {
try {
if (cache.isFeatureAvailable() &&
core.getState("ghjk-cache-save") === "true") {
const argsStr = core.getState("ghjk-post-args");
core.getState('ghjk-cache-save') === 'true') {
const argsStr = core.getState('ghjk-post-args');
core.info(argsStr);
const args = JSON.parse(argsStr);
const { key, cacheDirs } = args;
await cache.saveCache(cacheDirs, key);
}
else {
core.info("cache-save flag is false, skipping");
core.info('cache-save flag is false, skipping');
}
}
catch (error) {
Expand Down

0 comments on commit 318209a

Please sign in to comment.