Skip to content

Commit 7e41f3a

Browse files
authored
Update CI logic (#18980)
* trigger CI * trigger CI * trigger CI Co-authored-by: wyunchi-ms <[email protected]>
1 parent 84907de commit 7e41f3a

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

.ci-config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,5 +284,20 @@
284284
"test:all"
285285
]
286286
}
287+
],
288+
"selectModuleList": [
289+
"Accounts",
290+
"Aks",
291+
"ApplicationInsights",
292+
"Compute",
293+
"Functions",
294+
"KeyVault",
295+
"KubernetersConfiguration",
296+
"Network",
297+
"PostgreSql",
298+
"Purview",
299+
"Resources",
300+
"Storage",
301+
"Websites"
287302
]
288303
}

tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIFilterTask.cs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ private List<string> GetDependentModuleList(string moduleName, Dictionary<string
193193
// Run a selected module list instead of run all the modules to speed up the CI process.
194194
private List<string> GetSelectedModuleList()
195195
{
196-
return new List<string>(Environment.GetEnvironmentVariable("SELECTEDMODULELIST").Split(';'));
196+
CIPhaseFilterConfig config = GetCIPhaseFilterConfig();
197+
return config.SelectModuleList;
197198
}
198199

199200
private List<string> GetTestCsprojList(string moduleName, Dictionary<string, string[]> csprojMap)
@@ -251,7 +252,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
251252
{
252253
List<string> phaseList = new List<string>();
253254
bool isMatched = false;
254-
string machedModuleName = "";
255+
string matchedModuleName = "";
255256
foreach ((Regex regex, List<string> phaseConfigList) in ruleList)
256257
{
257258
var regexResult = regex.Match(filePath);
@@ -261,7 +262,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
261262
isMatched = true;
262263
if (regexResult.Groups[MODULE_NAME_PLACEHOLDER].Success)
263264
{
264-
machedModuleName = regexResult.Groups[MODULE_NAME_PLACEHOLDER].Value;
265+
matchedModuleName = regexResult.Groups[MODULE_NAME_PLACEHOLDER].Value;
265266
}
266267
Console.WriteLine(string.Format("File {0} match rule: {1} and phaseConfig is: [{2}]", filePath, regex.ToString(), string.Join(", ", phaseConfigList)));
267268
break;
@@ -294,7 +295,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
294295
}
295296
else
296297
{
297-
string moduleName = machedModuleName == "" ? filePath.Split('/')[1] : machedModuleName;
298+
string moduleName = matchedModuleName == "" ? filePath.Split('/')[1] : matchedModuleName;
298299
if (scope.Equals(SingleModule))
299300
{
300301
scopes.Add(moduleName);
@@ -411,7 +412,7 @@ private Dictionary<string, HashSet<string>> CalculateCsprojForBuildAndTest(Dicti
411412
return influencedModuleInfo;
412413
}
413414

414-
private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
415+
private CIPhaseFilterConfig GetCIPhaseFilterConfig()
415416
{
416417
string configPath = Path.GetFullPath(TaskMappingConfigName);
417418
if (!File.Exists(configPath))
@@ -420,8 +421,14 @@ private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
420421
}
421422
string content = File.ReadAllText(configPath);
422423

423-
CIPhaseFilterConfig config = JsonConvert.DeserializeObject<CIPhaseFilterConfig>(content);
424-
List<(Regex, List<string>)> ruleList = config.Rules.Select(rule => (new Regex(string.Join("|", rule.Patterns.Select(ProcessSinglePattern))), rule.Phases)).ToList();
424+
return JsonConvert.DeserializeObject<CIPhaseFilterConfig>(content);
425+
}
426+
427+
private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
428+
{
429+
430+
CIPhaseFilterConfig config = GetCIPhaseFilterConfig();
431+
List<(Regex, List<string>)> ruleList = config.Rules.Select(rule => (new Regex(string.Join("|", rule.Patterns.Select(ProcessSinglePattern).ToList())), rule.Phases)).ToList();
425432

426433
DateTime startTime = DateTime.Now;
427434

@@ -456,13 +463,28 @@ public override bool Execute()
456463
}
457464
else if (FilesChanged != null)
458465
{
459-
if (FilesChanged.Length > 0 && FilesChanged.Length < OCTOKIT_CHANGED_FILE_LIMIT)
466+
if (FilesChanged.Length <= 0)
460467
{
461-
return ProcessFileChanged(csprojMap);
468+
return false;
469+
}
470+
else if (FilesChanged.Length >= OCTOKIT_CHANGED_FILE_LIMIT)
471+
{
472+
var selectedModuleList = GetSelectedModuleList();
473+
Dictionary<string, HashSet<string>> influencedModuleInfo = new Dictionary<string, HashSet<string>>
474+
{
475+
[BUILD_PHASE] = new HashSet<string>(selectedModuleList),
476+
[ANALYSIS_BREAKING_CHANGE_PHASE] = new HashSet<string>(selectedModuleList),
477+
[ANALYSIS_DEPENDENCY_PHASE] = new HashSet<string>(selectedModuleList),
478+
[ANALYSIS_HELP_PHASE] = new HashSet<string>(selectedModuleList),
479+
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(selectedModuleList),
480+
[TEST_PHASE] = new HashSet<string>(selectedModuleList)
481+
};
482+
FilterTaskResult.PhaseInfo = CalculateCsprojForBuildAndTest(influencedModuleInfo, csprojMap);
483+
return true;
462484
}
463485
else
464486
{
465-
return false;
487+
return ProcessFileChanged(csprojMap);
466488
}
467489
}
468490
return true;

tools/BuildPackagesTask/Microsoft.Azure.Build.Tasks/CIPhaseFilterConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.WindowsAzure.Build.Tasks
1919
class CIPhaseFilterConfig
2020
{
2121
public List<Rule> Rules { get; set; }
22+
public List<string> SelectModuleList { get; set; }
2223
}
2324

2425
class Rule

tools/PrepareAutorestModule.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ foreach ($file in $ChangedFiles)
4747
if ($ModuleSet.Contains($ALL_MODULE))
4848
{
4949
$Null = $ModuleSet.Remove($ALL_MODULE)
50-
$SelectedModuleList = (Get-ChildItem "$PSScriptRoot\..\src\").Name | Where-Object { (Get-Item env:SELECTEDMODULELIST).Value.Split(';') -contains $_ }
50+
$CIConfig = Get-Content "$PSScriptRoot\..\.ci-config.json" | ConvertFrom-Json
51+
$SelectedModuleList = (Get-ChildItem "$PSScriptRoot\..\src\").Name | Where-Object { $CIConfig.selectModuleList -contains $_ }
5152
$Null = $ModuleSet.Add($SelectedModuleList)
5253
$ModuleList = $ModuleSet | Where-Object { $SKIP_MODULES -notcontains $_ }
5354
}

0 commit comments

Comments
 (0)