Skip to content

Commit

Permalink
new github workspace tracking. (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingluoHuang committed Jun 20, 2019
1 parent 9b8601a commit 8ff7f76
Show file tree
Hide file tree
Showing 19 changed files with 736 additions and 1,195 deletions.
2 changes: 2 additions & 0 deletions src/Misc/layoutbin/en-US/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@
"MissingConfig": "Cannot connect to server, because config files are missing. Skipping removing agent from the server.",
"MissingEnvName": "Required field 'name' is missing in ##[set-env] command.",
"MissingOutputName": "Required field 'name' is missing in ##[set-output] command.",
"MissingRepoFullName": "Required field 'repoFullName' is missing in ##[internal-set-repo-path] command.",
"MissingSecretName": "Required field 'name' is missing in ##[set-secret] command.",
"MissingWorkspaceRepo": "Required field 'workspaceRepo' is missing in ##[internal-set-repo-path] command.",
"N": "N",
"NeedAdminForConfigRunnerWinService": "Needs Administrator privileges for configuring runner as windows service.",
"NeedAdminForUnconfigWinServiceRunner": "Needs Administrator privileges for unconfiguring runner that running as windows service.",
Expand Down
102 changes: 3 additions & 99 deletions src/Runner.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,31 +180,14 @@ public static class ReturnCode
public const int RunnerUpdating = 3;
public const int RunOnceRunnerUpdating = 4;
}

public static class AgentConfigurationProvider
{
public static readonly string BuildReleasesAgentConfiguration = "BuildReleasesAgentConfiguration";
public static readonly string DeploymentAgentConfiguration = "DeploymentAgentConfiguration";
public static readonly string SharedDeploymentAgentConfiguration = "SharedDeploymentAgentConfiguration";
}
}

public static class Build
public static class Pipeline
{
public static readonly string NoCICheckInComment = "***NO_CI***";

public static class Path
{
public static readonly string ArtifactsDirectory = "a";
public static readonly string BinariesDirectory = "b";
public static readonly string GarbageCollectionDirectory = "GC";
public static readonly string LegacyArtifactsDirectory = "artifacts";
public static readonly string LegacyStagingDirectory = "staging";
public static readonly string SourceRootMappingDirectory = "SourceRootMapping";
public static readonly string SourcesDirectory = "s";
// public static readonly string TestResultsDirectory = "TestResults";
public static readonly string TopLevelTrackingConfigFile = "Mappings.json";
public static readonly string TrackingConfigFile = "SourceFolder.json";
public static readonly string PipelineMappingDirectory = "_PipelineMapping";
public static readonly string TrackingConfigFile = "PipelineFolder.json";
}
}

Expand All @@ -219,16 +202,6 @@ public static class Configuration
public static readonly string ServiceIdentity = "ServiceIdentity";
}

public static class EndpointData
{
public static readonly string SourcesDirectory = "SourcesDirectory";
public static readonly string SourceVersion = "SourceVersion";
public static readonly string SourceBranch = "SourceBranch";
public static readonly string SourceTfvcShelveset = "SourceTfvcShelveset";
public static readonly string GatedShelvesetName = "GatedShelvesetName";
public static readonly string GatedRunCI = "GatedRunCI";
}

public static class Expressions
{
public static readonly string Always = "always";
Expand Down Expand Up @@ -256,23 +229,6 @@ public static class Path
public static readonly string WorkDirectory = "_work";
}

public static class Release
{
public static readonly string Map = "Map";

public static class Path
{
public static readonly string ArtifactsDirectory = "a";
public static readonly string CommitsDirectory = "c";
public static readonly string DefinitionMapping = "DefinitionMapping.json";
public static readonly string ReleaseDirectoryPrefix = "r";
public static readonly string ReleaseTempDirectoryPrefix = "t";
public static readonly string RootMappingDirectory = "ReleaseRootMapping";
public static readonly string TrackingConfigFile = "DefinitionMapping.json";
public static readonly string GarbageCollectionDirectory = "GC";
}
}

// Related to definition variables.
public static class Variables
{
Expand Down Expand Up @@ -351,53 +307,6 @@ public static class Build
public static readonly string SyncSources = "build.syncSources";
}

public static class Common
{
public static readonly string TestResultsDirectory = "common.testresultsdirectory";
}

public static class Features
{
//
// Keep alphabetical
//
public static readonly string BuildDirectoryClean = "agent.clean.buildDirectory";
public static readonly string GitLfsSupport = "agent.source.git.lfs";
public static readonly string GitShallowDepth = "agent.source.git.shallowFetchDepth";
public static readonly string SkipSyncSource = "agent.source.skip";
}

public static class Pipeline
{
public static readonly string Workspace = "pipeline.workspace";
}

public static class Release
{
//
// Keep alphabetical
//
public static readonly string AgentReleaseDirectory = "agent.releaseDirectory";
public static readonly string ArtifactsDirectory = "system.artifactsDirectory";
public static readonly string AttemptNumber = "release.attemptNumber";
public static readonly string DisableRobocopy = "release.disableRobocopy";
public static readonly string ReleaseDefinitionName = "release.definitionName";
public static readonly string ReleaseEnvironmentName = "release.environmentName";
public static readonly string ReleaseEnvironmentUri = "release.environmentUri";
public static readonly string ReleaseDefinitionId = "release.definitionId";
public static readonly string ReleaseDescription = "release.releaseDescription";
public static readonly string ReleaseId = "release.releaseId";
public static readonly string ReleaseName = "release.releaseName";
public static readonly string ReleaseRequestedForId = "release.requestedForId";
public static readonly string ReleaseUri = "release.releaseUri";
public static readonly string ReleaseDownloadBufferSize = "release.artifact.download.buffersize";
public static readonly string ReleaseParallelDownloadLimit = "release.artifact.download.parallellimit";
public static readonly string ReleaseWebUrl = "release.releaseWebUrl";
public static readonly string RequestorId = "release.requestedFor";
public static readonly string RobocopyMT = "release.robocopyMT";
public static readonly string SkipArtifactsDownload = "release.skipartifactsDownload";
}

public static class System
{
//
Expand All @@ -422,11 +331,6 @@ public static class System
public static readonly string TeamProjectId = "system.teamProjectId";
public static readonly string WorkFolder = "system.workfolder";
}

public static class Task
{
public static readonly string DisplayName = "task.displayname";
}
}
}
}
2 changes: 1 addition & 1 deletion src/Runner.Plugins/RepositoryPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task RunAsync(RunnerActionPluginExecutionContext executionContext,
}

executionContext.Debug($"Update workspace repository location.");
executionContext.UpdateSelfRepositoryPath(expectRepoPath);
executionContext.SetRepositoryPath(repoFullName, expectRepoPath, true);
}

await new GitHubSourceProvider().GetSourceAsync(executionContext, expectRepoPath, token);
Expand Down
4 changes: 2 additions & 2 deletions src/Runner.Sdk/ActionPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ public void Command(string command)
Output($"##[command]{Escape(command)}");
}

public void UpdateSelfRepositoryPath(string path)
public void SetRepositoryPath(string repoName, string path, bool workspaceRepo)
{
Output($"##[internal-set-self-path]{path}");
Output($"##[internal-set-repo-path repoFullName={repoName};workspaceRepo={workspaceRepo.ToString()}]{path}");
}

public String GetRunnerContext(string contextName)
Expand Down
53 changes: 35 additions & 18 deletions src/Runner.Worker/ActionCommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void Initialize(IHostContext hostContext)
{
Trace.Info($"Register action command extension for command {commandExt.Command}");
_commandExtensions[commandExt.Command] = commandExt;
if (commandExt.Command != "internal-set-self-path")
if (commandExt.Command != "internal-set-repo-path")
{
_registeredCommands.Add(commandExt.Command);
}
Expand All @@ -49,13 +49,13 @@ public override void Initialize(IHostContext hostContext)
public void EnablePluginInternalCommand()
{
Trace.Info($"Enable plugin internal command extension.");
_registeredCommands.Add("internal-set-self-path");
_registeredCommands.Add("internal-set-repo-path");
}

public void DisablePluginInternalCommand()
{
Trace.Info($"Disable plugin internal command extension.");
_registeredCommands.Remove("internal-set-self-path");
_registeredCommands.Remove("internal-set-repo-path");
}

public bool TryProcessCommand(IExecutionContext context, string input)
Expand All @@ -77,8 +77,21 @@ public bool TryProcessCommand(IExecutionContext context, string input)
{
if (_stopProcessCommand)
{
context.Debug($"Process commands has been stopped and waiting for '##[{_stopToken}]' to resume.");
return false;
if (!string.IsNullOrEmpty(_stopToken) &&
string.Equals(actionCommand.Command, _stopToken, StringComparison.OrdinalIgnoreCase))
{
context.Output(input);
context.Output($"{WellKnownTags.Debug}Resume processing commands");
_registeredCommands.Remove(_stopToken);
_stopProcessCommand = false;
_stopToken = null;
return true;
}
else
{
context.Debug($"Process commands has been stopped and waiting for '##[{_stopToken}]' to resume.");
return false;
}
}
else
{
Expand All @@ -91,16 +104,6 @@ public bool TryProcessCommand(IExecutionContext context, string input)
_registeredCommands.Add(_stopToken);
return true;
}
else if (!string.IsNullOrEmpty(_stopToken) &&
string.Equals(actionCommand.Command, _stopToken, StringComparison.OrdinalIgnoreCase))
{
context.Output(input);
context.Output($"{WellKnownTags.Debug}Resume processing commands");
_registeredCommands.Remove(_stopToken);
_stopProcessCommand = false;
_stopToken = null;
return true;
}
else if (_commandExtensions.TryGetValue(actionCommand.Command, out IActionCommandExtension extension))
{
bool omitEcho;
Expand Down Expand Up @@ -144,19 +147,33 @@ public interface IActionCommandExtension : IExtension

public sealed class InternalPluginSetRepoPathCommandExtension : RunnerService, IActionCommandExtension
{
public string Command => "internal-set-self-path";
public string Command => "internal-set-repo-path";

public Type ExtensionType => typeof(IActionCommandExtension);

public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, out bool omitEcho)
{
context.SetGitHubContext("workspace", command.Data);
if (!command.Properties.TryGetValue(SetRepoPathCommandProperties.repoFullName, out string repoFullName) || string.IsNullOrEmpty(repoFullName))
{
throw new Exception(StringUtil.Loc("MissingRepoFullName"));
}

if (!command.Properties.TryGetValue(SetRepoPathCommandProperties.workspaceRepo, out string workspaceRepo) || string.IsNullOrEmpty(workspaceRepo))
{
throw new Exception(StringUtil.Loc("MissingWorkspaceRepo"));
}

var directoryManager = HostContext.GetService<IPipelineDirectoryManager>();
var trackingConfig = directoryManager.UpdateDirectory(context);
var trackingConfig = directoryManager.UpdateRepositoryDirectory(context, repoFullName, command.Data, StringUtil.ConvertToBoolean(workspaceRepo));

omitEcho = true;
}

private static class SetRepoPathCommandProperties
{
public const String repoFullName = "repoFullName";
public const String workspaceRepo = "workspaceRepo";
}
}

public sealed class SetEnvCommandExtension : RunnerService, IActionCommandExtension
Expand Down
7 changes: 6 additions & 1 deletion src/Runner.Worker/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ private async Task DownloadRepositoryActionAsync(IExecutionContext executionCont
using (var httpClient = new HttpClient(httpClientHandler))
{
var authToken = Environment.GetEnvironmentVariable("_GITHUB_ACTION_TOKEN");
if (string.IsNullOrEmpty(authToken))
{
authToken = executionContext.Variables.Get("PREVIEW_ACTION_TOKEN");
}

if (!string.IsNullOrEmpty(authToken))
{
HostContext.SecretMasker.AddValue(authToken);
Expand Down Expand Up @@ -350,7 +355,7 @@ private async Task DownloadRepositoryActionAsync(IExecutionContext executionCont

var dockerManger = HostContext.GetService<IDockerCommandManager>();
var imageName = $"{dockerManger.DockerInstanceLabel}:{Guid.NewGuid().ToString("N")}";
var buildExitCode = await dockerManger.DockerBuild(executionContext, Directory.GetParent(dockerFile).FullName, imageName);
var buildExitCode = await dockerManger.DockerBuild(executionContext, destDirectory, Directory.GetParent(dockerFile).FullName, imageName);
if (buildExitCode != 0)
{
throw new InvalidOperationException($"Docker build failed with exit code {buildExitCode}");
Expand Down

0 comments on commit 8ff7f76

Please sign in to comment.