Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log in to flakehub on existing installs #129

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,13 @@ class NixInstallerAction extends DetSysAction {
);
await this.executeUninstall();
} else {
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
// We're already installed, and not reinstalling, just log in to FlakeHub, set GITHUB_PATH and finish early
await this.setGithubPath();

if (this.determinate) {
await this.flakehubLogin();
}

actionsCore.info("Nix was already installed, using existing install");
return;
}
Expand Down Expand Up @@ -643,11 +648,11 @@ class NixInstallerAction extends DetSysAction {
await this.spawnDockerShim();
}

await this.setGithubPath();

if (this.determinate) {
await this.flakehubLogin();
}

await this.setGithubPath();
}

async spawnDockerShim(): Promise<void> {
Expand Down Expand Up @@ -859,13 +864,19 @@ class NixInstallerAction extends DetSysAction {
async setGithubPath(): Promise<void> {
// Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error.
try {
const nixVarNixProfilePath = "/nix/var/nix/profiles/default/bin";
const homeNixProfilePath = `${process.env["HOME"]}/.nix-profile/bin`;
actionsCore.addPath(nixVarNixProfilePath);
actionsCore.addPath(homeNixProfilePath);
actionsCore.info(
`Added \`${nixVarNixProfilePath}\` and \`${homeNixProfilePath}\` to \`$GITHUB_PATH\``,
);
const paths = [];

if (this.determinate) {
paths.push("/usr/local/bin");
}

paths.push("/nix/var/nix/profiles/default/bin");
paths.push(`${process.env["HOME"]}/.nix-profile/bin`);

for (const p of paths) {
actionsCore.addPath(p);
actionsCore.debug(`Added \`${p}\` to \`$GITHUB_PATH\``);
}
} catch {
actionsCore.info(
"Skipping setting $GITHUB_PATH in action, the `nix-installer` crate seems to have done this already. From `nix-installer` version 0.11.0 and up, this step is done in the action. Prior to 0.11.0, this was only done in the `nix-installer` binary.",
Expand All @@ -883,6 +894,7 @@ class NixInstallerAction extends DetSysAction {
try {
await actionsExec.exec(`determinate-nixd`, ["login", "github-action"]);
} catch (e: unknown) {
actionsCore.warning(`FlakeHub Login failure: ${stringifyError(e)}`);
this.recordEvent("flakehub-login:failure", {
exception: stringifyError(e),
});
Expand Down