From 75ffa7fc743135e1db864b699d78402ccc8ed988 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sat, 18 May 2024 18:46:09 -0400 Subject: [PATCH] Disable docker under act (#90) * Rename IN_GITHUB_ACTIONS to IN_ACT * If the trusted runner user is truthy, setup the runner as a trusted user. The boolean option is always set. * Set HAS_SYSTEMD in more cases * Unquote trust-runner-user in the action.yml * Don't bother with the docker shim under act * fmt * Regenerate * fixup --- action.yml | 2 +- dist/index.js | 14 ++++++++++---- src/index.ts | 15 +++++++++++---- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index b44d1ed..4322016 100644 --- a/action.yml +++ b/action.yml @@ -113,7 +113,7 @@ inputs: default: "https://install.determinate.systems/nix-installer/diagnostic" trust-runner-user: description: Whether to make the runner user trusted by the Nix daemon - default: "true" + default: true nix-installer-branch: description: (deprecated) The branch of `nix-installer` to use (conflicts with `nix-installer-tag`, `nix-installer-revision`, `nix-installer-pr`) required: false diff --git a/dist/index.js b/dist/index.js index c590610..aa83945 100644 --- a/dist/index.js +++ b/dist/index.js @@ -97332,7 +97332,7 @@ var EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub"; var EVENT_CONCLUDE_WORKFLOW = "conclude_workflow"; var FACT_HAS_DOCKER = "has_docker"; var FACT_HAS_SYSTEMD = "has_systemd"; -var FACT_IN_GITHUB_ACTIONS = "in_act"; +var FACT_IN_ACT = "in_act"; var FACT_IN_NAMESPACE_SO = "in_namespace_so"; var FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner"; var NixInstallerAction = class { @@ -97385,16 +97385,22 @@ var NixInstallerAction = class { } return; } + if (process.env["ACT"] && !process.env["NOT_ACT"]) { + core.debug( + "Not bothering to detect if the docker shim should be used, as it is typically incompatible with act." + ); + return; + } const systemdCheck = external_node_fs_namespaceObject.statSync("/run/systemd/system", { throwIfNoEntry: false }); if (systemdCheck?.isDirectory()) { + this.idslib.addFact(FACT_HAS_SYSTEMD, true); if (this.forceDockerShim) { core.warning( "Systemd is detected, but ignoring it since force-docker-shim is enabled." ); } else { - this.idslib.addFact(FACT_HAS_SYSTEMD, true); return; } } @@ -97638,7 +97644,7 @@ ${stderrBuffer}` extraConf += `access-tokens = ${serverUrl}=${this.githubToken}`; extraConf += "\n"; } - if (this.trustRunnerUser !== null) { + if (this.trustRunnerUser) { const user = (0,external_node_os_.userInfo)().username; if (user) { extraConf += `trusted-users = root ${user}`; @@ -97662,7 +97668,7 @@ ${stderrBuffer}` } executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; if (process.env["ACT"] && !process.env["NOT_ACT"]) { - this.idslib.addFact(FACT_IN_GITHUB_ACTIONS, true); + this.idslib.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`" ); diff --git a/src/index.ts b/src/index.ts index 5b8a326..8f1dbe4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,7 @@ const EVENT_CONCLUDE_WORKFLOW = "conclude_workflow"; // Facts const FACT_HAS_DOCKER = "has_docker"; const FACT_HAS_SYSTEMD = "has_systemd"; -const FACT_IN_GITHUB_ACTIONS = "in_act"; +const FACT_IN_ACT = "in_act"; const FACT_IN_NAMESPACE_SO = "in_namespace_so"; const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner"; @@ -123,16 +123,23 @@ class NixInstallerAction { return; } + if (process.env["ACT"] && !process.env["NOT_ACT"]) { + actionsCore.debug( + "Not bothering to detect if the docker shim should be used, as it is typically incompatible with act.", + ); + return; + } + const systemdCheck = fs.statSync("/run/systemd/system", { throwIfNoEntry: false, }); if (systemdCheck?.isDirectory()) { + this.idslib.addFact(FACT_HAS_SYSTEMD, true); if (this.forceDockerShim) { actionsCore.warning( "Systemd is detected, but ignoring it since force-docker-shim is enabled.", ); } else { - this.idslib.addFact(FACT_HAS_SYSTEMD, true); return; } } @@ -428,7 +435,7 @@ class NixInstallerAction { extraConf += `access-tokens = ${serverUrl}=${this.githubToken}`; extraConf += "\n"; } - if (this.trustRunnerUser !== null) { + if (this.trustRunnerUser) { const user = userInfo().username; if (user) { extraConf += `trusted-users = root ${user}`; @@ -453,7 +460,7 @@ class NixInstallerAction { executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; if (process.env["ACT"] && !process.env["NOT_ACT"]) { - this.idslib.addFact(FACT_IN_GITHUB_ACTIONS, true); + this.idslib.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`", );