Add guardrail against old nix-installer versions that set GITHUB_PATH

This commit is contained in:
Ana Hobden 2023-07-14 07:58:00 -07:00
parent 017103f261
commit 09be496fdd
3 changed files with 31 additions and 8 deletions

20
dist/index.js vendored
View file

@ -246,7 +246,7 @@ class NixInstallerAction {
} }
else { else {
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early // We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
this.set_github_path(); yield this.set_github_path();
actions_core.info("Nix was already installed, using existing install"); actions_core.info("Nix was already installed, using existing install");
return; return;
} }
@ -254,12 +254,24 @@ class NixInstallerAction {
// Normal just doing of the install // Normal just doing of the install
const binary_path = yield this.fetch_binary(); const binary_path = yield this.fetch_binary();
yield this.execute_install(binary_path); yield this.execute_install(binary_path);
this.set_github_path(); yield this.set_github_path();
}); });
} }
set_github_path() { set_github_path() {
actions_core.addPath("/nix/var/nix/profiles/default/bin"); return __awaiter(this, void 0, void 0, function* () {
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`); // Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error.
const github_path = process.env.GITHUB_PATH;
if (typeof github_path === "string") {
try {
(0, promises_1.access)(github_path);
}
catch (_a) {
actions_core.info("Skipping setting $GITHUB_PATH in action, as `nix-installer` crate did it already");
}
}
actions_core.addPath("/nix/var/nix/profiles/default/bin");
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`);
});
} }
execute_uninstall() { execute_uninstall() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -285,7 +285,7 @@ class NixInstallerAction {
await this.execute_uninstall(); await this.execute_uninstall();
} else { } else {
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early // We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
this.set_github_path(); await this.set_github_path();
actions_core.info("Nix was already installed, using existing install"); actions_core.info("Nix was already installed, using existing install");
return; return;
} }
@ -293,10 +293,21 @@ class NixInstallerAction {
// Normal just doing of the install // Normal just doing of the install
const binary_path = await this.fetch_binary(); const binary_path = await this.fetch_binary();
await this.execute_install(binary_path); await this.execute_install(binary_path);
this.set_github_path(); await this.set_github_path();
} }
set_github_path(): void { async set_github_path(): Promise<void> {
// Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error.
const github_path = process.env.GITHUB_PATH;
if (typeof github_path === "string") {
try {
access(github_path);
} catch {
actions_core.info(
"Skipping setting $GITHUB_PATH in action, as `nix-installer` crate did it already",
);
}
}
actions_core.addPath("/nix/var/nix/profiles/default/bin"); actions_core.addPath("/nix/var/nix/profiles/default/bin");
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`); actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`);
} }