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 {
// 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");
return;
}
@ -254,12 +254,24 @@ class NixInstallerAction {
// Normal just doing of the install
const binary_path = yield this.fetch_binary();
yield this.execute_install(binary_path);
this.set_github_path();
yield this.set_github_path();
});
}
set_github_path() {
actions_core.addPath("/nix/var/nix/profiles/default/bin");
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`);
return __awaiter(this, void 0, void 0, function* () {
// 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() {
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();
} else {
// 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");
return;
}
@ -293,10 +293,21 @@ class NixInstallerAction {
// Normal just doing of the install
const binary_path = await this.fetch_binary();
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(`${process.env.HOME}/.nix-profile/bin`);
}