Skip to content

Commit

Permalink
fix: running Node.js version when using exec() (#785)
Browse files Browse the repository at this point in the history
By default, `exec()` tries using the pre-installed Node.js instead of `runs` in `action.yml`.
This change fixes the bug by adding `runs` Node.js path to the `PATH` environment variable.
  • Loading branch information
ybiquitous committed Sep 2, 2023
1 parent 4732c19 commit df73363
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ var require_core = __commonJS({
command_1.issueCommand("add-mask", {}, secret);
}
exports.setSecret = setSecret;
function addPath(inputPath) {
function addPath2(inputPath) {
const filePath = process.env["GITHUB_PATH"] || "";
if (filePath) {
file_command_1.issueFileCommand("PATH", inputPath);
Expand All @@ -2073,7 +2073,7 @@ var require_core = __commonJS({
}
process.env["PATH"] = `${inputPath}${path.delimiter}${process.env["PATH"]}`;
}
exports.addPath = addPath;
exports.addPath = addPath2;
function getInput2(name, options) {
const val = process.env[`INPUT_${name.replace(/ /g, "_").toUpperCase()}`] || "";
if (options && options.required && !val) {
Expand Down Expand Up @@ -10961,7 +10961,12 @@ function getFromEnv(name) {
throw new Error(`Not found '${name}' in the environment variables`);
}
async function run() {
core2.info(`Running on Node.js ${import_node_process3.default.version}`);
core2.addPath(import_node_process3.default.execPath.replace(/\/node$/u, ""));
const npmVersion = await core2.group(`Update npm to ${NPM_VERSION}`, () => updateNpm(NPM_VERSION));
await core2.group("Show runtime info", async () => {
await (0, import_exec7.exec)("npm", ["version"]);
});
await core2.group("Install user packages", async () => {
await (0, import_exec7.exec)("npm", npmArgs("ci"));
});
Expand Down
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ function getFromEnv(name) {
}

async function run() {
core.info(`Running on Node.js ${process.version}`);
core.addPath(process.execPath.replace(/\/node$/u, ""));

const npmVersion = await core.group(`Update npm to ${NPM_VERSION}`, () => updateNpm(NPM_VERSION));

await core.group("Show runtime info", async () => {
await exec("npm", ["version"]);
});

await core.group("Install user packages", async () => {
await exec("npm", npmArgs("ci"));
});
Expand Down

0 comments on commit df73363

Please sign in to comment.