From be0c2a7c6af77546795c67589df8d25eb992f910 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Wed, 27 Nov 2024 18:42:43 +0100 Subject: [PATCH] Fix broken input flags and allow empty files (#448) --- src/Runner.Client/Program.cs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Runner.Client/Program.cs b/src/Runner.Client/Program.cs index c63f8fc61c7..7138b6bf13b 100644 --- a/src/Runner.Client/Program.cs +++ b/src/Runner.Client/Program.cs @@ -816,7 +816,7 @@ public static async Task ExpandCurrentPipeline(Parameters handle, string }; Dictionary cparameters = new Dictionary(StringComparer.OrdinalIgnoreCase); if(handle.InputFiles?.Length > 0) { - foreach(var file in handle.InputFiles) { + foreach(var file in handle.InputFiles.Where(f => f != "")) { Util.ReadEnvFile(file, (varname, varval) => cparameters[varname] = AzurePipelinesUtils.ConvertStringToTemplateToken(varval)); } } @@ -1093,6 +1093,8 @@ static int Main(string[] args) environmentSecretFileOpt, environmentVarOpt, environmentVarFileOpt, + workflowInputsOpt, + workflowInputFilesOpt, jobOpt, matrixOpt, listOpt, @@ -1761,7 +1763,7 @@ await Task.WhenAny(Task.Run(() => { List wenv = new List(); List wsecrets = new List(); if(parameters.EnvFile?.Length > 0) { - foreach(var file in parameters.EnvFile) { + foreach(var file in parameters.EnvFile.Where(f => f != "")) { try { wenv.AddRange(Util.ReadEnvFile(file)); } catch(Exception ex) { @@ -1771,7 +1773,7 @@ await Task.WhenAny(Task.Run(() => { } } if(parameters.SecretFiles?.Length > 0) { - foreach(var file in parameters.SecretFiles) { + foreach(var file in parameters.SecretFiles.Where(f => f != "")) { try { wsecrets.AddRange(Util.ReadEnvFile(file)); } catch(Exception ex) { @@ -1976,7 +1978,7 @@ await Task.WhenAny(Task.Run(() => { var inputs = payloadContent.TryGetValue("inputs", out var oinputs) ? (JObject)oinputs : new JObject(); payloadContent["inputs"] = inputs; if(parameters.InputFiles?.Length > 0) { - foreach(var file in parameters.InputFiles) { + foreach(var file in parameters.InputFiles.Where(f => f != "")) { try { Util.ReadEnvFile(file, (k, v) => inputs[k] = v); } catch(Exception ex) { @@ -1998,7 +2000,7 @@ await Task.WhenAny(Task.Run(() => { if(!ffVars.ContainsKey("system.runner.server.parameters")) { var inputs = new JObject(); if(parameters.InputFiles?.Length > 0) { - foreach(var file in parameters.InputFiles) { + foreach(var file in parameters.InputFiles.Where(f => f != "")) { try { Util.ReadEnvFile(file, (k, v) => inputs[k] = v); } catch(Exception ex) { @@ -2538,10 +2540,6 @@ await Task.WhenAny(Task.Run(() => { cmd.AddOption(opt); } } - if(ev == "workflow_dispatch" || ev == "azexpand" || ev == "azpipelines") { - cmd.AddOption(workflowInputsOpt); - cmd.AddOption(workflowInputFilesOpt); - } } var startserver = new Command("startserver", "Starts a server listening on the supplied address or selects a random free http address."); rootCommand.AddCommand(startserver); @@ -2617,7 +2615,7 @@ await Task.WhenAny(Task.Run(() => { { var envSecrets = new Dictionary>(StringComparer.OrdinalIgnoreCase); if(parameters.EnvironmentSecretFiles?.Length > 0) { - foreach(var opt in parameters.EnvironmentSecretFiles) { + foreach(var opt in parameters.EnvironmentSecretFiles.Where(f => f != "")) { var subopt = opt.Split('=', 2); string name = subopt.Length == 2 ? subopt[0] : ""; string filename = subopt.Length == 2 ? subopt[1] : subopt[0]; @@ -2643,7 +2641,7 @@ await Task.WhenAny(Task.Run(() => { } var envVars = new Dictionary>(StringComparer.OrdinalIgnoreCase); if(parameters.EnvironmentVarFiles?.Length > 0) { - foreach(var opt in parameters.EnvironmentVarFiles) { + foreach(var opt in parameters.EnvironmentVarFiles.Where(f => f != "")) { var subopt = opt.Split('=', 2); string name = subopt.Length == 2 ? subopt[0] : ""; string filename = subopt.Length == 2 ? subopt[1] : subopt[0]; @@ -2652,7 +2650,7 @@ await Task.WhenAny(Task.Run(() => { } } if(parameters.VarFiles?.Length > 0) { - foreach(var opt in parameters.VarFiles) { + foreach(var opt in parameters.VarFiles.Where(f => f != "")) { string name = ""; string filename = opt; var dict = envVars[name] = envVars.TryGetValue(name, out var v) ? v : new Dictionary(StringComparer.OrdinalIgnoreCase);