From b008639bbeb32aaab1c2d9b992c42f0f94a7dfd1 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Sat, 7 Oct 2023 15:21:08 +0200 Subject: [PATCH] make async --- src/Sdk/AzurePipelines/AzureDevops.cs | 41 ++++++++++--------- src/Sdk/AzurePipelines/DefaultFileProvider.cs | 6 ++- src/Sdk/AzurePipelines/IFileProvider.cs | 4 +- .../AzurePipelines/InMemoryFileProvider.cs | 9 ++-- src/Sdk/AzurePipelines/Job.cs | 35 ++++++++-------- src/Sdk/AzurePipelines/Pipeline.cs | 15 +++---- src/Sdk/AzurePipelines/Stage.cs | 15 +++---- src/Sdk/AzurePipelines/Strategy.cs | 5 ++- src/Sdk/Sdk.csproj | 2 +- 9 files changed, 71 insertions(+), 61 deletions(-) diff --git a/src/Sdk/AzurePipelines/AzureDevops.cs b/src/Sdk/AzurePipelines/AzureDevops.cs index a69b8e3071f..6ab24b575bf 100644 --- a/src/Sdk/AzurePipelines/AzureDevops.cs +++ b/src/Sdk/AzurePipelines/AzureDevops.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading; +using System.Threading.Tasks; using GitHub.DistributedTask.Expressions2; using GitHub.DistributedTask.Expressions2.Sdk.Functions.v1; using GitHub.DistributedTask.ObjectTemplating; @@ -55,7 +56,7 @@ public static TemplateContext CreateTemplateContext(GitHub.DistributedTask.Objec return templateContext; } - public static void ParseVariables(Runner.Server.Azure.Devops.Context context, IDictionary vars, TemplateToken rawvars, bool onlyStaticVars = false) { + public static async Task ParseVariables(Runner.Server.Azure.Devops.Context context, IDictionary vars, TemplateToken rawvars, bool onlyStaticVars = false) { if(rawvars is MappingToken mvars) { foreach(var kv in mvars) { // Skip expressions if we parse static variables @@ -116,15 +117,15 @@ public static void ParseVariables(Runner.Server.Azure.Devops.Context context, ID } } } else if(template != null) { - var file = ReadTemplate(context, template, parameters != null ? parameters.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "variable-template-root"); - ParseVariables(context.ChildContext(file, template), vars, (from e in file where e.Key.AssertString("").Value == "variables" select e.Value).First()); + var file = await ReadTemplate(context, template, parameters != null ? parameters.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "variable-template-root"); + await ParseVariables(context.ChildContext(file, template), vars, (from e in file where e.Key.AssertString("").Value == "variables" select e.Value).First()); } else { vars[name] = new VariableValue(value, isReadonly: isReadonly); } } } } - public static void ParseSteps(Runner.Server.Azure.Devops.Context context, IList steps, TemplateToken step) { + public static async Task ParseSteps(Runner.Server.Azure.Devops.Context context, IList steps, TemplateToken step) { var values = "task, powershell, pwsh, bash, script, checkout, download, downloadBuild, getPackage, publish, reviewApp, template"; var mstep = step.AssertMapping($"steps.* a step must contain one of the following keyworlds as the first key {values}"); mstep.AssertNotEmpty($"steps.* a step must contain one of the following keyworlds as the first key {values}"); @@ -304,9 +305,9 @@ public static void ParseSteps(Runner.Server.Azure.Devops.Context context, IList< if(unparsedTokens.Count == 1 && (unparsedTokens[0].Key as StringToken)?.Value != "parameters") { throw new Exception($"Unexpected yaml key {(unparsedTokens[0].Key as StringToken)?.Value} expected parameters"); } - var file = ReadTemplate(context, primaryValue, unparsedTokens.Count == 1 ? unparsedTokens[0].Value.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "step-template-root"); + var file = await ReadTemplate(context, primaryValue, unparsedTokens.Count == 1 ? unparsedTokens[0].Value.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "step-template-root"); foreach(var step2 in (from e in file where e.Key.AssertString("").Value == "steps" select e.Value).First().AssertSequence("")) { - ParseSteps(context.ChildContext(file, primaryValue), steps, step2); + await ParseSteps(context.ChildContext(file, primaryValue), steps, step2); } break; default: @@ -314,7 +315,7 @@ public static void ParseSteps(Runner.Server.Azure.Devops.Context context, IList< } } - private static PipelineContextData ConvertValue(Runner.Server.Azure.Devops.Context context, TemplateToken val, string type, TemplateToken values) { + private static async Task ConvertValue(Runner.Server.Azure.Devops.Context context, TemplateToken val, string type, TemplateToken values) { var steps = new List(); var jobs = new List(); var stages = new List(); @@ -352,14 +353,14 @@ private static PipelineContextData ConvertValue(Runner.Server.Azure.Devops.Conte if(val == null) { return null; } - ParseSteps(context, steps, val); + await ParseSteps(context, steps, val); return steps[0].ToContextData(); case "stepList": if(val == null) { return new ArrayContextData(); } foreach(var step2 in val.AssertSequence("")) { - ParseSteps(context, steps, step2); + await ParseSteps(context, steps, step2); } var stepList = new ArrayContextData(); foreach(var step in steps) { @@ -370,12 +371,12 @@ private static PipelineContextData ConvertValue(Runner.Server.Azure.Devops.Conte if(val == null) { return null; } - return new Job().Parse(context, val).ToContextData(); + return (await new Job().Parse(context, val)).ToContextData(); case "jobList": if(val == null) { return new ArrayContextData(); } - Job.ParseJobs(context, jobs, val.AssertSequence("")); + await Job.ParseJobs(context, jobs, val.AssertSequence("")); var jobList = new ArrayContextData(); foreach(var job in jobs) { jobList.Add(job.ToContextData()); @@ -385,14 +386,14 @@ private static PipelineContextData ConvertValue(Runner.Server.Azure.Devops.Conte if(val == null) { return null; } - var djob = new Job().Parse(context, val); + var djob = await new Job().Parse(context, val); if(!djob.DeploymentJob) throw new Exception("Only Deployment Jobs are valid"); return djob.ToContextData(); case "deploymentList": if(val == null) { return new ArrayContextData(); } - Job.ParseJobs(context, jobs, val.AssertSequence("")); + await Job.ParseJobs(context, jobs, val.AssertSequence("")); var djobList = new ArrayContextData(); foreach(var job in jobs) { if(!job.DeploymentJob) throw new Exception("Only Deployment Jobs are valid"); @@ -403,12 +404,12 @@ private static PipelineContextData ConvertValue(Runner.Server.Azure.Devops.Conte if(val == null) { return null; } - return new Stage().Parse(context, val).ToContextData(); + return (await new Stage().Parse(context, val)).ToContextData(); case "stageList": if(val == null) { return new ArrayContextData(); } - Stage.ParseStages(context, stages, val.AssertSequence("")); + await Stage.ParseStages(context, stages, val.AssertSequence("")); var stageList = new ArrayContextData(); foreach(var stage in stages) { stageList.Add(stage.ToContextData()); @@ -458,7 +459,7 @@ public static string RelativeTo(string cwd, string filename) { return string.Join('/', path.ToArray()); } - public static MappingToken ReadTemplate(Runner.Server.Azure.Devops.Context context, string filenameAndRef, Dictionary cparameters = null, string schemaName = null) { + public static async Task ReadTemplate(Runner.Server.Azure.Devops.Context context, string filenameAndRef, Dictionary cparameters = null, string schemaName = null) { var variables = context.VariablesProvider?.GetVariablesForEnvironment(""); var templateContext = AzureDevops.CreateTemplateContext(context.TraceWriter ?? new EmptyTraceWriter(), new List(), context.Flags); var afilenameAndRef = filenameAndRef.Split("@", 2); @@ -470,7 +471,7 @@ public static MappingToken ReadTemplate(Runner.Server.Azure.Devops.Context conte if(finalFileName == null) { throw new Exception($"Couldn't find template location {filenameAndRef}"); } - var fileContent = context.FileProvider.ReadFile(finalRepository, finalFileName); + var fileContent = await context.FileProvider.ReadFile(finalRepository, finalFileName); if(fileContent == null) { throw new Exception($"Couldn't read template {filenameAndRef} resolved to {finalFileName} ({finalRepository ?? "self"})"); } @@ -515,7 +516,7 @@ public static MappingToken ReadTemplate(Runner.Server.Azure.Devops.Context conte } if(rawStaticVariables != null) { IDictionary pvars = new Dictionary(StringComparer.OrdinalIgnoreCase); - ParseVariables(context, pvars, rawStaticVariables, true); + await ParseVariables(context, pvars, rawStaticVariables, true); foreach(var v in pvars) { variablesData[v.Key] = new StringContextData(v.Value.Value); } @@ -562,9 +563,9 @@ public static MappingToken ReadTemplate(Runner.Server.Azure.Devops.Context conte break; } } - var defCtxData = ConvertValue(context, def, type, values); + var defCtxData = await ConvertValue(context, def, type, values); if(cparameters?.TryGetValue(name, out var value) == true) { - parametersData[name] = ConvertValue(context, value, type, values); + parametersData[name] = await ConvertValue(context, value, type, values); providedParameter++; } else { parametersData[name] = defCtxData; diff --git a/src/Sdk/AzurePipelines/DefaultFileProvider.cs b/src/Sdk/AzurePipelines/DefaultFileProvider.cs index 5a3476721e4..d6ebf8f7df1 100644 --- a/src/Sdk/AzurePipelines/DefaultFileProvider.cs +++ b/src/Sdk/AzurePipelines/DefaultFileProvider.cs @@ -1,7 +1,9 @@ +using System.Threading.Tasks; + public class DefaultFileProvider : IFileProvider { - public string ReadFile(string repositoryAndRef, string path) + public Task ReadFile(string repositoryAndRef, string path) { - return System.IO.File.ReadAllText(path); + return Task.FromResult(System.IO.File.ReadAllText(path)); } } \ No newline at end of file diff --git a/src/Sdk/AzurePipelines/IFileProvider.cs b/src/Sdk/AzurePipelines/IFileProvider.cs index 39c2f5c9588..5be28173e85 100644 --- a/src/Sdk/AzurePipelines/IFileProvider.cs +++ b/src/Sdk/AzurePipelines/IFileProvider.cs @@ -1,3 +1,5 @@ +using System.Threading.Tasks; + public interface IFileProvider { - string ReadFile(string repositoryAndRef, string path); + Task ReadFile(string repositoryAndRef, string path); } \ No newline at end of file diff --git a/src/Sdk/AzurePipelines/InMemoryFileProvider.cs b/src/Sdk/AzurePipelines/InMemoryFileProvider.cs index 0eff2f781fb..c895dd7633f 100644 --- a/src/Sdk/AzurePipelines/InMemoryFileProvider.cs +++ b/src/Sdk/AzurePipelines/InMemoryFileProvider.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System; +using System.Threading.Tasks; public class DefaultInMemoryFileProviderFileProvider : IFileProvider { @@ -12,13 +13,13 @@ public DefaultInMemoryFileProviderFileProvider(KeyValuePair[] wo private Func readFile; public Dictionary Workflows { get; private set; } - public string ReadFile(string repositoryAndRef, string path) + public Task ReadFile(string repositoryAndRef, string path) { if(repositoryAndRef == null && Workflows.TryGetValue(path, out var content)) { - return content; + return Task.FromResult(content); } else if(readFile != null) { - return readFile(path, repositoryAndRef); + return Task.FromResult(readFile(path, repositoryAndRef)); } - return null; + return Task.FromResult(null); } } \ No newline at end of file diff --git a/src/Sdk/AzurePipelines/Job.cs b/src/Sdk/AzurePipelines/Job.cs index 9591debed1d..59eb0d61041 100644 --- a/src/Sdk/AzurePipelines/Job.cs +++ b/src/Sdk/AzurePipelines/Job.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using GitHub.DistributedTask.ObjectTemplating.Tokens; using GitHub.DistributedTask.Pipelines; using GitHub.DistributedTask.Pipelines.ContextData; @@ -31,7 +32,7 @@ public class Job { public string[] UsesPools { get; set; } public string WorkspaceClean { get; set; } - public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken source) { + public async Task Parse(Runner.Server.Azure.Devops.Context context, TemplateToken source) { var jobToken = source.AssertMapping("job-root"); foreach(var kv in jobToken) { switch(kv.Key.AssertString("key").Value) { @@ -55,29 +56,29 @@ public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sourc Strategy = new Strategy(); foreach(var sv in kv.Value.AssertMapping("strategy")) { if(DeploymentJob) { - Action parseRunOnce = (src, runOnce) => { + Func parseRunOnce = async (src, runOnce) => { foreach(var uv in src) { switch(uv.Key.AssertString("").Value) { case "preDeploy": - runOnce.PreDeploy = new Strategy.DeploymentHook().Parse(context, uv.Value); + runOnce.PreDeploy = await new Strategy.DeploymentHook().Parse(context, uv.Value); break; case "deploy": - runOnce.Deploy = new Strategy.DeploymentHook().Parse(context, uv.Value); + runOnce.Deploy = await new Strategy.DeploymentHook().Parse(context, uv.Value); break; case "routeTraffic": - runOnce.RouteTraffic = new Strategy.DeploymentHook().Parse(context, uv.Value); + runOnce.RouteTraffic = await new Strategy.DeploymentHook().Parse(context, uv.Value); break; case "postRouteTraffic": - runOnce.PostRouteTraffic = new Strategy.DeploymentHook().Parse(context, uv.Value); + runOnce.PostRouteTraffic = await new Strategy.DeploymentHook().Parse(context, uv.Value); break; case "on": foreach(var kv2 in uv.Value as MappingToken) { switch(kv2.Key.AssertString("").Value) { case "failure": - runOnce.OnFailure = new Strategy.DeploymentHook().Parse(context, kv2.Value); + runOnce.OnFailure = await new Strategy.DeploymentHook().Parse(context, kv2.Value); break; case "success": - runOnce.OnSuccess = new Strategy.DeploymentHook().Parse(context, kv2.Value); + runOnce.OnSuccess = await new Strategy.DeploymentHook().Parse(context, kv2.Value); break; } } @@ -88,11 +89,11 @@ public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sourc switch(sv.Key.AssertString("key").Value) { case "runOnce": Strategy.RunOnce = new Strategy.RunOnceStrategy(); - parseRunOnce(sv.Value as MappingToken, Strategy.RunOnce); + await parseRunOnce(sv.Value as MappingToken, Strategy.RunOnce); break; case "canary": Strategy.Canary = new Strategy.CanaryStrategy(); - parseRunOnce(sv.Value as MappingToken, Strategy.Canary); + await parseRunOnce(sv.Value as MappingToken, Strategy.Canary); var rawIncrements = (from k in sv.Value as MappingToken where k.Key.AssertString("").Value == "increments" select k.Value).FirstOrDefault()?.AssertSequence("canary increments"); if(rawIncrements != null) { Strategy.Canary.Increments = (from inc in rawIncrements select inc.AssertLiteralString("canary increment")).ToArray(); @@ -100,7 +101,7 @@ public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sourc break; case "rolling": Strategy.Rolling = new Strategy.RollingStrategy(); - parseRunOnce(sv.Value as MappingToken, Strategy.Rolling); + await parseRunOnce(sv.Value as MappingToken, Strategy.Rolling); Strategy.Rolling.MaxParallel = (from k in sv.Value as MappingToken where k.Key.AssertString("").Value == "maxParallel" select k.Value).FirstOrDefault()?.AssertLiteralString("maxParallel"); break; } @@ -137,7 +138,7 @@ public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sourc break; case "variables": variablesMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase); - AzureDevops.ParseVariables(context, variablesMetaData, kv.Value); + await AzureDevops.ParseVariables(context, variablesMetaData, kv.Value); Variables = variablesMetaData.Where(metaData => !metaData.Value.IsGroup).ToDictionary(metaData => metaData.Key, metaData => metaData.Value, StringComparer.OrdinalIgnoreCase); variablesMetaData = variablesMetaData.Where(metaData => !metaData.Value.IsGroupMember).ToDictionary(metaData => metaData.Key, metaData => metaData.Value, StringComparer.OrdinalIgnoreCase); break; @@ -147,7 +148,7 @@ public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sourc case "steps": Steps = new List(); foreach(var step2 in kv.Value.AssertSequence("")) { - AzureDevops.ParseSteps(context, Steps, step2); + await AzureDevops.ParseSteps(context, Steps, step2); } break; case "templateContext": @@ -198,7 +199,7 @@ public Job Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sourc return this; } - public static void ParseJobs(Context context, List jobs, SequenceToken jobsToken) { + public static async Task ParseJobs(Context context, List jobs, SequenceToken jobsToken) { foreach(var job in jobsToken) { if(job is MappingToken mstep && mstep.Count > 0) { if((mstep[0].Key as StringToken)?.Value == "template") { @@ -206,10 +207,10 @@ public static void ParseJobs(Context context, List jobs, SequenceToken jobs if(mstep.Count == 2 && (mstep[1].Key as StringToken)?.Value != "parameters") { throw new Exception($"Unexpected yaml key {(mstep[1].Key as StringToken)?.Value} expected parameters"); } - var file = AzureDevops.ReadTemplate(context, path, mstep.Count == 2 ? mstep[1].Value.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "job-template-root"); - ParseJobs(context.ChildContext(file, path), jobs, (from e in file where e.Key.AssertString("").Value == "jobs" select e.Value).First().AssertSequence("")); + var file = await AzureDevops.ReadTemplate(context, path, mstep.Count == 2 ? mstep[1].Value.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "job-template-root"); + await ParseJobs(context.ChildContext(file, path), jobs, (from e in file where e.Key.AssertString("").Value == "jobs" select e.Value).First().AssertSequence("")); } else { - jobs.Add(new Job().Parse(context, mstep)); + jobs.Add(await new Job().Parse(context, mstep)); } } } diff --git a/src/Sdk/AzurePipelines/Pipeline.cs b/src/Sdk/AzurePipelines/Pipeline.cs index b8fc52238da..d93eea75e55 100644 --- a/src/Sdk/AzurePipelines/Pipeline.cs +++ b/src/Sdk/AzurePipelines/Pipeline.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using GitHub.DistributedTask.ObjectTemplating.Tokens; using GitHub.DistributedTask.Pipelines; using GitHub.DistributedTask.Pipelines.ContextData; @@ -22,7 +23,7 @@ public class Pipeline { public bool? AppendCommitMessageToRunName { get; set; } public String LockBehavior { get; set; } - public Pipeline Parse(Runner.Server.Azure.Devops.Context context, TemplateToken source) { + public async Task Parse(Runner.Server.Azure.Devops.Context context, TemplateToken source) { var pipelineRootToken = source.AssertMapping("pipeline-root"); Pipeline parent = null; foreach(var kv in pipelineRootToken) { @@ -32,7 +33,7 @@ public Pipeline Parse(Runner.Server.Azure.Devops.Context context, TemplateToken break; case "variables": variablesMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase); - AzureDevops.ParseVariables(context, variablesMetaData, kv.Value); + await AzureDevops.ParseVariables(context, variablesMetaData, kv.Value); Variables = variablesMetaData.Where(metaData => !metaData.Value.IsGroup).ToDictionary(metaData => metaData.Key, metaData => metaData.Value, StringComparer.OrdinalIgnoreCase); variablesMetaData = variablesMetaData.Where(metaData => !metaData.Value.IsGroupMember).ToDictionary(metaData => metaData.Key, metaData => metaData.Value, StringComparer.OrdinalIgnoreCase); break; @@ -50,22 +51,22 @@ public Pipeline Parse(Runner.Server.Azure.Devops.Context context, TemplateToken break; } } - var templ = AzureDevops.ReadTemplate(context, template, parameters); - parent = new Pipeline().Parse(context.ChildContext(templ, template), templ); + var templ = await AzureDevops.ReadTemplate(context, template, parameters); + parent = await new Pipeline().Parse(context.ChildContext(templ, template), templ); break; case "stages": Stages = new List(); - Stage.ParseStages(context, Stages, kv.Value.AssertSequence("stages")); + await Stage.ParseStages(context, Stages, kv.Value.AssertSequence("stages")); break; case "steps": - var implicitJob = new Job().Parse(context, source); + var implicitJob = await new Job().Parse(context, source); implicitJob.Name = null; Stages = new List{ new Stage { Jobs = new List{ implicitJob } } }; break; case "jobs": - var implicitStage = new Stage().Parse(context, source); + var implicitStage = await new Stage().Parse(context, source); implicitStage.Name = null; Stages = new List{ implicitStage }; break; diff --git a/src/Sdk/AzurePipelines/Stage.cs b/src/Sdk/AzurePipelines/Stage.cs index b1f1d3ee38b..dc75a8cc65a 100644 --- a/src/Sdk/AzurePipelines/Stage.cs +++ b/src/Sdk/AzurePipelines/Stage.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using GitHub.DistributedTask.ObjectTemplating.Tokens; using GitHub.DistributedTask.Pipelines; using GitHub.DistributedTask.Pipelines.ContextData; @@ -21,7 +22,7 @@ public class Stage { public Pool Pool { get; set; } public String LockBehavior { get; set; } - public Stage Parse(Runner.Server.Azure.Devops.Context context, TemplateToken source) { + public async Task Parse(Runner.Server.Azure.Devops.Context context, TemplateToken source) { var jobToken = source.AssertMapping("job-root"); foreach(var kv in jobToken) { switch(kv.Key.AssertString("key").Value) { @@ -39,13 +40,13 @@ public Stage Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sou break; case "variables": variablesMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase); - AzureDevops.ParseVariables(context, variablesMetaData, kv.Value); + await AzureDevops.ParseVariables(context, variablesMetaData, kv.Value); Variables = variablesMetaData.Where(metaData => !metaData.Value.IsGroup).ToDictionary(metaData => metaData.Key, metaData => metaData.Value, StringComparer.OrdinalIgnoreCase); variablesMetaData = variablesMetaData.Where(metaData => !metaData.Value.IsGroupMember).ToDictionary(metaData => metaData.Key, metaData => metaData.Value, StringComparer.OrdinalIgnoreCase); break; case "jobs": Jobs = new List(); - Job.ParseJobs(context, Jobs, kv.Value.AssertSequence("")); + await Job.ParseJobs(context, Jobs, kv.Value.AssertSequence("")); break; case "templateContext": TemplateContext = AzureDevops.ConvertAllScalarsToString(kv.Value); @@ -61,7 +62,7 @@ public Stage Parse(Runner.Server.Azure.Devops.Context context, TemplateToken sou return this; } - public static void ParseStages(Runner.Server.Azure.Devops.Context context, List stages, SequenceToken stagesToken) { + public static async Task ParseStages(Runner.Server.Azure.Devops.Context context, List stages, SequenceToken stagesToken) { foreach(var job in stagesToken) { if(job is MappingToken mstep && mstep.Count > 0) { if((mstep[0].Key as StringToken)?.Value == "template") { @@ -69,10 +70,10 @@ public static void ParseStages(Runner.Server.Azure.Devops.Context context, List< if(mstep.Count == 2 && (mstep[1].Key as StringToken)?.Value != "parameters") { throw new Exception($"Unexpected yaml key {(mstep[1].Key as StringToken)?.Value} expected parameters"); } - var file = AzureDevops.ReadTemplate(context, path, mstep.Count == 2 ? mstep[1].Value.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "stage-template-root"); - ParseStages(context.ChildContext(file, path), stages, (from e in file where e.Key.AssertString("").Value == "stages" select e.Value).First().AssertSequence("")); + var file = await AzureDevops.ReadTemplate(context, path, mstep.Count == 2 ? mstep[1].Value.AssertMapping("param").ToDictionary(kv => kv.Key.AssertString("").Value, kv => kv.Value) : null, "stage-template-root"); + await ParseStages(context.ChildContext(file, path), stages, (from e in file where e.Key.AssertString("").Value == "stages" select e.Value).First().AssertSequence("")); } else { - stages.Add(new Stage().Parse(context, mstep)); + stages.Add(await new Stage().Parse(context, mstep)); } } } diff --git a/src/Sdk/AzurePipelines/Strategy.cs b/src/Sdk/AzurePipelines/Strategy.cs index f046800b400..0152b23a2cc 100644 --- a/src/Sdk/AzurePipelines/Strategy.cs +++ b/src/Sdk/AzurePipelines/Strategy.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using GitHub.DistributedTask.ObjectTemplating.Tokens; using GitHub.DistributedTask.Pipelines; using GitHub.DistributedTask.Pipelines.ContextData; @@ -19,13 +20,13 @@ public class DeploymentHook { public List Steps { get; set; } public Pool Pool { get; set; } - public DeploymentHook Parse(Context context, TemplateToken src) { + public async Task Parse(Context context, TemplateToken src) { foreach(var kv in src.AssertMapping("")) { switch(kv.Key.AssertString("").Value) { case "steps": Steps = new List(); foreach(var step2 in kv.Value.AssertSequence("")) { - AzureDevops.ParseSteps(context, Steps, step2); + await AzureDevops.ParseSteps(context, Steps, step2); } break; case "pool": diff --git a/src/Sdk/Sdk.csproj b/src/Sdk/Sdk.csproj index e916f147119..210313f55da 100644 --- a/src/Sdk/Sdk.csproj +++ b/src/Sdk/Sdk.csproj @@ -19,7 +19,7 @@ - +