Skip to content

Commit

Permalink
Merge pull request #21 from esy/prometheansacrifice/fix-prefix-not-pa…
Browse files Browse the repository at this point in the history
…ssed-to-esy-commands

Re-work how esy prefix is used to handle `EXDEV` errors.
  • Loading branch information
ManasJayanth authored Jul 12, 2024
2 parents 1eca777 + 18d5225 commit 78b4c52
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
34 changes: 26 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "";
Expand All @@ -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();
Expand All @@ -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, []);
Expand All @@ -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");
Expand All @@ -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) {
Expand Down
40 changes: 32 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ 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");
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);
Expand All @@ -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);
}

Expand All @@ -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(
Expand All @@ -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-`];

Expand All @@ -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);
Expand Down

0 comments on commit 78b4c52

Please sign in to comment.