From ca223275fa8dffc5645ca180eff515d74cf81d8a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 14 May 2024 13:19:41 +0100 Subject: [PATCH] parse env files --- Build/EnvFile.cs | 33 +++++++++++++++++++++++++++++++++ Build/Program.cs | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Build/EnvFile.cs diff --git a/Build/EnvFile.cs b/Build/EnvFile.cs new file mode 100644 index 0000000000..ed940eb5f0 --- /dev/null +++ b/Build/EnvFile.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Build; + +public static class EnvFile +{ + public static Dictionary Parse(string path) + { + Dictionary data = new(); + + if (!File.Exists(path)) + { + throw new FileNotFoundException(path); + } + + using var reader = File.OpenText(path); + string? line; + while ((line = reader.ReadLine()) != null) + { + var values = line.Split("=", StringSplitOptions.RemoveEmptyEntries); + if (values.Length < 2) + { + continue; + } + data.Add(values[0], string.Join('=', values.Skip(1))); + } + + return data; + } +} diff --git a/Build/Program.cs b/Build/Program.cs index 291153a42f..0adda756f5 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -107,7 +107,8 @@ IEnumerable GetFiles(string d) BUILD_INSTALLERS, async () => { - var token = File.ReadAllText(".env"); + var data = EnvFile.Parse(".env"); + var token = data["TOKEN"]; var runId = Environment.GetEnvironmentVariable("RUN_ID"); Console.WriteLine($"Found: {runId} and {token.Length}"); await Github.BuildInstallers(token, runId).ConfigureAwait(false);