mirror of
https://github.com/DeterminateSystems/nix-installer-action.git
synced 2024-12-23 05:22:21 +01:00
Streamline runner OS logic
This commit is contained in:
parent
61795779f3
commit
f6047128c4
2 changed files with 65 additions and 45 deletions
51
dist/index.js
generated
vendored
51
dist/index.js
generated
vendored
|
@ -97800,6 +97800,7 @@ var NixInstallerAction = class extends DetSysAction {
|
|||
this.reinstall = inputs_exports.getBool("reinstall");
|
||||
this.startDaemon = inputs_exports.getBool("start-daemon");
|
||||
this.trustRunnerUser = inputs_exports.getBool("trust-runner-user");
|
||||
this.runnerOs = process.env["RUNNER_OS"];
|
||||
}
|
||||
async main() {
|
||||
await this.detectAndForceDockerShim();
|
||||
|
@ -97809,9 +97810,17 @@ var NixInstallerAction = class extends DetSysAction {
|
|||
await this.cleanupDockerShim();
|
||||
await this.reportOverall();
|
||||
}
|
||||
get isMacOS() {
|
||||
return this.runnerOs === "macOS";
|
||||
}
|
||||
get isLinux() {
|
||||
return this.runnerOs === "Linux";
|
||||
}
|
||||
get isAct() {
|
||||
return process.env["ACT"] !== "" && !(process.env["NOT_ACT"] === "");
|
||||
}
|
||||
async detectAndForceDockerShim() {
|
||||
const runnerOs = process.env["RUNNER_OS"];
|
||||
if (runnerOs !== "Linux") {
|
||||
if (this.isLinux) {
|
||||
if (this.forceDockerShim) {
|
||||
core.warning(
|
||||
"Ignoring force-docker-shim which is set to true, as it is only supported on Linux."
|
||||
|
@ -97820,7 +97829,7 @@ var NixInstallerAction = class extends DetSysAction {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (process.env["ACT"] && !process.env["NOT_ACT"]) {
|
||||
if (this.isAct) {
|
||||
core.debug(
|
||||
"Not bothering to detect if the docker shim should be used, as it is typically incompatible with act."
|
||||
);
|
||||
|
@ -97984,7 +97993,6 @@ ${stderrBuffer}`
|
|||
}
|
||||
async executionEnvironment() {
|
||||
const executionEnv = {};
|
||||
const runnerOs = process.env["RUNNER_OS"];
|
||||
executionEnv.NIX_INSTALLER_NO_CONFIRM = "true";
|
||||
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = JSON.stringify(
|
||||
this.getCorrelationHashes()
|
||||
|
@ -98025,13 +98033,13 @@ ${stderrBuffer}`
|
|||
}
|
||||
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT = this.getDiagnosticsUrl()?.toString() ?? "";
|
||||
if (this.macEncrypt !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt;
|
||||
}
|
||||
if (this.macCaseSensitive !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error(
|
||||
"`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`"
|
||||
);
|
||||
|
@ -98039,7 +98047,7 @@ ${stderrBuffer}`
|
|||
executionEnv.NIX_INSTALLER_CASE_SENSITIVE = this.macCaseSensitive;
|
||||
}
|
||||
if (this.macVolumeLabel !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error(
|
||||
"`mac-volume-label` while `$RUNNER_OS` was not `macOS`"
|
||||
);
|
||||
|
@ -98047,7 +98055,7 @@ ${stderrBuffer}`
|
|||
executionEnv.NIX_INSTALLER_VOLUME_LABEL = this.macVolumeLabel;
|
||||
}
|
||||
if (this.macRootDisk !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk;
|
||||
|
@ -98059,7 +98067,7 @@ ${stderrBuffer}`
|
|||
executionEnv.NIX_INSTALLER_LOG_DIRECTIVES = this.logDirectives;
|
||||
}
|
||||
if (this.init !== null) {
|
||||
if (runnerOs === "macOS") {
|
||||
if (this.isMacOS) {
|
||||
throw new Error(
|
||||
"`init` is not a valid option when `$RUNNER_OS` is `macOS`"
|
||||
);
|
||||
|
@ -98128,8 +98136,8 @@ ${stderrBuffer}`
|
|||
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
|
||||
args.push(this.planner);
|
||||
} else {
|
||||
this.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner());
|
||||
args.push(getDefaultPlanner());
|
||||
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.defaultPlanner);
|
||||
args.push(this.defaultPlanner);
|
||||
}
|
||||
if (this.extraArgs) {
|
||||
const extraArgs = parseArgsStringToArgv(this.extraArgs);
|
||||
|
@ -98521,17 +98529,18 @@ ${stderrBuffer}`
|
|||
return "unavailable";
|
||||
}
|
||||
}
|
||||
};
|
||||
function getDefaultPlanner() {
|
||||
const envOs = process.env["RUNNER_OS"];
|
||||
if (envOs === "macOS") {
|
||||
return "macos";
|
||||
} else if (envOs === "Linux") {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${envOs}\`)`);
|
||||
get defaultPlanner() {
|
||||
if (this.isMacOS) {
|
||||
return "macos";
|
||||
} else if (this.isLinux) {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new Error(
|
||||
`Unsupported \`RUNNER_OS\` (currently \`${this.runnerOs}\`)`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
function main() {
|
||||
new NixInstallerAction().execute();
|
||||
}
|
||||
|
|
59
src/index.ts
59
src/index.ts
|
@ -65,6 +65,7 @@ class NixInstallerAction extends DetSysAction {
|
|||
reinstall: boolean;
|
||||
startDaemon: boolean;
|
||||
trustRunnerUser: boolean | null;
|
||||
runnerOs: string | undefined;
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
|
@ -104,6 +105,7 @@ class NixInstallerAction extends DetSysAction {
|
|||
this.reinstall = inputs.getBool("reinstall");
|
||||
this.startDaemon = inputs.getBool("start-daemon");
|
||||
this.trustRunnerUser = inputs.getBool("trust-runner-user");
|
||||
this.runnerOs = process.env["RUNNER_OS"];
|
||||
}
|
||||
|
||||
async main(): Promise<void> {
|
||||
|
@ -116,13 +118,23 @@ class NixInstallerAction extends DetSysAction {
|
|||
await this.reportOverall();
|
||||
}
|
||||
|
||||
async detectAndForceDockerShim(): Promise<void> {
|
||||
const runnerOs = process.env["RUNNER_OS"];
|
||||
private get isMacOS(): boolean {
|
||||
return this.runnerOs === "macOS";
|
||||
}
|
||||
|
||||
private get isLinux(): boolean {
|
||||
return this.runnerOs === "Linux";
|
||||
}
|
||||
|
||||
private get isAct(): boolean {
|
||||
return process.env["ACT"] !== "" && !(process.env["NOT_ACT"] === "");
|
||||
}
|
||||
|
||||
async detectAndForceDockerShim(): Promise<void> {
|
||||
// Detect if we're in a GHA runner which is Linux, doesn't have Systemd, and does have Docker.
|
||||
// This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/),
|
||||
// and especially GitHub Enterprise Server.
|
||||
if (runnerOs !== "Linux") {
|
||||
if (this.isLinux) {
|
||||
if (this.forceDockerShim) {
|
||||
actionsCore.warning(
|
||||
"Ignoring force-docker-shim which is set to true, as it is only supported on Linux.",
|
||||
|
@ -132,7 +144,7 @@ class NixInstallerAction extends DetSysAction {
|
|||
return;
|
||||
}
|
||||
|
||||
if (process.env["ACT"] && !process.env["NOT_ACT"]) {
|
||||
if (this.isAct) {
|
||||
actionsCore.debug(
|
||||
"Not bothering to detect if the docker shim should be used, as it is typically incompatible with act.",
|
||||
);
|
||||
|
@ -325,7 +337,6 @@ class NixInstallerAction extends DetSysAction {
|
|||
|
||||
private async executionEnvironment(): Promise<ExecuteEnvironment> {
|
||||
const executionEnv: ExecuteEnvironment = {};
|
||||
const runnerOs = process.env["RUNNER_OS"];
|
||||
|
||||
executionEnv.NIX_INSTALLER_NO_CONFIRM = "true";
|
||||
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = JSON.stringify(
|
||||
|
@ -381,14 +392,14 @@ class NixInstallerAction extends DetSysAction {
|
|||
|
||||
// TODO: Error if the user uses these on not-MacOS
|
||||
if (this.macEncrypt !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt;
|
||||
}
|
||||
|
||||
if (this.macCaseSensitive !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error(
|
||||
"`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`",
|
||||
);
|
||||
|
@ -397,7 +408,7 @@ class NixInstallerAction extends DetSysAction {
|
|||
}
|
||||
|
||||
if (this.macVolumeLabel !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error(
|
||||
"`mac-volume-label` while `$RUNNER_OS` was not `macOS`",
|
||||
);
|
||||
|
@ -406,7 +417,7 @@ class NixInstallerAction extends DetSysAction {
|
|||
}
|
||||
|
||||
if (this.macRootDisk !== null) {
|
||||
if (runnerOs !== "macOS") {
|
||||
if (!this.isMacOS) {
|
||||
throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`");
|
||||
}
|
||||
executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk;
|
||||
|
@ -422,7 +433,7 @@ class NixInstallerAction extends DetSysAction {
|
|||
|
||||
// TODO: Error if the user uses these on MacOS
|
||||
if (this.init !== null) {
|
||||
if (runnerOs === "macOS") {
|
||||
if (this.isMacOS) {
|
||||
throw new Error(
|
||||
"`init` is not a valid option when `$RUNNER_OS` is `macOS`",
|
||||
);
|
||||
|
@ -498,8 +509,8 @@ class NixInstallerAction extends DetSysAction {
|
|||
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
|
||||
args.push(this.planner);
|
||||
} else {
|
||||
this.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner());
|
||||
args.push(getDefaultPlanner());
|
||||
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.defaultPlanner);
|
||||
args.push(this.defaultPlanner);
|
||||
}
|
||||
|
||||
if (this.extraArgs) {
|
||||
|
@ -962,6 +973,18 @@ class NixInstallerAction extends DetSysAction {
|
|||
return "unavailable";
|
||||
}
|
||||
}
|
||||
|
||||
private get defaultPlanner(): string {
|
||||
if (this.isMacOS) {
|
||||
return "macos";
|
||||
} else if (this.isLinux) {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new Error(
|
||||
`Unsupported \`RUNNER_OS\` (currently \`${this.runnerOs}\`)`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ExecuteEnvironment = {
|
||||
|
@ -990,18 +1013,6 @@ type ExecuteEnvironment = {
|
|||
NIX_INSTALLER_LOGGER?: string;
|
||||
};
|
||||
|
||||
function getDefaultPlanner(): string {
|
||||
const envOs = process.env["RUNNER_OS"];
|
||||
|
||||
if (envOs === "macOS") {
|
||||
return "macos";
|
||||
} else if (envOs === "Linux") {
|
||||
return "linux";
|
||||
} else {
|
||||
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${envOs}\`)`);
|
||||
}
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
new NixInstallerAction().execute();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue