Skip to content

Commit

Permalink
parse env files
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed May 14, 2024
1 parent 739898b commit ca22327
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Build/EnvFile.cs
Original file line number Diff line number Diff line change
@@ -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<string, string> Parse(string path)
{
Dictionary<string, string> 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;
}
}
3 changes: 2 additions & 1 deletion Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ IEnumerable<string> 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);
Expand Down

0 comments on commit ca22327

Please sign in to comment.