From abc65839f38c4455ec7c50a6667487fdd11be307 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Mon, 6 Jan 2020 12:56:15 -0500 Subject: [PATCH] detect source file path without using env. (#257) --- src/Test/L0/TestUtil.cs | 14 ++++++++++---- src/Test/L0/Worker/ActionManagerL0.cs | 2 +- src/dev.sh | 2 -- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Test/L0/TestUtil.cs b/src/Test/L0/TestUtil.cs index 101dedee7..c6c60be56 100644 --- a/src/Test/L0/TestUtil.cs +++ b/src/Test/L0/TestUtil.cs @@ -1,8 +1,7 @@ -using GitHub.Runner.Common.Util; -using System.IO; +using System.IO; using Xunit; -using System; using GitHub.Runner.Sdk; +using System.Runtime.CompilerServices; namespace GitHub.Runner.Common.Tests { @@ -21,9 +20,16 @@ namespace GitHub.Runner.Common.Tests return projectDir; } + public static string GetTestFilePath([CallerFilePath] string path = null) + { + return path; + } + public static string GetSrcPath() { - string srcDir = Environment.GetEnvironmentVariable("GITHUB_RUNNER_SRC_DIR"); + string L0dir = Path.GetDirectoryName(GetTestFilePath()); + string testDir = Path.GetDirectoryName(L0dir); + string srcDir = Path.GetDirectoryName(testDir); ArgUtil.Directory(srcDir, nameof(srcDir)); Assert.Equal(Src, Path.GetFileName(srcDir)); return srcDir; diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index ed3f1b065..0f73d52a9 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -125,7 +125,7 @@ namespace GitHub.Runner.Common.Tests.Worker Directory.CreateDirectory(Path.GetDirectoryName(watermarkFile)); File.WriteAllText(watermarkFile, DateTime.UtcNow.ToString()); Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(watermarkFile), "notexist")); - File.Copy(Path.Combine(Environment.GetEnvironmentVariable("GITHUB_RUNNER_SRC_DIR"), "Test", TestDataFolderName, "dockerfileaction.yml"), Path.Combine(Path.GetDirectoryName(watermarkFile), "notexist", "action.yml")); + File.Copy(Path.Combine(TestUtil.GetSrcPath(), "Test", TestDataFolderName, "dockerfileaction.yml"), Path.Combine(Path.GetDirectoryName(watermarkFile), "notexist", "action.yml")); //Act await _actionManager.PrepareActionsAsync(_ec.Object, actions); diff --git a/src/dev.sh b/src/dev.sh index 37e3fac7e..43474c68c 100755 --- a/src/dev.sh +++ b/src/dev.sh @@ -137,8 +137,6 @@ function runtest () ulimit -n 1024 fi - export GITHUB_RUNNER_SRC_DIR=${SCRIPT_DIR} - dotnet msbuild -t:test -p:PackageRuntime="${RUNTIME_ID}" -p:BUILDCONFIG="${BUILD_CONFIG}" -p:RunnerVersion="${RUNNER_VERSION}" ./dir.proj || failed "failed tests" }