mirror of
https://github.com/actions/runner.git
synced 2025-12-12 14:17:46 +00:00
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:
@@ -1355,6 +1355,12 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
foreach (var key in dict.Keys.ToList())
|
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)
|
if (dict[key] is StringContextData)
|
||||||
{
|
{
|
||||||
var value = dict[key].ToString();
|
var value = dict[key].ToString();
|
||||||
|
|||||||
@@ -26,11 +26,18 @@ namespace GitHub.Runner.Worker.Expressions
|
|||||||
ArgUtil.NotNull(githubContextData, nameof(githubContextData));
|
ArgUtil.NotNull(githubContextData, nameof(githubContextData));
|
||||||
var githubContext = githubContextData as DictionaryContextData;
|
var githubContext = githubContextData as DictionaryContextData;
|
||||||
ArgUtil.NotNull(githubContext, nameof(githubContext));
|
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;
|
var workspaceData = workspace as StringContextData;
|
||||||
ArgUtil.NotNull(workspaceData, nameof(workspaceData));
|
ArgUtil.NotNull(workspaceData, nameof(workspaceData));
|
||||||
|
|
||||||
string githubWorkspace = workspaceData.Value;
|
string githubWorkspace = workspaceData.Value;
|
||||||
|
|
||||||
bool followSymlink = false;
|
bool followSymlink = false;
|
||||||
List<string> patterns = new();
|
List<string> patterns = new();
|
||||||
var firstParameter = true;
|
var firstParameter = true;
|
||||||
|
|||||||
@@ -175,7 +175,14 @@ namespace GitHub.Runner.Worker
|
|||||||
context.Debug("Update context data");
|
context.Debug("Update context data");
|
||||||
string _workDirectory = HostContext.GetDirectory(WellKnownDirectory.Work);
|
string _workDirectory = HostContext.GetDirectory(WellKnownDirectory.Work);
|
||||||
context.SetRunnerContext("workspace", Path.Combine(_workDirectory, trackingConfig.PipelineDirectory));
|
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
|
// Temporary hack for GHES alpha
|
||||||
var configurationStore = HostContext.GetService<IConfigurationStore>();
|
var configurationStore = HostContext.GetService<IConfigurationStore>();
|
||||||
|
|||||||
@@ -82,5 +82,6 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating
|
|||||||
public const String WorkflowRoot = "workflow-root";
|
public const String WorkflowRoot = "workflow-root";
|
||||||
public const String WorkingDirectory = "working-directory";
|
public const String WorkingDirectory = "working-directory";
|
||||||
public const String Workspace = "workspace";
|
public const String Workspace = "workspace";
|
||||||
|
public const String HostWorkspace = "host-workspace";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user