Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/t maste/write to disk #30

Merged
merged 4 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Runner.Worker/ActionRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR seems fine to me. Make sure Ting is happy with it before merging.

using System.Linq;
using System.Threading.Tasks;
using GitHub.DistributedTask.Expressions;
Expand Down Expand Up @@ -55,6 +56,21 @@ public async Task RunAsync()

IStepHost stepHost = HostContext.CreateService<IDefaultStepHost>();

// Makes directory for event_path data
var tempDirectory = HostContext.GetDirectory(WellKnownDirectory.Temp);
var workflowDirectory = Path.Combine(tempDirectory, "workflow");
Directory.CreateDirectory(workflowDirectory);

var gitHubEvent = ExecutionContext.GetGitHubContext("event");

// adds the GitHub event path/file if the event exists
if (gitHubEvent != null)
{
var workflowFile = Path.Combine(workflowDirectory, "event.json");
File.WriteAllText(workflowFile, gitHubEvent);
mesternefeld marked this conversation as resolved.
Show resolved Hide resolved
ExecutionContext.SetGitHubContext("event_path", workflowFile);
}

// Setup container stephost for running inside the container.
if (ExecutionContext.Container != null)
{
Expand Down
13 changes: 12 additions & 1 deletion src/Runner.Worker/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,14 @@ public string GetGitHubContext(string name)
var githubContext = ExpressionValues["github"] as GitHubContext;
if (githubContext.TryGetValue(name, out var value))
{
return value as StringContextData;
if (value is StringContextData)
{
return value as StringContextData;
}
else
{
return value.ToJToken().ToString();;
mesternefeld marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
{
Expand Down Expand Up @@ -563,14 +570,18 @@ public void InitializeJob(Pipelines.AgentJobRequestMessage message, Cancellation
// GITHUB_ACTION=dump.env
githubContext["action"] = new StringContextData(Variables.Build_Number);

githubContext["event"] = new StringContextData("testing");
mesternefeld marked this conversation as resolved.
Show resolved Hide resolved

// GITHUB_EVENT_PATH=/github/workflow/event.json
}
else
{
var githubContext = new GitHubContext();
var ghDictionary = (DictionaryContextData)ExpressionValues["github"];
Trace.Info("Testing GitHub Keys");
mesternefeld marked this conversation as resolved.
Show resolved Hide resolved
foreach (var pair in ghDictionary)
{
Trace.Info(pair.Key);
mesternefeld marked this conversation as resolved.
Show resolved Hide resolved
githubContext.Add(pair.Key, pair.Value);
}

Expand Down
14 changes: 14 additions & 0 deletions src/Sdk/DTPipelines/Pipelines/ContextData/ArrayContextData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.Serialization;
using GitHub.Services.WebApi.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Expressions = GitHub.DistributedTask.Expressions;

namespace GitHub.DistributedTask.Pipelines.ContextData
Expand Down Expand Up @@ -51,6 +52,19 @@ public override PipelineContextData Clone()
return result;
}

public override JToken ToJToken()
{
var result = new JArray();
if (m_items?.Count > 0)
{
foreach (var item in m_items)
{
result.Add(item.ToJToken());
}
}
return result;
}

public IEnumerator<PipelineContextData> GetEnumerator()
{
if (m_items?.Count > 0)
Expand Down
14 changes: 14 additions & 0 deletions src/Sdk/DTPipelines/Pipelines/ContextData/DictionaryContextData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.Serialization;
using GitHub.Services.WebApi.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Expressions = GitHub.DistributedTask.Expressions;

namespace GitHub.DistributedTask.Pipelines.ContextData
Expand Down Expand Up @@ -174,6 +175,19 @@ public override PipelineContextData Clone()
return result;
}

public override JToken ToJToken()
{
var json = new JObject();
if (m_list?.Count > 0)
{
foreach (var item in m_list)
{
json.Add(item.Key, item.Value.ToJToken());
}
}
return json;
}

public Boolean ContainsKey(String key)
{
return TryGetValue(key, out _);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.Serialization;
using GitHub.Services.WebApi.Internal;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace GitHub.DistributedTask.Pipelines.ContextData
{
Expand All @@ -24,5 +25,7 @@ protected PipelineContextData(Int32 type)
internal Int32 Type { get; }

public abstract PipelineContextData Clone();

public abstract JToken ToJToken();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.Serialization;
using GitHub.DistributedTask.Expressions;
using GitHub.Services.WebApi.Internal;
using Newtonsoft.Json.Linq;

namespace GitHub.DistributedTask.Pipelines.ContextData
{
Expand Down Expand Up @@ -35,6 +36,11 @@ public override PipelineContextData Clone()
return new StringContextData(m_value);
}

public override JToken ToJToken()
{
return (JToken) m_value;
}

String IString.GetString()
{
return Value;
Expand Down