From 9c4e8b237e1d6c4b38db9a2ade8f5d224c88ad42 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Wed, 29 May 2024 15:51:33 -0300 Subject: [PATCH] Provide better if statement --- dist/index.js | 11 +++++++---- src/index.ts | 15 +++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index f4a7a92..598f7bd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -97864,9 +97864,12 @@ var NixInstallerAction = class extends DetSysAction { get isLinux() { return this.runnerOs === "Linux"; } - get isAct() { + get runningInAct() { return process.env["ACT"] !== "" && !(process.env["NOT_ACT"] === ""); } + get runningInNamespaceRunner() { + return process.env["NSC_VM_ID"] !== void 0 && !(process.env["NOT_NAMESPACE"] === "true"); + } async detectAndForceDockerShim() { if (this.isLinux) { if (this.forceDockerShim) { @@ -97877,7 +97880,7 @@ var NixInstallerAction = class extends DetSysAction { } return; } - if (this.isAct) { + if (this.runningInAct) { core.debug( "Not bothering to detect if the docker shim should be used, as it is typically incompatible with act." ); @@ -98158,14 +98161,14 @@ ${stderrBuffer}` extraConf += "\n"; } executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; - if (process.env["ACT"] && !process.env["NOT_ACT"]) { + if (this.runningInAct) { this.addFact(FACT_IN_ACT, true); core.info( "Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`" ); executionEnv.NIX_INSTALLER_INIT = "none"; } - if (process.env["NSC_VM_ID"] && !process.env["NOT_NAMESPACE"]) { + if (this.runningInNamespaceRunner) { this.addFact(FACT_IN_NAMESPACE_SO, true); core.info( "Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace" diff --git a/src/index.ts b/src/index.ts index 2405a4a..e43960f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -133,10 +133,17 @@ class NixInstallerAction extends DetSysAction { return this.runnerOs === "Linux"; } - private get isAct(): boolean { + private get runningInAct(): boolean { return process.env["ACT"] !== "" && !(process.env["NOT_ACT"] === ""); } + private get runningInNamespaceRunner(): boolean { + return ( + process.env["NSC_VM_ID"] !== undefined && + !(process.env["NOT_NAMESPACE"] === "true") + ); + } + async detectAndForceDockerShim(): Promise { // 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/), @@ -151,7 +158,7 @@ class NixInstallerAction extends DetSysAction { return; } - if (this.isAct) { + if (this.runningInAct) { actionsCore.debug( "Not bothering to detect if the docker shim should be used, as it is typically incompatible with act.", ); @@ -486,7 +493,7 @@ class NixInstallerAction extends DetSysAction { } executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; - if (process.env["ACT"] && !process.env["NOT_ACT"]) { + if (this.runningInAct) { this.addFact(FACT_IN_ACT, true); actionsCore.info( "Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`", @@ -494,7 +501,7 @@ class NixInstallerAction extends DetSysAction { executionEnv.NIX_INSTALLER_INIT = "none"; } - if (process.env["NSC_VM_ID"] && !process.env["NOT_NAMESPACE"]) { + if (this.runningInNamespaceRunner) { this.addFact(FACT_IN_NAMESPACE_SO, true); actionsCore.info( "Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace",