Commit b22b1f48 authored by Vincent Haupert's avatar Vincent Haupert Committed by Vincent Haupert
Browse files

github-runner: patch access to `.env` and `.path`

parent 2f813ae1
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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=()
+76 −0
Original line number Diff line number Diff line
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