Skip to content

Commit

Permalink
WIP: run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Jun 12, 2024
1 parent c8e45d6 commit 0380bab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
16 changes: 12 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ inputs:
description: Flag to control if esy itself should be installed by the action
required: false
setup-esy-tarball:
description: URL to esy tarball. Must be provided together with shasum and version. Else, the action will default to latest from NPM
description:
URL to esy tarball. Must be provided together with shasum and version.
Else, the action will default to latest from NPM
required: false
setup-esy-shasum:
description: shasum of the tarball. Must be provided together with shasum and version. Else, the action will default to latest from NPM
description:
shasum of the tarball. Must be provided together with shasum and version.
Else, the action will default to latest from NPM
required: false
setup-esy-version:
description: version of the esy tool. Must be provided together with shasum and version. Else, the action will default to latest from NPM
description:
version of the esy tool. Must be provided together with shasum and
version. Else, the action will default to latest from NPM
required: false
setup-esy-npm-package:
description: Alternative NPM package that contains esy. Can contain version/tag too. Eg esy@beta.
description:
Alternative NPM package that contains esy. Can contain version/tag too. Eg
esy@beta.
required: false
runs:
using: node20
Expand Down
52 changes: 26 additions & 26 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ async function run(name: string, command: string, args: string[]) {
type NpmInfo = { dist: { tarball: string; shasum: string }; version: string };
let cachedEsyNPMInfo: NpmInfo | undefined;
function getLatestEsyNPMInfo(
alternativeEsyNPMPackage: string | undefined,
alternativeEsyNPMPackage: string | undefined
): NpmInfo {
try {
if (!cachedEsyNPMInfo) {
cachedEsyNPMInfo = JSON.parse(
cp
.execSync(`npm info ${alternativeEsyNPMPackage ?? "esy"} --json`)
.toString()
.trim(),
.trim()
);
return cachedEsyNPMInfo!;
} else {
Expand All @@ -55,7 +55,7 @@ function getLatestEsyNPMInfo(
}

function getEsyDownloadArtifactsMeta(
alternativeEsyNPMPackage: string | undefined,
alternativeEsyNPMPackage: string | undefined
) {
const esyNPMInfo = getLatestEsyNPMInfo(alternativeEsyNPMPackage);
const tarballUrl = esyNPMInfo.dist.tarball;
Expand Down Expand Up @@ -101,24 +101,24 @@ async function main() {
const checksumAlgo = "sha1";
const computedChecksum = await computeChecksum(
downloadedEsyNPMTarball,
checksumAlgo,
checksumAlgo
);
if (computedChecksum !== checksum) {
throw new Error(
`Downloaded by checksum failed. url: ${setupEsyTarball} downloadPath: ${downloadedEsyNPMTarball} checksum expected: ${checksum} checksum computed: ${computedChecksum} checksum algorithm: ${checksumAlgo}`,
`Downloaded by checksum failed. url: ${setupEsyTarball} downloadPath: ${downloadedEsyNPMTarball} checksum expected: ${checksum} checksum computed: ${computedChecksum} checksum algorithm: ${checksumAlgo}`
);
}

const extractedEsyNPM = await toolCache.extractTar(
downloadedEsyNPMTarball,
downloadedEsyNPMTarball
);
core.startGroup("Running postinstall");
const esyPackagePath = path.join(extractedEsyNPM, "package");
const postInstall = JSON.parse(
fs
.readFileSync(path.join(esyPackagePath, "package.json"))
.toString()
.trim(),
.trim()
).scripts.postinstall;
process.chdir(esyPackagePath);
await exec(postInstall);
Expand All @@ -127,7 +127,7 @@ async function main() {
const cachedPath = await toolCache.cacheDir(
esyPackagePath,
"esy",
version,
version
);

core.addPath(path.join(cachedPath, "bin"));
Expand All @@ -141,7 +141,7 @@ async function main() {
const installCacheKey = await cache.restoreCache(
installPath,
installKey,
[],
[]
);
if (installCacheKey) {
console.log("Restored the install cache");
Expand Down Expand Up @@ -169,7 +169,7 @@ async function main() {
const buildCacheKey = await cache.restoreCache(
depsPath,
buildKey,
restoreKeys,
restoreKeys
);
if (buildCacheKey) {
console.log("Restored the build cache");
Expand Down Expand Up @@ -202,15 +202,15 @@ async function main() {
async function uncompress(
dest: string,
tarFile: string,
strip?: number,
strip?: number
): Promise<void> {
return new Promise((resolve, reject) => {
fs.createReadStream(tarFile)
.pipe(
tar.x({
strip: strip,
C: dest, // alias for cwd:'some-dir', also ok
}),
})
)
.on("close", () => resolve())
.on("error", reject);
Expand All @@ -229,7 +229,7 @@ async function prepareNPMArtifacts() {
const statusCmd = manifestKey ? `esy ${manifestKey} status` : "esy status";
try {
const manifestFilePath = JSON.parse(
cp.execSync(statusCmd).toString(),
cp.execSync(statusCmd).toString()
).rootPackageConfigPath;
const manifest = JSON.parse(fs.readFileSync(manifestFilePath).toString());
if (manifest.esy.release) {
Expand All @@ -254,7 +254,7 @@ async function prepareNPMArtifacts() {
// optional: how long to retain the artifact
// if unspecified, defaults to repository/org retention settings (the limit of this value)
retentionDays: 10,
},
}
);

console.log(`Created artifact with id: ${id} (bytes: ${size}`);
Expand Down Expand Up @@ -285,19 +285,19 @@ async function bundleNPMArtifacts() {
});
await uncompress(folderPath, path.join(folderPath, "npm-tarball.tgz"), 1);
return folderName;
}),
})
);
const artifactFolders = artifactFoldersList.reduce(
(acc: string[], folderName: string) => {
acc.push(folderName);
return acc;
},
[],
[]
);
const esyInstallReleaseJS = "esyInstallRelease.js";
fs.cpSync(
path.join(releaseFolder, artifactFoldersList[0], esyInstallReleaseJS),
path.join(releaseFolder, esyInstallReleaseJS),
path.join(releaseFolder, esyInstallReleaseJS)
);
console.log("Creating package.json");
const possibleEsyJsonPath = path.join(workingDirectory, "esy.json");
Expand All @@ -311,21 +311,21 @@ async function bundleNPMArtifacts() {
process.exit(1);
}
const mainPackageJson = JSON.parse(
fs.readFileSync(`${mainPackageJsonPath}`).toString(),
fs.readFileSync(`${mainPackageJsonPath}`).toString()
);
const bins = Array.isArray(mainPackageJson.esy.release.bin)
? mainPackageJson.esy.release.bin.reduce(
(acc: any, curr: string) =>
Object.assign({ [curr]: "bin/" + curr }, acc),
{},
{}
)
: Object.keys(mainPackageJson.esy.release.bin).reduce(
(acc, currKey) =>
Object.assign(
{ [currKey]: "bin/" + mainPackageJson.esy.release.bin[currKey] },
acc,
acc
),
{},
{}
);
const rewritePrefix =
mainPackageJson.esy &&
Expand Down Expand Up @@ -358,7 +358,7 @@ async function bundleNPMArtifacts() {
].concat(artifactFolders),
},
null,
2,
2
);

fs.writeFileSync(path.join(releaseFolder, "package.json"), packageJson, {
Expand All @@ -369,7 +369,7 @@ async function bundleNPMArtifacts() {
console.log("Copying LICENSE");
fs.copyFileSync(
path.join(workingDirectory, "LICENSE"),
path.join(releaseFolder, "LICENSE"),
path.join(releaseFolder, "LICENSE")
);
} catch (e) {
console.warn("No LICENSE found");
Expand All @@ -379,7 +379,7 @@ async function bundleNPMArtifacts() {
console.log("Copying README.md");
fs.copyFileSync(
path.join(workingDirectory, "README.md"),
path.join(releaseFolder, "README.md"),
path.join(releaseFolder, "README.md")
);
} catch {
console.warn("No LICENSE found");
Expand All @@ -390,7 +390,7 @@ async function bundleNPMArtifacts() {
console.log("Copying postinstall.js from", releasePostInstallJS);
fs.copyFileSync(
releasePostInstallJS,
path.join(releaseFolder, "postinstall.js"),
path.join(releaseFolder, "postinstall.js")
);

console.log("Creating placeholder files");
Expand Down Expand Up @@ -427,7 +427,7 @@ ECHO You need to have postinstall enabled`;
// optional: how long to retain the artifact
// if unspecified, defaults to repository/org retention settings (the limit of this value)
retentionDays: 10,
},
}
);

core.endGroup();
Expand Down

0 comments on commit 0380bab

Please sign in to comment.