Skip to content

Commit

Permalink
Fixes for projects that use custom working directory (#30)
Browse files Browse the repository at this point in the history
* Makes working-directory absolute if it wasn't

* Make manifest.esy property optional

* Fixes working directory while npm-release

* Guard the prepare-npm-artifacts mode against missing esy.release config

* Fixes workingDirectory of esy status command

* Fixes workingDirectory of esy npm-release command

* Build on Ubuntu
  • Loading branch information
ManasJayanth authored Jul 27, 2024
1 parent 4a96b1c commit c991fa7
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Path where esy can setup the cache. Default: `$HOME/.esy`
#### `working-directory`

Working directory of the project. Useful for projects that place esy project
under a folder.
under a folder. It's converted into an absolute path, if it already isn't.

Default: Action workspace root.

Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ inputs:
description: A cache key for retrieving esy sources cache.
required: true
working-directory:
description: Working directory for esy
description:
Working directory for esy. It's converted into an absolute path, if it
already isn't
required: false
esy-prefix:
description: Prefix of esy folder
Expand Down
54 changes: 33 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139524,11 +139524,18 @@ if (partsSeparatedBtAT.length > 1 && partsSeparatedBtAT[0] !== "") {
console.error("Please specify the version (or NPM dist-tag) in the setup-esy-version field");
process.exit(-1);
}
let workingDirectory = core.getInput("working-directory") || process.cwd();
workingDirectory = external_path_.isAbsolute(workingDirectory)
? workingDirectory
: external_path_.join(process.cwd(), workingDirectory);
function run(name, command, args) {
return __awaiter(this, void 0, void 0, function* () {
const PATH = process.env.PATH ? process.env.PATH : "";
core.startGroup(name);
yield (0,exec.exec)(command, args, { env: Object.assign(Object.assign({}, process.env), { PATH }) });
yield (0,exec.exec)(command, args, {
env: Object.assign(Object.assign({}, process.env), { PATH }),
cwd: workingDirectory,
});
core.endGroup();
});
}
Expand Down Expand Up @@ -139589,7 +139596,8 @@ const index_platform = external_os_.platform();
const arch = external_os_.arch();
function main() {
return __awaiter(this, void 0, void 0, function* () {
const workingDirectory = core.getInput("working-directory") || process.cwd();
// Otherwise, when we change directories and then back (workingDirectory -> /tmp -> workingDirectory)
// chdir() would try to enter a path relative to that path
try {
if (setupEsy) {
let tarballUrl, checksum, esyPackageVersion, esyPackageName;
Expand Down Expand Up @@ -139708,29 +139716,34 @@ function compress(dir, outputFile) {
}
function prepareNPMArtifacts() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const statusCmd = manifestKey ? `esy ${manifestKey} status` : "esy status";
try {
const manifestFilePath = JSON.parse(external_child_process_.execSync(statusCmd).toString()).rootPackageConfigPath;
const manifestFilePath = JSON.parse(external_child_process_.execSync(statusCmd, { cwd: workingDirectory }).toString()).rootPackageConfigPath;
const manifest = JSON.parse(external_fs_.readFileSync(manifestFilePath).toString());
if (manifest.esy.release) {
if ((_a = manifest.esy) === null || _a === void 0 ? void 0 : _a.release) {
yield runEsyCommand("Running esy npm-release", ["npm-release"]);
let tarFile = `npm-tarball.tgz`;
yield compress(external_path_.join(workingDirectory, "_release"), tarFile);
const artifactName = `esy-npm-release-${index_platform}-${arch}`;
console.log("Artifact name: ", artifactName);
const { id, size } = yield artifact_default().uploadArtifact(artifactName, [tarFile], process.env.GITHUB_WORKSPACE, {
// The level of compression for Zlib to be applied to the artifact archive.
// - 0: No compression
// - 1: Best speed
// - 6: Default compression (same as GNU Gzip)
// - 9: Best compression
compressionLevel: 0,
// 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}`);
}
else {
console.error(external_fs_.readFileSync(manifestFilePath).toString());
throw new Error(`No config found in ${manifestFilePath} for npm-release. See https://esy.sh/docs/npm-release to learn more.`);
}
let tarFile = `npm-tarball.tgz`;
yield compress("_release", tarFile);
const artifactName = `esy-npm-release-${index_platform}-${arch}`;
console.log("Artifact name: ", artifactName);
const { id, size } = yield artifact_default().uploadArtifact(artifactName, [tarFile], process.env.GITHUB_WORKSPACE, {
// The level of compression for Zlib to be applied to the artifact archive.
// - 0: No compression
// - 1: Best speed
// - 6: Default compression (same as GNU Gzip)
// - 9: Best compression
compressionLevel: 0,
// 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}`);
}
catch (error) {
if (error instanceof Error) {
Expand All @@ -139744,7 +139757,6 @@ function prepareNPMArtifacts() {
}
function bundleNPMArtifacts() {
return __awaiter(this, void 0, void 0, function* () {
const workingDirectory = core.getInput("working-directory") || process.cwd();
external_fs_.statSync(workingDirectory);
process.chdir(workingDirectory);
const releaseFolder = external_path_.join(workingDirectory, "_npm-release");
Expand Down
68 changes: 40 additions & 28 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ if (partsSeparatedBtAT.length > 1 && partsSeparatedBtAT[0] !== "") {
);
process.exit(-1);
}
let workingDirectory = core.getInput("working-directory") || process.cwd();
workingDirectory = path.isAbsolute(workingDirectory)
? workingDirectory
: path.join(process.cwd(), workingDirectory);

async function run(name: string, command: string, args: string[]) {
const PATH = process.env.PATH ? process.env.PATH : "";
core.startGroup(name);
await exec(command, args, { env: { ...process.env, PATH } });
await exec(command, args, {
env: { ...process.env, PATH },
cwd: workingDirectory,
});
core.endGroup();
}

Expand Down Expand Up @@ -128,7 +135,8 @@ function computeChecksum(filePath: string, algo: string) {
const platform = os.platform();
const arch = os.arch();
async function main() {
const workingDirectory = core.getInput("working-directory") || process.cwd();
// Otherwise, when we change directories and then back (workingDirectory -> /tmp -> workingDirectory)
// chdir() would try to enter a path relative to that path
try {
if (setupEsy) {
let tarballUrl, checksum, esyPackageVersion, esyPackageName;
Expand Down Expand Up @@ -283,35 +291,40 @@ async function prepareNPMArtifacts() {
const statusCmd = manifestKey ? `esy ${manifestKey} status` : "esy status";
try {
const manifestFilePath = JSON.parse(
cp.execSync(statusCmd).toString()
cp.execSync(statusCmd, { cwd: workingDirectory }).toString()
).rootPackageConfigPath;
const manifest = JSON.parse(fs.readFileSync(manifestFilePath).toString());
if (manifest.esy.release) {
if (manifest.esy?.release) {
await runEsyCommand("Running esy npm-release", ["npm-release"]);
}
let tarFile = `npm-tarball.tgz`;
await compress("_release", tarFile);

const artifactName = `esy-npm-release-${platform}-${arch}`;
console.log("Artifact name: ", artifactName);
const { id, size } = await artifact.uploadArtifact(
artifactName,
[tarFile],
process.env.GITHUB_WORKSPACE!,
{
// The level of compression for Zlib to be applied to the artifact archive.
// - 0: No compression
// - 1: Best speed
// - 6: Default compression (same as GNU Gzip)
// - 9: Best compression
compressionLevel: 0,
// optional: how long to retain the artifact
// if unspecified, defaults to repository/org retention settings (the limit of this value)
retentionDays: 10,
}
);
let tarFile = `npm-tarball.tgz`;
await compress(path.join(workingDirectory, "_release"), tarFile);

const artifactName = `esy-npm-release-${platform}-${arch}`;
console.log("Artifact name: ", artifactName);
const { id, size } = await artifact.uploadArtifact(
artifactName,
[tarFile],
process.env.GITHUB_WORKSPACE!,
{
// The level of compression for Zlib to be applied to the artifact archive.
// - 0: No compression
// - 1: Best speed
// - 6: Default compression (same as GNU Gzip)
// - 9: Best compression
compressionLevel: 0,
// 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}`);
console.log(`Created artifact with id: ${id} (bytes: ${size}`);
} else {
console.error(fs.readFileSync(manifestFilePath).toString());
throw new Error(
`No config found in ${manifestFilePath} for npm-release. See https://esy.sh/docs/npm-release to learn more.`
);
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
Expand All @@ -322,7 +335,6 @@ async function prepareNPMArtifacts() {
}

async function bundleNPMArtifacts() {
const workingDirectory = core.getInput("working-directory") || process.cwd();
fs.statSync(workingDirectory);
process.chdir(workingDirectory);
const releaseFolder = path.join(workingDirectory, "_npm-release");
Expand Down

0 comments on commit c991fa7

Please sign in to comment.