Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh files generated during build (Unblocks CI / courtesy push) + added validation #19310

Merged
merged 17 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
102 changes: 102 additions & 0 deletions BuildConfigGen/MakeOptionsReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace BuildConfigGen
{
internal static class MakeOptionsReader
{
internal static Dictionary<string, AgentTask> ReadMakeOptions(string gitRootPath)
{
Dictionary<string, AgentTask> agentTasks = new Dictionary<string, AgentTask>();
merlynomsft marked this conversation as resolved.
Show resolved Hide resolved

var r = new Utf8JsonReader(File.ReadAllBytes(Path.Combine(gitRootPath, @"make-options.json")));

bool inConfig = false;
string configName = "";

while (r.Read())
{

switch (r.TokenType)
{
case JsonTokenType.PropertyName:
merlynomsft marked this conversation as resolved.
Show resolved Hide resolved
{
string? text = r.GetString();
//Console.WriteLine(r.TokenType + " " + text);
merlynomsft marked this conversation as resolved.
Show resolved Hide resolved

if (text == "taskResources")
{
// skip
inConfig = false;
}
else if (text == "tasks")
{
inConfig = false;
}
else
{

inConfig = true;
configName = text!;
}

break;
}
case JsonTokenType.String:
{
if (inConfig)
{
string? text = r.GetString();
//Console.WriteLine(r.TokenType + " " + text);

AgentTask task;
if (agentTasks.TryGetValue(text!, out task!))
{

merlynomsft marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
task = new AgentTask(text!);
agentTasks.Add(text!, task);
}

if (configName == "")
{
throw new Exception("expected configName to have value");
}

task.Configs.Add(configName);
}

break;
}
default:
//Console.WriteLine(r.TokenType);
break;
}
}

// startarray, endarray

return agentTasks;
}


internal class AgentTask
{
public AgentTask(string name)
{
Name = name;
}

public string Name;

public HashSet<string> Configs = new HashSet<string>();

}
}
}
56 changes: 49 additions & 7 deletions BuildConfigGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,57 @@ public record ConfigRecord(string name, string constMappingKey, bool isDefault,
/// <param name="configs">List of configs to generate seperated by |</param>
/// <param name="currentSprint">Overide current sprint; omit to get from whatsprintis.it</param>
/// <param name="writeUpdates">Write updates if true, else validate that the output is up-to-date</param>
static void Main(string task, string configs, int? currentSprint, bool writeUpdates = false)
/// <param name="allTasks"></param>
static void Main(string? task = null, string? configs = null, int? currentSprint = null, bool writeUpdates = false, bool allTasks = false)
{
// error handling strategy:
// 1. design: anything goes wrong, try to detect and crash as early as possible to preserve the callstack to make debugging easier.
// 2. we allow all exceptions to fall though. Non-zero exit code will be surfaced
// 3. Ideally default windows exception will occur and errors reported to WER/watson. I'm not sure this is happening, perhaps DragonFruit is handling the exception
foreach (var t in task.Split(',', '|'))
if (allTasks)
{
Main3(t, configs, writeUpdates, currentSprint);
NullOrThrow(task, "If allTasks specified, task must not be supplied");
NullOrThrow(configs, "If allTasks specified, configs must not be supplied");
}
else
{
NotNullOrThrow(task, "Task is required");
NotNullOrThrow(configs, "Configs is required");
}

if (allTasks)
{
string currentDir = Environment.CurrentDirectory;
string gitRootPath = GitUtil.GetGitRootPath(currentDir);

var tasks = MakeOptionsReader.ReadMakeOptions(gitRootPath);
foreach (var t in tasks.Values)
{
Main3(t.Name, string.Join('|', t.Configs), writeUpdates, currentSprint);
merlynomsft marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
{
// error handling strategy:
// 1. design: anything goes wrong, try to detect and crash as early as possible to preserve the callstack to make debugging easier.
// 2. we allow all exceptions to fall though. Non-zero exit code will be surfaced
// 3. Ideally default windows exception will occur and errors reported to WER/watson. I'm not sure this is happening, perhaps DragonFruit is handling the exception
foreach (var t in task!.Split(',', '|'))
{
Main3(t, configs!, writeUpdates, currentSprint);
}
}
}

private static void NullOrThrow<T>(T value, string message)
merlynomsft marked this conversation as resolved.
Show resolved Hide resolved
{
if(value != null)
{
throw new Exception(message);
}
}

private static void NotNullOrThrow<T>(T value, string message)
{
if (value == null)
{
throw new Exception(message);
}
}

Expand Down
40 changes: 20 additions & 20 deletions Tasks/AzureAppServiceManageV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Tasks/AzureAppServiceManageV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"demands": [],
"version": {
"Major": 0,
"Minor": 228,
"Patch": 1
"Minor": 231,
"Patch": 0
},
"minimumAgentVersion": "1.102.0",
"instanceNameFormat": "$(Action): $(WebAppName)",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureAppServiceManageV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"demands": [],
"version": {
"Major": 0,
"Minor": 228,
"Patch": 1
"Minor": 231,
"Patch": 0
},
"minimumAgentVersion": "1.102.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 228,
"Minor": 231,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFunctionAppContainerV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 1,
"Minor": 228,
"Minor": 231,
"Patch": 0
},
"minimumAgentVersion": "2.104.1",
Expand Down
Loading
Loading