Skip to content

Commit edd743c

Browse files
wyunchi-msisra-fel
andauthored
Add logic to produce pipeline result for github bot to comsume (Azure#19878)
* 1. Add logic for build and static analysis job to produce `PipelineResult.json` for github bot to consume. 2. Rename the table title of existing Static Analysis exceptions for each module. 3. Add variable in pipeline yml to let script get PowerShell platform in azure pipeline. * Rename CollectError.ps1 to CollectStaticAnalysisPipelineResult.ps1 * Update .azure-pipelines/windows-powershell.yml Co-authored-by: Yeming Liu <11371776+isra-fel@users.noreply.github.com> * Rename status Co-authored-by: Yeming Liu <11371776+isra-fel@users.noreply.github.com>
1 parent de3fc2f commit edd743c

File tree

235 files changed

+970
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+970
-374
lines changed

.azure-pipelines/powershell-core.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ variables:
1414
AnalysisTimeoutInMinutes: 120
1515
TestTimeoutInMinutes: 180
1616
BuildAzPredictor: false
17+
PowerShellPlatform: PowerShell Core
1718

1819
trigger: none
1920

@@ -43,6 +44,7 @@ jobs:
4344
osName: $(OSName)
4445
configuration: ${{ variables.Configuration }}
4546
testFramework: ${{ variables.TestFramework }}
47+
powerShellPlatform: ${{ variables.PowerShellPlatform }}
4648

4749
- job: Analyze
4850
displayName: Analyze
@@ -63,6 +65,7 @@ jobs:
6365
osName: $(OSName)
6466
configuration: ${{ variables.Configuration }}
6567
testFramework: ${{ variables.TestFramework }}
68+
powerShellPlatform: ${{ variables.PowerShellPlatform }}
6669

6770
- job: Test
6871
displayName: Test
@@ -90,3 +93,4 @@ jobs:
9093
testFramework: ${{ variables.TestFramework }}
9194
testTarget: ${{ variables.TestTarget }}
9295
configuration: ${{ variables.Configuration }}
96+
powerShellPlatform: ${{ variables.PowerShellPlatform }}

.azure-pipelines/util/analyze-steps.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
osName: ''
33
configuration: ''
44
testFramework: ''
5+
powerShellPlatform: ''
56

67
steps:
78
- template: download-build-steps.yml
@@ -51,6 +52,7 @@ steps:
5152
arguments: 'build.proj /t:GenerateHelp /p:Configuration=${{ parameters.configuration }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
5253
env:
5354
OCTOKITPAT: $(OCTOKITPAT)
55+
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
5456

5557
- task: DotNetCoreCLI@2
5658
displayName: 'Static Analysis'

.azure-pipelines/util/build-steps.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
osName: ''
33
testFramework: ''
44
configuration: ''
5+
powerShellPlatform: ''
56

67
steps:
78
- task: NodeTool@0
@@ -51,6 +52,7 @@ steps:
5152
arguments: 'build.proj /t:Build /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
5253
env:
5354
OCTOKITPAT: $(OCTOKITPAT)
55+
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
5456

5557
- task: PowerShell@2
5658
displayName: Build-AzPredictor

.azure-pipelines/util/test-steps.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ parameters:
33
testFramework: ''
44
testTarget: ''
55
configuration: ''
6+
powerShellPlatform: ''
67

78
steps:
89
- template: download-build-steps.yml
@@ -38,6 +39,7 @@ steps:
3839
arguments: 'build.proj /t:${{ parameters.testTarget }} /p:Configuration=${{ parameters.configuration }};TestFramework=${{ parameters.testFramework }};PullRequestNumber=$(System.PullRequest.PullRequestNumber)'
3940
env:
4041
OCTOKITPAT: $(OCTOKITPAT)
42+
PowerShellPlatform: ${{ parameters.powerShellPlatform }}
4143

4244
- powershell: |
4345
Install-Module -Name Pester -RequiredVersion 4.10.1 -Force -SkipPublisherCheck

.azure-pipelines/windows-powershell.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ variables:
88
IsGenerateBased: $[eq(variables['system.pullRequest.targetBranch'], 'generation')]
99
BuildTimeoutInMinutes: 120
1010
AnalysisTimeoutInMinutes: 120
11+
PowerShellPlatform: Windows PowerShell
1112

1213
trigger: none
1314

@@ -35,6 +36,7 @@ jobs:
3536
osName: ${{ variables.WindowsName }}
3637
testFramework: ${{ variables.TestFramework }}
3738
configuration: ${{ variables.Configuration }}
39+
powerShellPlatform: ${{ variables.PowerShellPlatform }}
3840

3941
- job: Analyze
4042
displayName: Analyze
@@ -55,6 +57,7 @@ jobs:
5557
osName: $(OSName)
5658
configuration: ${{ variables.Configuration }}
5759
testFramework: ${{ variables.TestFramework }}
60+
powerShellPlatform: ${{ variables.PowerShellPlatform }}
5861

5962
- job: Test
6063
displayName: Test
@@ -76,3 +79,4 @@ jobs:
7679
testFramework: ${{ variables.TestFramework }}
7780
testTarget: ${{ variables.TestTarget }}
7881
configuration: ${{ variables.Configuration }}
82+
powerShellPlatform: ${{ variables.PowerShellPlatform }}

.ci-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
],
8989
"phases": [
9090
"build:module",
91-
"help:module"
91+
"help:module",
92+
"example:module"
9293
]
9394
},
9495
{

build.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@
272272
<Message Importance="high" Text="Running static analysis..." />
273273

274274
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/CheckAssemblies.ps1 -BuildConfig $(Configuration) &quot;" />
275-
275+
276+
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;. $(RepoTools)/StaticAnalysis/CollectStaticAnalysisPipelineResult.ps1 -StaticAnalysisOutputDirectory $(StaticAnalysisOutputDirectory) &quot;"/>
276277
<Exec Command="dotnet $(RepoArtifacts)StaticAnalysis/StaticAnalysis.Netcore.dll -p $(RepoArtifacts)$(Configuration) -r $(StaticAnalysisOutputDirectory) --analyzers check-error" />
277278
<OnError ExecuteTargets="StaticAnalysisErrorMessage" />
278279
</Target>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class CIFilterTask : Task
7070

7171
private const string BUILD_PHASE = "build";
7272
private const string ANALYSIS_BREAKING_CHANGE_PHASE = "breaking-change";
73+
private const string ANALYSIS_HELP_EXAMPLE_PHASE = "help-example";
7374
private const string ANALYSIS_HELP_PHASE = "help";
7475
private const string ANALYSIS_DEPENDENCY_PHASE = "dependency";
7576
private const string ANALYSIS_SIGNATURE_PHASE = "signature";
@@ -186,6 +187,7 @@ private bool ProcessTargetModule(Dictionary<string, string[]> csprojMap)
186187
[BUILD_PHASE] = new HashSet<string>(GetBuildCsprojList(TargetModule, csprojMap).ToList()),
187188
[ANALYSIS_BREAKING_CHANGE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
188189
[ANALYSIS_DEPENDENCY_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
190+
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
189191
[ANALYSIS_HELP_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
190192
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(GetDependenceModuleList(TargetModule, csprojMap).ToList()),
191193
[TEST_PHASE] = new HashSet<string>(GetTestCsprojList(TargetModule, csprojMap).ToList())
@@ -240,6 +242,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
240242
BUILD_PHASE + ":" + AllModule,
241243
ANALYSIS_BREAKING_CHANGE_PHASE + ":" + AllModule,
242244
ANALYSIS_DEPENDENCY_PHASE + ":" + AllModule,
245+
ANALYSIS_HELP_EXAMPLE_PHASE + ":" + AllModule,
243246
ANALYSIS_HELP_PHASE + ":" + AllModule,
244247
ANALYSIS_SIGNATURE_PHASE + ":" + AllModule,
245248
TEST_PHASE + ":" + AllModule,
@@ -287,6 +290,7 @@ private Dictionary<string, HashSet<string>> CalculateInfluencedModuleInfoForEach
287290
BUILD_PHASE,
288291
ANALYSIS_BREAKING_CHANGE_PHASE,
289292
ANALYSIS_DEPENDENCY_PHASE,
293+
ANALYSIS_HELP_EXAMPLE_PHASE,
290294
ANALYSIS_HELP_PHASE,
291295
ANALYSIS_SIGNATURE_PHASE,
292296
TEST_PHASE
@@ -406,6 +410,7 @@ private bool ProcessFileChanged(Dictionary<string, string[]> csprojMap)
406410
[BUILD_PHASE] = new HashSet<string>(influencedModuleInfo[BUILD_PHASE].Select(GetModuleNameFromPath).Where(x => x != null)),
407411
[ANALYSIS_BREAKING_CHANGE_PHASE] = influencedModuleInfo[ANALYSIS_BREAKING_CHANGE_PHASE],
408412
[ANALYSIS_DEPENDENCY_PHASE] = influencedModuleInfo[ANALYSIS_DEPENDENCY_PHASE],
413+
[ANALYSIS_HELP_EXAMPLE_PHASE] = influencedModuleInfo[ANALYSIS_HELP_EXAMPLE_PHASE],
409414
[ANALYSIS_HELP_PHASE] = influencedModuleInfo[ANALYSIS_HELP_PHASE],
410415
[ANALYSIS_SIGNATURE_PHASE] = influencedModuleInfo[ANALYSIS_SIGNATURE_PHASE],
411416
[TEST_PHASE] = new HashSet<string>(influencedModuleInfo[TEST_PHASE].Select(GetModuleNameFromPath).Where(x => x != null))
@@ -455,6 +460,7 @@ public override bool Execute()
455460
[BUILD_PHASE] = new HashSet<string>(selectedModuleList),
456461
[ANALYSIS_BREAKING_CHANGE_PHASE] = new HashSet<string>(selectedModuleList),
457462
[ANALYSIS_DEPENDENCY_PHASE] = new HashSet<string>(selectedModuleList),
463+
[ANALYSIS_HELP_EXAMPLE_PHASE] = new HashSet<string>(selectedModuleList),
458464
[ANALYSIS_HELP_PHASE] = new HashSet<string>(selectedModuleList),
459465
[ANALYSIS_SIGNATURE_PHASE] = new HashSet<string>(selectedModuleList),
460466
[TEST_PHASE] = new HashSet<string>(selectedModuleList)

tools/ExecuteCIStep.ps1

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ If ($Build)
8181
$Detail = Join-String -Separator ": " -InputObject $Detail
8282
If ($Position.Contains("src"))
8383
{
84-
$ModuleName = $Position.Replace("\", "/").Split("src/")[1].Split('/')[0]
84+
$ModuleName = "Az." + $Position.Replace("\", "/").Split("src/")[1].Split('/')[0]
8585
}
8686
Else
8787
{
@@ -96,7 +96,99 @@ If ($Build)
9696
"Detail" = $Detail
9797
}
9898
}
99-
ConvertTo-Json -Depth 10 -InputObject $BuildResultArray | Out-File -FilePath "$RepoArtifacts/PipelineResult/Build.json"
99+
100+
#Region produce result.json for GitHub bot to comsume
101+
If ($IsWindows)
102+
{
103+
$OS = "Windows"
104+
}
105+
ElseIf ($IsLinux)
106+
{
107+
$OS = "Linux"
108+
}
109+
ElseIf ($IsMacOS)
110+
{
111+
$OS = "MacOS"
112+
}
113+
Else
114+
{
115+
$OS = "Others"
116+
}
117+
$Platform = "$($Env:PowerShellPlatform) - $OS"
118+
$Template = Get-Content "$PSScriptRoot/PipelineResultTemplate.json" | ConvertFrom-Json
119+
$ModuleBuildInfoList = @()
120+
$CIPlan = Get-Content "$RepoArtifacts/PipelineResult/CIPlan.json" | ConvertFrom-Json
121+
ForEach ($ModuleName In $CIPlan.build)
122+
{
123+
$BuildResultOfModule = $BuildResultArray | Where-Object { $_.Module -Eq "Az.$ModuleName" }
124+
If ($BuildResultOfModule.Length -Eq 0)
125+
{
126+
$ModuleBuildInfoList += @{
127+
Module = "Az.$ModuleName";
128+
Status = "Success";
129+
Content = "";
130+
}
131+
}
132+
Else
133+
{
134+
$Content = "|Type|Code|Position|Detail|`n|---|---|---|---|`n"
135+
ForEach ($BuildResult In $BuildResultOfModule)
136+
{
137+
If ($BuildResult.Type -Eq "Error")
138+
{
139+
$ErrorTypeEmoji = ""
140+
}
141+
ElseIf ($BuildResult.Type -Eq "Warning")
142+
{
143+
$ErrorTypeEmoji = "⚠️"
144+
}
145+
$Content += "|$ErrorTypeEmoji|$($BuildResult.Code)|$($BuildResult.Position)|$($BuildResult.Detail)|`n"
146+
}
147+
$ModuleBuildInfoList += @{
148+
Module = "Az.$ModuleName";
149+
Status = "Failed";
150+
Content = $Content;
151+
}
152+
}
153+
}
154+
$BuildDetail = @{
155+
Platform = $Platform;
156+
Modules = $ModuleBuildInfoList;
157+
}
158+
If ($BuildResultArray.Length -Ne 0)
159+
{
160+
$BuildDetail.Status = "Failed"
161+
$DependencyStepStatus = "Canceled"
162+
}
163+
Else
164+
{
165+
$BuildDetail.Status = "Success"
166+
$DependencyStepStatus = "Running"
167+
}
168+
$Template.Build.Details += $BuildDetail
169+
170+
$DependencyStepList = $Template | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | Where-Object { $_ -Ne "build" }
171+
172+
ForEach ($DependencyStep In $DependencyStepList)
173+
{
174+
$ModuleInfoList = @()
175+
ForEach ($ModuleName In $CIPlan.$DependencyStep)
176+
{
177+
$ModuleInfoList += @{
178+
Module = "Az.$ModuleName";
179+
Status = $DependencyStepStatus;
180+
Content = "";
181+
}
182+
}
183+
$Detail = @{
184+
Status = $DependencyStepStatus;
185+
Modules = $ModuleInfoList;
186+
}
187+
$Template.$DependencyStep.Details += $Detail
188+
}
189+
190+
ConvertTo-Json -Depth 10 -InputObject $Template | Out-File -FilePath "$RepoArtifacts/PipelineResult/PipelineResult.json"
191+
#EndRegion
100192
}
101193
Return
102194
}

tools/PipelineResultTemplate.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"build": {
3+
"Name": "Build",
4+
"Order": 1,
5+
"Details": [
6+
]
7+
},
8+
"breaking-change": {
9+
"Name": "Breaking Change Check",
10+
"Order": 2,
11+
"Details": [
12+
]
13+
},
14+
"signature": {
15+
"Name": "Signature Check",
16+
"Order": 3,
17+
"Details": [
18+
]
19+
},
20+
"help-example": {
21+
"Name": "Help Example Check",
22+
"Order": 4,
23+
"Details": [
24+
]
25+
},
26+
"help": {
27+
"Name": "Help File Existence Check",
28+
"Order": 5,
29+
"Details": [
30+
]
31+
},
32+
"test": {
33+
"Name": "Test",
34+
"Order": 100,
35+
"Details": [
36+
]
37+
}
38+
}

0 commit comments

Comments
 (0)