Skip to content

Commit 3ab4313

Browse files
authored
1. Use CIPlan.json to determine the CI plan (Azure#19799)
2. Reuse the artifacts from the previous build to save the time in StaticAnalysis and Test
1 parent ec3ce1c commit 3ab4313

File tree

6 files changed

+146
-16
lines changed

6 files changed

+146
-16
lines changed

.ci-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,6 @@
299299
"Resources",
300300
"Storage",
301301
"Websites"
302-
]
302+
],
303+
"artifactPipelineInfoFolder": "artifacts/PipelineResult"
303304
}

build.proj

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,35 +236,34 @@
236236
<!-- Everything except Publish -->
237237
<Target Name="Full" DependsOnTargets="Clean;Build;OnPremChecks;CopyAboutTopics;GenerateHelp;StaticAnalysis;Test" />
238238

239-
<Target Name="StaticAnalysisBreakingChange" Condition="'$(RunStaticAnalysis)' == 'true'" DependsOnTargets="Build">
239+
<Target Name="StaticAnalysisBreakingChange" Condition="'$(RunStaticAnalysis)' == 'true'">
240240
<Message Importance="high" Text="Running static analysis for breaking change..." />
241241
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />
242242

243-
<Exec Command="dotnet $(RepoArtifacts)StaticAnalysis/StaticAnalysis.Netcore.dll -p $(RepoArtifacts)$(Configuration) -r $(StaticAnalysisOutputDirectory) --analyzers breaking-change -u -m '%(FilterTaskResult.breaking-change)'" />
243+
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisBreakingChange -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
244244
</Target>
245245

246-
<Target Name="StaticAnalysisDependency" Condition="'$(RunStaticAnalysis)' == 'true'" DependsOnTargets="Build">
246+
<Target Name="StaticAnalysisDependency" Condition="'$(RunStaticAnalysis)' == 'true'">
247247
<Message Importance="high" Text="Running static analysis for dependency..." />
248248
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />
249249

250-
<Exec Command="dotnet $(RepoArtifacts)StaticAnalysis/StaticAnalysis.Netcore.dll -p $(RepoArtifacts)$(Configuration) -r $(StaticAnalysisOutputDirectory) --analyzers dependency -u -m '%(FilterTaskResult.breaking-change)'" />
250+
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisDependency -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
251251
</Target>
252252

253-
<Target Name="StaticAnalysisSignature" Condition="'$(RunStaticAnalysis)' == 'true'" DependsOnTargets="Build">
253+
<Target Name="StaticAnalysisSignature" Condition="'$(RunStaticAnalysis)' == 'true'">
254254
<Message Importance="high" Text="Running static analysis for signature..." />
255255
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />
256-
257-
<Exec Command="dotnet $(RepoArtifacts)StaticAnalysis/StaticAnalysis.Netcore.dll -p $(RepoArtifacts)$(Configuration) -r $(StaticAnalysisOutputDirectory) --analyzers signature -u -m '%(FilterTaskResult.signature)'" />
256+
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisSignature -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
258257
</Target>
259258

260-
<Target Name="StaticAnalysisHelp" Condition="'$(RunStaticAnalysis)' == 'true'" DependsOnTargets="Build">
259+
<Target Name="StaticAnalysisHelp" Condition="'$(RunStaticAnalysis)' == 'true'">
261260
<Message Importance="high" Text="Running static analysis for help..." />
262261
<MakeDir Directories="$(StaticAnalysisOutputDirectory)" />
263262

264-
<Exec Command="dotnet $(RepoArtifacts)StaticAnalysis/StaticAnalysis.Netcore.dll -p $(RepoArtifacts)$(Configuration) -r $(StaticAnalysisOutputDirectory) --analyzers help -u -m '%(FilterTaskResult.help)'" />
263+
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -StaticAnalysisHelp -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory)&quot;" />
265264
</Target>
266265

267-
<Target Name="StaticAnalysisExample" Condition="'$(RunStaticAnalysis)' == 'true'" DependsOnTargets="Build" AfterTargets="StaticAnalysisHelp">
266+
<Target Name="StaticAnalysisExample" Condition="'$(RunStaticAnalysis)' == 'true'" AfterTargets="StaticAnalysisHelp">
268267
<Message Importance="high" Text="Running static analysis for PowerShell examples..." />
269268
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/StaticAnalysis/ExampleAnalyzer/Measure-MarkdownOrScript.ps1 -MarkdownPaths $(RepoArtifacts)/FilesChanged.txt -RulePaths $(RepoTools)/StaticAnalysis/ExampleAnalyzer/AnalyzeRules/*.psm1 &quot;"/>
270269
</Target>
@@ -318,12 +317,12 @@
318317
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(DockerTools)/CleanArtifacts.ps1 -Docker $(DockerRoot) &quot;" />
319318
</Target>
320319

321-
<Target Name="Test" DependsOnTargets="FilterBuild" Condition="'$(IsGenerateBased)' == 'false'">
320+
<Target Name="Test" Condition="'$(IsGenerateBased)' == 'false'">
322321
<Message Importance="high" Text="Running check in tests..." />
323322
<MakeDir Directories="$(TestOutputDirectory)" ContinueOnError="false" />
324323
<!-- https://github.com/Microsoft/msbuild/issues/3157#issuecomment-378002971 -->
325324
<!-- https://github.com/xunit/xunit/issues/1154#issuecomment-405366373 -->
326-
<Exec Command="dotnet test $(RepoArtifacts)Azure.PowerShell.sln --filter &quot;AcceptanceType=CheckIn%26RunType!=DesktopOnly&quot; --configuration $(Configuration) --framework $(TestFramework) --logger trx --results-directory &quot;$(TestOutputDirectory)&quot;" Condition="'$(TestCsprojList)' != ''" />
325+
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;.\tools\ExecuteCIStep.ps1 -Test -RepoArtifacts $(RepoArtifacts) -Configuration $(Configuration) -TestFramework $(TestFramework) -TestOutputDirectory $(TestOutputDirectory)&quot;" />
327326
<Message Importance="high" Text="Finish running tests..." />
328327
<OnError ExecuteTargets="TestFailureErrorMessage" />
329328
</Target>

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private Dictionary<string, HashSet<string>> CalculateCsprojForBuildAndTest(Dicti
337337
}
338338
if (csprojSet.Count != 0)
339339
{
340-
foreach (string filename in Directory.GetFiles(@"src/Accounts", "*.csproj", SearchOption.AllDirectories).Where(x => !x.Contains("Test")))
340+
foreach (string filename in Directory.GetFiles(@"src\Accounts", "*.csproj", SearchOption.AllDirectories).Where(x => !x.Contains("Test")))
341341
{
342342
csprojSet.Add(filename);
343343
}
@@ -353,7 +353,7 @@ private Dictionary<string, HashSet<string>> CalculateCsprojForBuildAndTest(Dicti
353353
}
354354
if (csprojSet.Count != 0)
355355
{
356-
csprojSet.Add("tools/TestFx/TestFx.csproj");
356+
csprojSet.Add(@"tools\TestFx\TestFx.csproj");
357357
}
358358
influencedModuleInfo[phaseName] = csprojSet;
359359
}
@@ -397,9 +397,26 @@ private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
397397

398398
FilterTaskResult.PhaseInfo = influencedModuleInfo;
399399

400+
influencedModuleInfo[string.Format("{0}-module", BUILD_PHASE)] = new HashSet<string>(influencedModuleInfo[BUILD_PHASE].Select(GetModuleNameFromPath).Where(x => x != null));
401+
influencedModuleInfo[string.Format("{0}-module", TEST_PHASE)] = new HashSet<string>(influencedModuleInfo[TEST_PHASE].Select(GetModuleNameFromPath).Where(x => x != null));
402+
if (!Directory.Exists(config.ArtifactPipelineInfoFolder))
403+
{
404+
Directory.CreateDirectory(config.ArtifactPipelineInfoFolder);
405+
}
406+
File.WriteAllText(Path.Combine(config.ArtifactPipelineInfoFolder, "CIPlan.json"), JsonConvert.SerializeObject(influencedModuleInfo, Formatting.Indented));
407+
400408
return true;
401409
}
402410

411+
private string GetModuleNameFromPath(string path)
412+
{
413+
if (path.IndexOf("src") == -1)
414+
{
415+
return null;
416+
}
417+
return path.Replace("\\", "/").Split("src/")[1].Split('/')[0];
418+
}
419+
403420
/// <summary>
404421
/// Executes the task to generate a list of test assemblies
405422
/// based on file changes from a specified Pull Request.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CIPhaseFilterConfig
2020
{
2121
public List<Rule> Rules { get; set; }
2222
public List<string> SelectModuleList { get; set; }
23+
public string ArtifactPipelineInfoFolder { get; set; }
2324
}
2425

2526
class Rule

tools/CreateFilterMappings.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function Create-ProjectToFullPathMappings
100100
{
101101
throw ($CsprojFile.FullName + " is conflicts with " + $Mappings[$CsprojFile.BaseName])
102102
}
103-
$Mappings[$CsprojFile.BaseName] = $CsprojFile.FullName
103+
$Mappings[$CsprojFile.BaseName] = [IO.Path]::GetRelativePath([IO.Path]::Combine($PSScriptRoot, ".."), $CsprojFile.FullName)
104104
}
105105
}
106106

tools/ExecuteCIStep.ps1

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# ----------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost If the code
13+
# is regenerated.
14+
# ----------------------------------------------------------------------------------
15+
16+
Param(
17+
[Switch]
18+
$Test,
19+
20+
[Switch]
21+
$StaticAnalysisBreakingChange,
22+
23+
[Switch]
24+
$StaticAnalysisDependency,
25+
26+
[Switch]
27+
$StaticAnalysisSignature,
28+
29+
[Switch]
30+
$StaticAnalysisHelp,
31+
32+
[String]
33+
$RepoArtifacts='artifacts',
34+
35+
[String]
36+
$Configuration='Debug',
37+
38+
[String]
39+
$TestFramework='netcoreapp2.2',
40+
41+
[String]
42+
$TestOutputDirectory='artifacts\TestResults',
43+
44+
[String]
45+
$StaticAnalysisOutputDirectory='artifacts\StaticAnalysisResults',
46+
47+
[String]
48+
$ModuleList
49+
)
50+
$ErrorActionPreference = 'Stop'
51+
52+
If (-Not $PSBoundParameters.ContainsKey("ModuleList"))
53+
{
54+
$CIPlan = Get-Content $RepoArtifacts/PipelineResult/CIPlan.json | ConvertFrom-Json
55+
}
56+
57+
If ($Test -And $CIPlan.test.Length -Ne 0)
58+
{
59+
dotnet test $RepoArtifacts/Azure.PowerShell.sln --filter "AcceptanceType=CheckIn&RunType!=DesktopOnly" --configuration $Configuration --framework $TestFramework --logger trx --results-directory $TestOutputDirectory
60+
}
61+
62+
If ($StaticAnalysisBreakingChange)
63+
{
64+
If ($PSBoundParameters.ContainsKey("ModuleList"))
65+
{
66+
$BreakingChangeCheckModuleList = $ModuleList
67+
}
68+
Else
69+
{
70+
$BreakingChangeCheckModuleList = Join-String -Separator ';' -InputObject $CIPlan.'breaking-change'
71+
}
72+
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers breaking-change -u -m $BreakingChangeCheckModuleList
73+
}
74+
75+
If ($StaticAnalysisDependency)
76+
{
77+
If ($PSBoundParameters.ContainsKey("ModuleList"))
78+
{
79+
$DependencyCheckModuleList = $ModuleList
80+
}
81+
Else
82+
{
83+
$DependencyCheckModuleList = Join-String -Separator ';' -InputObject $CIPlan.dependency
84+
}
85+
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers dependency -u -m $DependencyCheckModuleList
86+
}
87+
88+
If ($StaticAnalysisSignature)
89+
{
90+
If ($PSBoundParameters.ContainsKey("ModuleList"))
91+
{
92+
$SignatureCheckModuleList = $ModuleList
93+
}
94+
Else
95+
{
96+
$SignatureCheckModuleList = Join-String -Separator ';' -InputObject $CIPlan.signature
97+
}
98+
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers signature -u -m $SignatureCheckModuleList
99+
}
100+
101+
If ($StaticAnalysisHelp)
102+
{
103+
If ($PSBoundParameters.ContainsKey("ModuleList"))
104+
{
105+
$HelpCheckModuleList = $ModuleList
106+
}
107+
Else
108+
{
109+
$HelpCheckModuleList = Join-String -Separator ';' -InputObject $CIPlan.help
110+
}
111+
dotnet $RepoArtifacts/StaticAnalysis/StaticAnalysis.Netcore.dll -p $RepoArtifacts/$Configuration -r $StaticAnalysisOutputDirectory --analyzers help -u -m $HelpCheckModuleList
112+
}

0 commit comments

Comments
 (0)