about summary refs log tree commit diff
path: root/pkgs/development/tools/continuous-integration
diff options
context:
space:
mode:
authorVincent Haupert <mail@vincent-haupert.de>2023-02-26 12:58:42 +0100
committerVincent Haupert <vincent@yaxi.tech>2023-02-26 15:39:18 +0100
commitb22b1f4874a1614307b4efa8d5309301832685e4 (patch)
treeee4c2200a143dbb427562e4fce60b1b7b0d907aa /pkgs/development/tools/continuous-integration
parent2f813ae18b27bd926595be2b9e9e7f7e696af193 (diff)
github-runner: patch access to `.env` and `.path`
Diffstat (limited to 'pkgs/development/tools/continuous-integration')
-rw-r--r--pkgs/development/tools/continuous-integration/github-runner/default.nix11
-rw-r--r--pkgs/development/tools/continuous-integration/github-runner/patches/env-sh-use-runner-root.patch76
2 files changed, 81 insertions, 6 deletions
diff --git a/pkgs/development/tools/continuous-integration/github-runner/default.nix b/pkgs/development/tools/continuous-integration/github-runner/default.nix
index 979701ef26659..91b593f729430 100644
--- a/pkgs/development/tools/continuous-integration/github-runner/default.nix
+++ b/pkgs/development/tools/continuous-integration/github-runner/default.nix
@@ -33,6 +33,8 @@ buildDotnetModule rec {
     ./patches/use-get-directory-for-diag.patch
     # Don't try to install service
     ./patches/dont-install-service.patch
+    # Access `.env` and `.path` relative to `$RUNNER_ROOT`, if set
+    ./patches/env-sh-use-runner-root.patch
     # Fix FHS path: https://github.com/actions/runner/pull/2464
     (fetchpatch {
       name = "ln-fhs.patch";
@@ -166,6 +168,9 @@ buildDotnetModule rec {
     install -m755 src/Misc/layoutroot/config.sh                $out/lib/github-runner
     install -m755 src/Misc/layoutroot/env.sh                   $out/lib/github-runner
 
+    # env.sh is patched to not require any wrapping
+    ln -sr "$out/lib/github-runner/env.sh" "$out/bin/"
+
     substituteInPlace $out/lib/github-runner/config.sh \
       --replace './bin/Runner.Listener' "$out/bin/Runner.Listener"
   '' + lib.optionalString stdenv.isLinux ''
@@ -193,12 +198,6 @@ buildDotnetModule rec {
     install -D src/Misc/layoutbin/hashFiles/index.js $out/lib/github-runner/hashFiles/index.js
     mkdir -p $out/lib/github-runner/checkScripts
     install src/Misc/layoutbin/checkScripts/* $out/lib/github-runner/checkScripts/
-
-    # Use $RUNNER_ROOT in env.sh, if set
-    substituteInPlace "$out/lib/github-runner/env.sh" \
-      --replace '.env'  ' ''${RUNNER_ROOT:-.}/.env' \
-      --replace '.path' ' ''${RUNNER_ROOT:-.}/.path'
-    ln -s "$out/lib/github-runner/env.sh" "$out/bin/env.sh"
   '' + lib.optionalString stdenv.isLinux ''
     # Wrap explicitly to, e.g., prevent extra entries for LD_LIBRARY_PATH
     makeWrapperArgs=()
diff --git a/pkgs/development/tools/continuous-integration/github-runner/patches/env-sh-use-runner-root.patch b/pkgs/development/tools/continuous-integration/github-runner/patches/env-sh-use-runner-root.patch
new file mode 100644
index 0000000000000..d87e00d0f349b
--- /dev/null
+++ b/pkgs/development/tools/continuous-integration/github-runner/patches/env-sh-use-runner-root.patch
@@ -0,0 +1,76 @@
+From 84b2fcdf042771ae8adc0f59f1a3ecd9788a808d Mon Sep 17 00:00:00 2001
+From: Vincent Haupert <mail@vincent-haupert.de>
+Date: Sun, 26 Feb 2023 11:37:01 +0100
+Subject: [PATCH] Access `.env` and `.path` relative to `$RUNNER_ROOT`, if set
+
+---
+ src/Misc/layoutbin/runsvc.sh   |  4 ++--
+ src/Misc/layoutroot/env.sh     | 10 +++++-----
+ src/Runner.Listener/Program.cs |  2 +-
+ 3 files changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/src/Misc/layoutbin/runsvc.sh b/src/Misc/layoutbin/runsvc.sh
+index c135645..bb0fbf6 100755
+--- a/src/Misc/layoutbin/runsvc.sh
++++ b/src/Misc/layoutbin/runsvc.sh
+@@ -4,9 +4,9 @@
+ # for more info on how to propagate SIGTERM to a child process see: http://veithen.github.io/2014/11/16/sigterm-propagation.html
+ trap 'kill -INT $PID' TERM INT
+ 
+-if [ -f ".path" ]; then
++if [ -f "${RUNNER_ROOT:-"."}/.path" ]; then
+     # configure
+-    export PATH=`cat .path`
++    export PATH=`cat "${RUNNER_ROOT:-"."}/.path"`
+     echo ".path=${PATH}"
+ fi
+ 
+diff --git a/src/Misc/layoutroot/env.sh b/src/Misc/layoutroot/env.sh
+index 641d244..85379bf 100755
+--- a/src/Misc/layoutroot/env.sh
++++ b/src/Misc/layoutroot/env.sh
+@@ -16,10 +16,10 @@ varCheckList=(
+ 
+ envContents=""
+ 
+-if [ -f ".env" ]; then
+-    envContents=`cat .env`
++if [ -f "${RUNNER_ROOT:-"."}/.env" ]; then
++    envContents=`cat "${RUNNER_ROOT:-"."}/.env"`
+ else
+-    touch .env
++    touch "${RUNNER_ROOT:-"."}/.env"
+ fi
+ 
+ function writeVar()
+@@ -29,12 +29,12 @@ function writeVar()
+     if test "${envContents#*$checkDelim}" = "$envContents"
+     then
+         if [ ! -z "${!checkVar}" ]; then
+-            echo "${checkVar}=${!checkVar}">>.env
++            echo "${checkVar}=${!checkVar}">>"${RUNNER_ROOT:-"."}/.env"
+         fi
+     fi 
+ }
+ 
+-echo $PATH>.path
++echo $PATH>"${RUNNER_ROOT:-"."}/.path"
+ 
+ for var_name in ${varCheckList[@]}
+ do
+diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs
+index d4d5e43..beacc9d 100644
+--- a/src/Runner.Listener/Program.cs
++++ b/src/Runner.Listener/Program.cs
+@@ -148,7 +148,7 @@ namespace GitHub.Runner.Listener
+         private static void LoadAndSetEnv()
+         {
+             var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
+-            var rootDir = new DirectoryInfo(binDir).Parent.FullName;
++            var rootDir = Environment.GetEnvironmentVariable("RUNNER_ROOT") ?? new DirectoryInfo(binDir).Parent.FullName;
+             string envFile = Path.Combine(rootDir, ".env");
+             if (File.Exists(envFile))
+             {
+-- 
+2.38.1
+