Streamline runner OS logic

This commit is contained in:
Luc Perkins 2024-05-22 13:40:01 -03:00
parent 61795779f3
commit f6047128c4
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
2 changed files with 65 additions and 45 deletions

51
dist/index.js generated vendored
View file

@ -97800,6 +97800,7 @@ var NixInstallerAction = class extends DetSysAction {
this.reinstall = inputs_exports.getBool("reinstall"); this.reinstall = inputs_exports.getBool("reinstall");
this.startDaemon = inputs_exports.getBool("start-daemon"); this.startDaemon = inputs_exports.getBool("start-daemon");
this.trustRunnerUser = inputs_exports.getBool("trust-runner-user"); this.trustRunnerUser = inputs_exports.getBool("trust-runner-user");
this.runnerOs = process.env["RUNNER_OS"];
} }
async main() { async main() {
await this.detectAndForceDockerShim(); await this.detectAndForceDockerShim();
@ -97809,9 +97810,17 @@ var NixInstallerAction = class extends DetSysAction {
await this.cleanupDockerShim(); await this.cleanupDockerShim();
await this.reportOverall(); 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() { async detectAndForceDockerShim() {
const runnerOs = process.env["RUNNER_OS"]; if (this.isLinux) {
if (runnerOs !== "Linux") {
if (this.forceDockerShim) { if (this.forceDockerShim) {
core.warning( core.warning(
"Ignoring force-docker-shim which is set to true, as it is only supported on Linux." "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; return;
} }
if (process.env["ACT"] && !process.env["NOT_ACT"]) { if (this.isAct) {
core.debug( core.debug(
"Not bothering to detect if the docker shim should be used, as it is typically incompatible with act." "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() { async executionEnvironment() {
const executionEnv = {}; const executionEnv = {};
const runnerOs = process.env["RUNNER_OS"];
executionEnv.NIX_INSTALLER_NO_CONFIRM = "true"; executionEnv.NIX_INSTALLER_NO_CONFIRM = "true";
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = JSON.stringify( executionEnv.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = JSON.stringify(
this.getCorrelationHashes() this.getCorrelationHashes()
@ -98025,13 +98033,13 @@ ${stderrBuffer}`
} }
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT = this.getDiagnosticsUrl()?.toString() ?? ""; executionEnv.NIX_INSTALLER_DIAGNOSTIC_ENDPOINT = this.getDiagnosticsUrl()?.toString() ?? "";
if (this.macEncrypt !== null) { if (this.macEncrypt !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`"); throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`");
} }
executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt; executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt;
} }
if (this.macCaseSensitive !== null) { if (this.macCaseSensitive !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error( throw new Error(
"`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`" "`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`"
); );
@ -98039,7 +98047,7 @@ ${stderrBuffer}`
executionEnv.NIX_INSTALLER_CASE_SENSITIVE = this.macCaseSensitive; executionEnv.NIX_INSTALLER_CASE_SENSITIVE = this.macCaseSensitive;
} }
if (this.macVolumeLabel !== null) { if (this.macVolumeLabel !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error( throw new Error(
"`mac-volume-label` while `$RUNNER_OS` was not `macOS`" "`mac-volume-label` while `$RUNNER_OS` was not `macOS`"
); );
@ -98047,7 +98055,7 @@ ${stderrBuffer}`
executionEnv.NIX_INSTALLER_VOLUME_LABEL = this.macVolumeLabel; executionEnv.NIX_INSTALLER_VOLUME_LABEL = this.macVolumeLabel;
} }
if (this.macRootDisk !== null) { if (this.macRootDisk !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`"); throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`");
} }
executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk; executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk;
@ -98059,7 +98067,7 @@ ${stderrBuffer}`
executionEnv.NIX_INSTALLER_LOG_DIRECTIVES = this.logDirectives; executionEnv.NIX_INSTALLER_LOG_DIRECTIVES = this.logDirectives;
} }
if (this.init !== null) { if (this.init !== null) {
if (runnerOs === "macOS") { if (this.isMacOS) {
throw new Error( throw new Error(
"`init` is not a valid option when `$RUNNER_OS` is `macOS`" "`init` is not a valid option when `$RUNNER_OS` is `macOS`"
); );
@ -98128,8 +98136,8 @@ ${stderrBuffer}`
this.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner); this.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
args.push(this.planner); args.push(this.planner);
} else { } else {
this.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner()); this.addFact(FACT_NIX_INSTALLER_PLANNER, this.defaultPlanner);
args.push(getDefaultPlanner()); args.push(this.defaultPlanner);
} }
if (this.extraArgs) { if (this.extraArgs) {
const extraArgs = parseArgsStringToArgv(this.extraArgs); const extraArgs = parseArgsStringToArgv(this.extraArgs);
@ -98521,17 +98529,18 @@ ${stderrBuffer}`
return "unavailable"; return "unavailable";
} }
} }
}; get defaultPlanner() {
function getDefaultPlanner() { if (this.isMacOS) {
const envOs = process.env["RUNNER_OS"]; return "macos";
if (envOs === "macOS") { } else if (this.isLinux) {
return "macos"; return "linux";
} else if (envOs === "Linux") { } else {
return "linux"; throw new Error(
} else { `Unsupported \`RUNNER_OS\` (currently \`${this.runnerOs}\`)`
throw new Error(`Unsupported \`RUNNER_OS\` (currently \`${envOs}\`)`); );
}
} }
} };
function main() { function main() {
new NixInstallerAction().execute(); new NixInstallerAction().execute();
} }

View file

@ -65,6 +65,7 @@ class NixInstallerAction extends DetSysAction {
reinstall: boolean; reinstall: boolean;
startDaemon: boolean; startDaemon: boolean;
trustRunnerUser: boolean | null; trustRunnerUser: boolean | null;
runnerOs: string | undefined;
constructor() { constructor() {
super({ super({
@ -104,6 +105,7 @@ class NixInstallerAction extends DetSysAction {
this.reinstall = inputs.getBool("reinstall"); this.reinstall = inputs.getBool("reinstall");
this.startDaemon = inputs.getBool("start-daemon"); this.startDaemon = inputs.getBool("start-daemon");
this.trustRunnerUser = inputs.getBool("trust-runner-user"); this.trustRunnerUser = inputs.getBool("trust-runner-user");
this.runnerOs = process.env["RUNNER_OS"];
} }
async main(): Promise<void> { async main(): Promise<void> {
@ -116,13 +118,23 @@ class NixInstallerAction extends DetSysAction {
await this.reportOverall(); await this.reportOverall();
} }
async detectAndForceDockerShim(): Promise<void> { private get isMacOS(): boolean {
const runnerOs = process.env["RUNNER_OS"]; 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. // 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/), // This is a common case in self-hosted runners, providers like [Namespace](https://namespace.so/),
// and especially GitHub Enterprise Server. // and especially GitHub Enterprise Server.
if (runnerOs !== "Linux") { if (this.isLinux) {
if (this.forceDockerShim) { if (this.forceDockerShim) {
actionsCore.warning( actionsCore.warning(
"Ignoring force-docker-shim which is set to true, as it is only supported on Linux.", "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; return;
} }
if (process.env["ACT"] && !process.env["NOT_ACT"]) { if (this.isAct) {
actionsCore.debug( actionsCore.debug(
"Not bothering to detect if the docker shim should be used, as it is typically incompatible with act.", "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> { private async executionEnvironment(): Promise<ExecuteEnvironment> {
const executionEnv: ExecuteEnvironment = {}; const executionEnv: ExecuteEnvironment = {};
const runnerOs = process.env["RUNNER_OS"];
executionEnv.NIX_INSTALLER_NO_CONFIRM = "true"; executionEnv.NIX_INSTALLER_NO_CONFIRM = "true";
executionEnv.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = JSON.stringify( 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 // TODO: Error if the user uses these on not-MacOS
if (this.macEncrypt !== null) { if (this.macEncrypt !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`"); throw new Error("`mac-encrypt` while `$RUNNER_OS` was not `macOS`");
} }
executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt; executionEnv.NIX_INSTALLER_ENCRYPT = this.macEncrypt;
} }
if (this.macCaseSensitive !== null) { if (this.macCaseSensitive !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error( throw new Error(
"`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`", "`mac-case-sensitive` while `$RUNNER_OS` was not `macOS`",
); );
@ -397,7 +408,7 @@ class NixInstallerAction extends DetSysAction {
} }
if (this.macVolumeLabel !== null) { if (this.macVolumeLabel !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error( throw new Error(
"`mac-volume-label` while `$RUNNER_OS` was not `macOS`", "`mac-volume-label` while `$RUNNER_OS` was not `macOS`",
); );
@ -406,7 +417,7 @@ class NixInstallerAction extends DetSysAction {
} }
if (this.macRootDisk !== null) { if (this.macRootDisk !== null) {
if (runnerOs !== "macOS") { if (!this.isMacOS) {
throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`"); throw new Error("`mac-root-disk` while `$RUNNER_OS` was not `macOS`");
} }
executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk; executionEnv.NIX_INSTALLER_ROOT_DISK = this.macRootDisk;
@ -422,7 +433,7 @@ class NixInstallerAction extends DetSysAction {
// TODO: Error if the user uses these on MacOS // TODO: Error if the user uses these on MacOS
if (this.init !== null) { if (this.init !== null) {
if (runnerOs === "macOS") { if (this.isMacOS) {
throw new Error( throw new Error(
"`init` is not a valid option when `$RUNNER_OS` is `macOS`", "`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); this.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
args.push(this.planner); args.push(this.planner);
} else { } else {
this.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner()); this.addFact(FACT_NIX_INSTALLER_PLANNER, this.defaultPlanner);
args.push(getDefaultPlanner()); args.push(this.defaultPlanner);
} }
if (this.extraArgs) { if (this.extraArgs) {
@ -962,6 +973,18 @@ class NixInstallerAction extends DetSysAction {
return "unavailable"; 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 = { type ExecuteEnvironment = {
@ -990,18 +1013,6 @@ type ExecuteEnvironment = {
NIX_INSTALLER_LOGGER?: string; 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 { function main(): void {
new NixInstallerAction().execute(); new NixInstallerAction().execute();
} }