Skip to content

Commit

Permalink
load and print machine setup info from .setup_info (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingluoHuang authored Mar 11, 2020
1 parent d34afb5 commit f9b5d62
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Runner.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum WellKnownConfigFile
CredentialStore,
Certificates,
Options,
SetupInfo,
}

public static class Constants
Expand Down
7 changes: 7 additions & 0 deletions src/Runner.Common/HostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ public string GetConfigFile(WellKnownConfigFile configFile)
GetDirectory(WellKnownDirectory.Root),
".options");
break;

case WellKnownConfigFile.SetupInfo:
path = Path.Combine(
GetDirectory(WellKnownDirectory.Root),
".setup_info");
break;

default:
throw new NotSupportedException($"Unexpected well known config file: '{configFile}'");
}
Expand Down
49 changes: 49 additions & 0 deletions src/Runner.Worker/JobExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using GitHub.DistributedTask.Expressions2;
using GitHub.DistributedTask.Pipelines.ObjectTemplating;
Expand All @@ -14,6 +15,16 @@

namespace GitHub.Runner.Worker
{
[DataContract]
public class SetupInfo
{
[DataMember]
public string Group { get; set; }

[DataMember]
public string Detail { get; set; }
}

[ServiceLocator(Default = typeof(JobExtension))]

public interface IJobExtension : IRunnerService
Expand Down Expand Up @@ -49,6 +60,44 @@ public async Task<List<IStep>> InitializeJob(IExecutionContext jobContext, Pipel
context.Start();
context.Debug($"Starting: Set up job");
context.Output($"Current runner version: '{BuildConstants.RunnerPackage.Version}'");

var setupInfoFile = HostContext.GetConfigFile(WellKnownConfigFile.SetupInfo);
if (File.Exists(setupInfoFile))
{
Trace.Info($"Load machine setup info from {setupInfoFile}");
try
{
var setupInfo = IOUtil.LoadObject<List<SetupInfo>>(setupInfoFile);
if (setupInfo?.Count > 0)
{
foreach (var info in setupInfo)
{
if (!string.IsNullOrEmpty(info?.Detail))
{
var groupName = info.Group;
if (string.IsNullOrEmpty(groupName))
{
groupName = "Machine Setup Info";
}

context.Output($"##[group]{groupName}");
var multiLines = info.Detail.Replace("\r\n", "\n").TrimEnd('\n').Split('\n');
foreach (var line in multiLines)
{
context.Output(line);
}
context.Output("##[endgroup]");
}
}
}
}
catch (Exception ex)
{
context.Output($"Fail to load and print machine setup info: {ex.Message}");
Trace.Error(ex);
}
}

var repoFullName = context.GetGitHubContext("repository");
ArgUtil.NotNull(repoFullName, nameof(repoFullName));
context.Debug($"Primary repository: {repoFullName}");
Expand Down
7 changes: 7 additions & 0 deletions src/Test/L0/TestHostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ public string GetConfigFile(WellKnownConfigFile configFile)
GetDirectory(WellKnownDirectory.Root),
".options");
break;

case WellKnownConfigFile.SetupInfo:
path = Path.Combine(
GetDirectory(WellKnownDirectory.Root),
".setup_info");
break;

default:
throw new NotSupportedException($"Unexpected well known config file: '{configFile}'");
}
Expand Down

0 comments on commit f9b5d62

Please sign in to comment.