Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Jul 13, 2024
1 parent 85c3d0c commit 750eefd
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 105 deletions.
72 changes: 42 additions & 30 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180399,6 +180399,13 @@ const setupEsyTarball = core.getInput("setup-esy-tarball");
const setupEsyShaSum = core.getInput("setup-esy-shasum");
const setupEsyVersion = core.getInput("setup-esy-version");
const setupEsyNPMPackageName = core.getInput("setup-esy-npm-package");
const partsSeparatedBtAT = setupEsyNPMPackageName.split("@");
if (partsSeparatedBtAT.length > 1 && partsSeparatedBtAT[0] !== "") {
// ie @ appears in such a way that it separates name and version. Not to signify namespace
// esy@latest enters this block. @prometheansacrifice/esy doesn't
console.error("Please specify the version (or NPM dist-tag) in the setup-esy-version field");
process.exit(-1);
}
function appendEnvironmentFile(key, value) {
external_fs_.appendFileSync(process.env.GITHUB_OUTPUT, `${key}=${value}\n`);
external_fs_.appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`);
Expand All @@ -180419,18 +180426,17 @@ function getLatestEsyNPMInfo(alternativeEsyNPMPackage) {
esyPackage = "esy@latest";
}
else {
const [packageName, _packageVersion] = alternativeEsyNPMPackage.split("@");
const { validForOldPackages, validForNewPackages, errors = [], } = lib_default()(packageName);
const { validForOldPackages, validForNewPackages, errors = [], } = lib_default()(alternativeEsyNPMPackage);
if (!validForNewPackages || !validForOldPackages) {
throw new Error(`Invalid alternative NPM package name provided: ${packageName}
throw new Error(`Invalid alternative NPM package name provided: ${alternativeEsyNPMPackage}
Errors:
${errors.join("\n")}`);
}
esyPackage = alternativeEsyNPMPackage;
esyPackage = `${alternativeEsyNPMPackage}@${setupEsyVersion}`;
}
try {
if (!cachedEsyNPMInfo) {
cachedEsyNPMInfo = JSON.parse(external_child_process_.execSync(`npm info ${esyPackage} --json`).toString().trim());
cachedEsyNPMInfo = JSON.parse(external_child_process_.execSync(`npm info "${esyPackage}" --json`).toString().trim());
return cachedEsyNPMInfo;
}
else {
Expand All @@ -180446,7 +180452,8 @@ function getEsyDownloadArtifactsMeta(alternativeEsyNPMPackage) {
const tarballUrl = esyNPMInfo.dist.tarball;
const shasum = esyNPMInfo.dist.shasum;
const version = esyNPMInfo.version;
return { tarballUrl, shasum, version };
const name = esyNPMInfo.name;
return { name, tarballUrl, shasum, version };
}
function runEsyCommand(name, args) {
if (args[0] !== "npm-release" && args[0] !== "release") {
Expand All @@ -180473,39 +180480,44 @@ function main() {
const workingDirectory = core.getInput("working-directory") || process.cwd();
try {
if (setupEsy) {
let tarballUrl, checksum, version;
let tarballUrl, checksum, esyPackageVersion, esyPackageName;
if (!setupEsyVersion || !setupEsyShaSum || !setupEsyTarball) {
const meta = getEsyDownloadArtifactsMeta(setupEsyNPMPackageName);
tarballUrl = meta.tarballUrl;
checksum = meta.shasum;
version = meta.version;
esyPackageVersion = meta.version;
esyPackageName = meta.name;
}
else {
tarballUrl = setupEsyTarball;
version = setupEsyTarball;
esyPackageVersion = setupEsyVersion;
checksum = setupEsyShaSum;
esyPackageName = setupEsyNPMPackageName;
}
let cachedPath = tool_cache.find(esyPackageName, esyPackageVersion, arch);
if (cachedPath === "") {
console.log("Fetching tarball from", tarballUrl);
const downloadedEsyNPMTarball = yield tool_cache.downloadTool(tarballUrl);
const checksumAlgo = "sha1";
const computedChecksum = yield computeChecksum(downloadedEsyNPMTarball, checksumAlgo);
if (computedChecksum !== checksum) {
throw new Error(`Downloaded by checksum failed. url: ${setupEsyTarball} downloadPath: ${downloadedEsyNPMTarball} checksum expected: ${checksum} checksum computed: ${computedChecksum} checksum algorithm: ${checksumAlgo}`);
}
else {
console.log("Checksum validation succeeded. Downloaded tarball's checksum is:", checksum);
}
const extractedEsyNPM = yield tool_cache.extractTar(downloadedEsyNPMTarball);
core.startGroup("Running postinstall");
const esyPackagePath = external_path_.join(extractedEsyNPM, "package");
const postInstall = JSON.parse(external_fs_.readFileSync(external_path_.join(esyPackagePath, "package.json"))
.toString()
.trim()).scripts.postinstall;
process.chdir(esyPackagePath);
yield (0,exec.exec)(postInstall);
core.endGroup();
process.chdir(workingDirectory);
cachedPath = yield tool_cache.cacheDir(esyPackagePath, esyPackageName, esyPackageVersion);
}
console.log("Fetching tarball from", tarballUrl);
const downloadedEsyNPMTarball = yield tool_cache.downloadTool(tarballUrl);
const checksumAlgo = "sha1";
const computedChecksum = yield computeChecksum(downloadedEsyNPMTarball, checksumAlgo);
if (computedChecksum !== checksum) {
throw new Error(`Downloaded by checksum failed. url: ${setupEsyTarball} downloadPath: ${downloadedEsyNPMTarball} checksum expected: ${checksum} checksum computed: ${computedChecksum} checksum algorithm: ${checksumAlgo}`);
}
else {
console.log("Checksum validation succeeded. Downloaded tarball's checksum is:", checksum);
}
const extractedEsyNPM = yield tool_cache.extractTar(downloadedEsyNPMTarball);
core.startGroup("Running postinstall");
const esyPackagePath = external_path_.join(extractedEsyNPM, "package");
const postInstall = JSON.parse(external_fs_.readFileSync(external_path_.join(esyPackagePath, "package.json"))
.toString()
.trim()).scripts.postinstall;
process.chdir(esyPackagePath);
yield (0,exec.exec)(postInstall);
core.endGroup();
process.chdir(workingDirectory);
const cachedPath = yield tool_cache.cacheDir(esyPackagePath, "esy", version);
core.addPath(external_path_.join(cachedPath, "bin"));
}
external_fs_.statSync(workingDirectory);
Expand Down
Loading

0 comments on commit 750eefd

Please sign in to comment.