1 From 84b2fcdf042771ae8adc0f59f1a3ecd9788a808d Mon Sep 17 00:00:00 2001
2 From: Vincent Haupert <mail@vincent-haupert.de>
3 Date: Sun, 26 Feb 2023 11:37:01 +0100
4 Subject: [PATCH] Access `.env` and `.path` relative to `$RUNNER_ROOT`, if set
7 src/Misc/layoutbin/runsvc.sh | 4 ++--
8 src/Misc/layoutroot/env.sh | 10 +++++-----
9 src/Runner.Listener/Program.cs | 2 +-
10 3 files changed, 8 insertions(+), 8 deletions(-)
12 diff --git a/src/Misc/layoutbin/runsvc.sh b/src/Misc/layoutbin/runsvc.sh
13 index c135645..bb0fbf6 100755
14 --- a/src/Misc/layoutbin/runsvc.sh
15 +++ b/src/Misc/layoutbin/runsvc.sh
17 # for more info on how to propagate SIGTERM to a child process see: http://veithen.github.io/2014/11/16/sigterm-propagation.html
18 trap 'kill -INT $PID' TERM INT
20 -if [ -f ".path" ]; then
21 +if [ -f "${RUNNER_ROOT:-"."}/.path" ]; then
23 - export PATH=`cat .path`
24 + export PATH=`cat "${RUNNER_ROOT:-"."}/.path"`
28 diff --git a/src/Misc/layoutroot/env.sh b/src/Misc/layoutroot/env.sh
29 index 641d244..85379bf 100755
30 --- a/src/Misc/layoutroot/env.sh
31 +++ b/src/Misc/layoutroot/env.sh
32 @@ -16,10 +16,10 @@ varCheckList=(
36 -if [ -f ".env" ]; then
37 - envContents=`cat .env`
38 +if [ -f "${RUNNER_ROOT:-"."}/.env" ]; then
39 + envContents=`cat "${RUNNER_ROOT:-"."}/.env"`
42 + touch "${RUNNER_ROOT:-"."}/.env"
46 @@ -29,12 +29,12 @@ function writeVar()
47 if test "${envContents#*$checkDelim}" = "$envContents"
49 if [ ! -z "${!checkVar}" ]; then
50 - echo "${checkVar}=${!checkVar}">>.env
51 + echo "${checkVar}=${!checkVar}">>"${RUNNER_ROOT:-"."}/.env"
57 +echo $PATH>"${RUNNER_ROOT:-"."}/.path"
59 for var_name in ${varCheckList[@]}
61 diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs
62 index d4d5e43..beacc9d 100644
63 --- a/src/Runner.Listener/Program.cs
64 +++ b/src/Runner.Listener/Program.cs
65 @@ -148,7 +148,7 @@ namespace GitHub.Runner.Listener
66 private static void LoadAndSetEnv()
68 var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
69 - var rootDir = new DirectoryInfo(binDir).Parent.FullName;
70 + var rootDir = Environment.GetEnvironmentVariable("RUNNER_ROOT") ?? new DirectoryInfo(binDir).Parent.FullName;
71 string envFile = Path.Combine(rootDir, ".env");
72 if (File.Exists(envFile))