Skip to content

Commit

Permalink
Better messaging when we set GITHUB_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoverbear committed Jul 14, 2023
1 parent bdec431 commit d29c939
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 53 deletions.
43 changes: 19 additions & 24 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

54 changes: 26 additions & 28 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,13 @@ class NixInstallerAction {
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.
try {
actions_core.addPath("/nix/var/nix/profiles/default/bin");
actions_core.addPath(`${process.env.HOME}/.nix-profile/bin`);
const nix_var_nix_profile_path = "/nix/var/nix/profiles/default/bin";
const home_nix_profile_path = `${process.env.HOME}/.nix-profile/bin`;
actions_core.addPath(nix_var_nix_profile_path);
actions_core.addPath(home_nix_profile_path);
actions_core.info(
`Added \`${nix_var_nix_profile_path}\` and \`${home_nix_profile_path}\` to \`$GITHUB_PATH\``,
);
} catch (error) {
actions_core.warning(
"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 only done in the action. Prior to 0.11.0, this was done in the `nix-installer` binary.",
Expand Down Expand Up @@ -463,51 +468,44 @@ function resolve_nix_installer_url(platform: string): URL {
const nix_installer_tag = action_input_string_or_null("nix-installer-tag");
const nix_installer_url = action_input_string_or_null("nix-installer-url");

let resolved_nix_installer_url = null;
let num_set = 0;
if (nix_installer_branch !== null) {
num_set += 1;
}
if (nix_installer_pr !== null) {
num_set += 1;
}
if (nix_installer_revision !== null) {
num_set += 1;
}
if (nix_installer_tag !== null) {
num_set += 1;
}
if (nix_installer_url !== null) {
num_set += 1;
}
if (num_set > 1) {
throw new Error(
`The following options are mututally exclusive, but ${num_set} were set: \`nix_installer_branch\`, \`nix_installer_pr\`, \`nix_installer_revision\`, \`nix_installer_tag\`, and \`nix_installer_url\``,
);
}

if (nix_installer_branch !== null) {
return new URL(
num_set += 1;
resolved_nix_installer_url = new URL(
`https://install.determinate.systems/nix/branch/${nix_installer_branch}/nix-installer-${platform}?ci=github`,
);
} else if (nix_installer_pr !== null) {
return new URL(
num_set += 1;
resolved_nix_installer_url = new URL(
`https://install.determinate.systems/nix/pr/${nix_installer_pr}/nix-installer-${platform}?ci=github`,
);
} else if (nix_installer_revision !== null) {
return new URL(
num_set += 1;
resolved_nix_installer_url = new URL(
`https://install.determinate.systems/nix/rev/${nix_installer_revision}/nix-installer-${platform}?ci=github`,
);
} else if (nix_installer_tag !== null) {
return new URL(
num_set += 1;
resolved_nix_installer_url = new URL(
`https://install.determinate.systems/nix/tag/${nix_installer_tag}/nix-installer-${platform}?ci=github`,
);
} else if (nix_installer_url !== null) {
return new URL(nix_installer_url);
num_set += 1;
resolved_nix_installer_url = new URL(nix_installer_url);
} else {
return new URL(
resolved_nix_installer_url = new URL(
`https://install.determinate.systems/nix/nix-installer-${platform}?ci=github`,
);
}

if (num_set > 1) {
throw new Error(
`The following options are mututally exclusive, but ${num_set} were set: \`nix_installer_branch\`, \`nix_installer_pr\`, \`nix_installer_revision\`, \`nix_installer_tag\`, and \`nix_installer_url\``,
);
}
return resolved_nix_installer_url;
}

function action_input_string_or_null(name: string): string | null {
Expand Down

0 comments on commit d29c939

Please sign in to comment.