diff --git a/dist/index.js b/dist/index.js index 9fb13c2..52aa569 100644 --- a/dist/index.js +++ b/dist/index.js @@ -175229,13 +175229,17 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume -const esyPrefix = core.getInput("esy-prefix"); +let esyPrefix = core.getInput("esy-prefix"); const cacheKey = core.getInput("cache-key"); const sourceCacheKey = core.getInput("source-cache-key"); const manifestKey = core.getInput("manifest"); const prepareNPMArtifactsMode = core.getInput("prepare-npm-artifacts-mode"); const bundleNPMArtifactsMode = core.getInput("bundle-npm-artifacts-mode"); const customPostInstallJS = core.getInput("postinstall-js"); +function appendEnvironmentFile(key, value) { + external_fs_.appendFileSync(process.env.GITHUB_OUTPUT, `${key}=${value}\n`); + external_fs_.appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`); +} function run(name, command, args) { return __awaiter(this, void 0, void 0, function* () { const PATH = process.env.PATH ? process.env.PATH : ""; @@ -175245,6 +175249,7 @@ function run(name, command, args) { }); } function runEsyCommand(name, args) { + args.push(`--prefix=${esyPrefix}`); return run(name, "esy", manifestKey ? [`@${manifestKey}`, ...args] : args); } const index_platform = external_os_.platform(); @@ -175255,7 +175260,18 @@ function main() { const workingDirectory = core.getInput("working-directory") || process.cwd(); external_fs_.statSync(workingDirectory); process.chdir(workingDirectory); - const installPath = ["~/.esy/source"]; + esyPrefix = + esyPrefix && esyPrefix !== "" + ? esyPrefix + : external_path_.join(external_path_.dirname(process.env.GITHUB_WORKSPACE || + process.env.HOME || + process.env.HOMEPATH || + "~"), ".esy"); + console.log("esy-prefix", esyPrefix); + const ghOutputEsyPrefixK = "ESY_PREFIX"; + console.log(`Setting ${ghOutputEsyPrefixK} to`, esyPrefix); + appendEnvironmentFile(ghOutputEsyPrefixK, esyPrefix); + const installPath = [`${esyPrefix}/source`]; const installKey = `source-${index_platform}-${arch}-${sourceCacheKey}`; core.startGroup("Restoring install cache"); const installCacheKey = yield cache.restoreCache(installPath, installKey, []); @@ -175267,12 +175283,11 @@ function main() { if (installCacheKey != installKey) { yield cache.saveCache(installPath, installKey); } - const ESY_FOLDER = esyPrefix ? esyPrefix : external_path_.join(external_os_.homedir(), ".esy"); - const esy3 = external_fs_.readdirSync(ESY_FOLDER) + const esy3 = external_fs_.readdirSync(esyPrefix) .filter((name) => name.length > 0 && name[0] === "3") .sort() .pop(); - const depsPath = [external_path_.join(ESY_FOLDER, esy3, "i")]; + const depsPath = [external_path_.join(esyPrefix, esy3, "i")]; const buildKey = `build-${index_platform}-${arch}-${cacheKey}`; const restoreKeys = [`build-${index_platform}-${arch}-`, `build-`]; core.startGroup("Restoring build cache"); @@ -175289,9 +175304,12 @@ function main() { yield cache.saveCache(depsPath, buildKey); } // TODO: support cleanup + manifest - if (!manifestKey && !buildCacheKey) { - yield run("Run esy cleanup", "esy", ["cleanup", "."]); - } + // Need to improve how subcommands are called + // --prefix after cleanup subcommand doesn't work + // --prefix prepended doesn't work with any other sub-command + // if (!manifestKey && !buildCacheKey) { + // await runEsyCommand("Run esy cleanup", ["cleanup", "."]); + // } } catch (error) { if (error instanceof Error) { diff --git a/index.ts b/index.ts index 37aa433..fdff0ce 100644 --- a/index.ts +++ b/index.ts @@ -10,7 +10,7 @@ import * as util from "util"; import * as cp from "child_process"; import * as tar from "tar"; -const esyPrefix = core.getInput("esy-prefix"); +let esyPrefix = core.getInput("esy-prefix"); const cacheKey = core.getInput("cache-key"); const sourceCacheKey = core.getInput("source-cache-key"); const manifestKey = core.getInput("manifest"); @@ -18,6 +18,11 @@ const prepareNPMArtifactsMode = core.getInput("prepare-npm-artifacts-mode"); const bundleNPMArtifactsMode = core.getInput("bundle-npm-artifacts-mode"); const customPostInstallJS = core.getInput("postinstall-js"); +function appendEnvironmentFile(key: string, value: string) { + fs.appendFileSync(process.env.GITHUB_OUTPUT!, `${key}=${value}\n`); + fs.appendFileSync(process.env.GITHUB_ENV!, `${key}=${value}\n`); +} + async function run(name: string, command: string, args: string[]) { const PATH = process.env.PATH ? process.env.PATH : ""; core.startGroup(name); @@ -26,6 +31,7 @@ async function run(name: string, command: string, args: string[]) { } function runEsyCommand(name: string, args: string[]) { + args.push(`--prefix=${esyPrefix}`); return run(name, "esy", manifestKey ? [`@${manifestKey}`, ...args] : args); } @@ -38,7 +44,23 @@ async function main() { fs.statSync(workingDirectory); process.chdir(workingDirectory); - const installPath = ["~/.esy/source"]; + esyPrefix = + esyPrefix && esyPrefix !== "" + ? esyPrefix + : path.join( + path.dirname( + process.env.GITHUB_WORKSPACE || + process.env.HOME || + process.env.HOMEPATH || + "~" + ), + ".esy" + ); + console.log("esy-prefix", esyPrefix); + const ghOutputEsyPrefixK = "ESY_PREFIX"; + console.log(`Setting ${ghOutputEsyPrefixK} to`, esyPrefix); + appendEnvironmentFile(ghOutputEsyPrefixK, esyPrefix); + const installPath = [`${esyPrefix}/source`]; const installKey = `source-${platform}-${arch}-${sourceCacheKey}`; core.startGroup("Restoring install cache"); const installCacheKey = await cache.restoreCache( @@ -57,14 +79,13 @@ async function main() { await cache.saveCache(installPath, installKey); } - const ESY_FOLDER = esyPrefix ? esyPrefix : path.join(os.homedir(), ".esy"); const esy3 = fs - .readdirSync(ESY_FOLDER) + .readdirSync(esyPrefix) .filter((name: string) => name.length > 0 && name[0] === "3") .sort() .pop(); - const depsPath = [path.join(ESY_FOLDER, esy3!, "i")]; + const depsPath = [path.join(esyPrefix, esy3!, "i")]; const buildKey = `build-${platform}-${arch}-${cacheKey}`; const restoreKeys = [`build-${platform}-${arch}-`, `build-`]; @@ -90,9 +111,12 @@ async function main() { } // TODO: support cleanup + manifest - if (!manifestKey && !buildCacheKey) { - await run("Run esy cleanup", "esy", ["cleanup", "."]); - } + // Need to improve how subcommands are called + // --prefix after cleanup subcommand doesn't work + // --prefix prepended doesn't work with any other sub-command + // if (!manifestKey && !buildCacheKey) { + // await runEsyCommand("Run esy cleanup", ["cleanup", "."]); + // } } catch (error) { if (error instanceof Error) { core.setFailed(error.message);