Extend github context with host-workspace (#2517)

* hash files translation works with host context translated

* Change file encoding to utf8 for PipelineTemplateConstants.cs

* infer the feature flag on hash files based on the existence of the context

* encoded utf8 with bom

* rename host-workspace to host-work-directory and feature flag the new context var

* Added comment to explain ignore host work directory resolution

Co-authored-by: fhammerl <fhammerl@github.com>

* trigger pipeline

* Move to the github host-workspace context instead of the runner host-work-directory

* remove unused imports

---------

Co-authored-by: fhammerl <fhammerl@github.com>
This commit is contained in:
Nikola Jokic
2023-06-29 12:12:23 +02:00
committed by GitHub
parent a2b7856c9c
commit c05e6748c3
4 changed files with 23 additions and 2 deletions

View File

@@ -1355,6 +1355,12 @@ namespace GitHub.Runner.Worker
{
foreach (var key in dict.Keys.ToList())
{
if (key == PipelineTemplateConstants.HostWorkspace)
{
// The HostWorkspace context var is excluded so that there is a var that always points to the host path.
// This var can be used to translate back from container paths, e.g. in HashFilesFunction, which always runs on the host machine
continue;
}
if (dict[key] is StringContextData)
{
var value = dict[key].ToString();

View File

@@ -26,11 +26,18 @@ namespace GitHub.Runner.Worker.Expressions
ArgUtil.NotNull(githubContextData, nameof(githubContextData));
var githubContext = githubContextData as DictionaryContextData;
ArgUtil.NotNull(githubContext, nameof(githubContext));
githubContext.TryGetValue(PipelineTemplateConstants.Workspace, out var workspace);
if (!githubContext.TryGetValue(PipelineTemplateConstants.HostWorkspace, out var workspace))
{
githubContext.TryGetValue(PipelineTemplateConstants.Workspace, out workspace);
}
ArgUtil.NotNull(workspace, nameof(workspace));
var workspaceData = workspace as StringContextData;
ArgUtil.NotNull(workspaceData, nameof(workspaceData));
string githubWorkspace = workspaceData.Value;
bool followSymlink = false;
List<string> patterns = new();
var firstParameter = true;

View File

@@ -175,7 +175,14 @@ namespace GitHub.Runner.Worker
context.Debug("Update context data");
string _workDirectory = HostContext.GetDirectory(WellKnownDirectory.Work);
context.SetRunnerContext("workspace", Path.Combine(_workDirectory, trackingConfig.PipelineDirectory));
context.SetGitHubContext("workspace", Path.Combine(_workDirectory, trackingConfig.WorkspaceDirectory));
var githubWorkspace = Path.Combine(_workDirectory, trackingConfig.WorkspaceDirectory);
if (jobContext.Global.Variables.GetBoolean(Constants.Runner.Features.UseContainerPathForTemplate) ?? false)
{
// This value is used to translate paths from the container path back to the host path.
context.SetGitHubContext("host-workspace", githubWorkspace);
}
context.SetGitHubContext("workspace", githubWorkspace);
// Temporary hack for GHES alpha
var configurationStore = HostContext.GetService<IConfigurationStore>();

View File

@@ -82,5 +82,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
public const String WorkflowRoot = "workflow-root";
public const String WorkingDirectory = "working-directory";
public const String Workspace = "workspace";
public const String HostWorkspace = "host-workspace";
}
}