Skip to content

Commit 625a7cb

Browse files
committed
analyse
1 parent 0c5d692 commit 625a7cb

File tree

6 files changed

+559
-310
lines changed

6 files changed

+559
-310
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
param (
2+
[string]$MatrixKey,
3+
[string]$RepoRoot
4+
)
5+
6+
$utilFilePath = Join-Path $RepoRoot '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'util.psm1'
7+
Import-Module $utilFilePath -Force
8+
$moduleGroup = Get-Targets -RepoRoot $RepoRoot -TargetsOutputFileName "analyzeTargets.json" -MatrixKey $MatrixKey
9+
$RepoArtifacts = Join-Path $RepoRoot 'artifacts'
10+
$StaticAnalysisOutputDirectory = Join-Path $RepoArtifacts 'StaticAnalysisResults'
11+
if (-not (Test-Path -Path $StaticAnalysisOutputDirectory)) {
12+
New-Item -ItemType Directory -Path $StaticAnalysisOutputDirectory
13+
}
14+
$toolsDirectory = Join-Path $RepoRoot 'tools'
15+
16+
$results = @()
17+
foreach ($moduleName in $moduleGroup) {
18+
Write-Host "=============================================================="
19+
Write-Host "Analysing Module: $moduleName"
20+
21+
$startTime = Get-Date
22+
$result = @{
23+
Module = $moduleName
24+
Status = "Success"
25+
DurationSeconds = 0
26+
Error = ""
27+
FailedTasks = @()
28+
}
29+
$Parameters = @{
30+
RepoArtifacts = $RepoArtifacts
31+
StaticAnalysisOutputDirectory = $StaticAnalysisOutputDirectory
32+
Configuration = "Debug"
33+
TargetModule = @($moduleName)
34+
}
35+
$FailedTasks = @()
36+
$ErrorLogPath = "$StaticAnalysisOutputDirectory/error.log"
37+
38+
try {
39+
.("$toolsDirectory/ExecuteCIStep.ps1") -StaticAnalysisBreakingChange @Parameters 2>$ErrorLogPath
40+
If (($LASTEXITCODE -ne 0) -and ($LASTEXITCODE -ne $null))
41+
{
42+
$FailedTasks += "BreakingChange"
43+
}
44+
.("$toolsDirectory/ExecuteCIStep.ps1") -StaticAnalysisDependency @Parameters 2>>$ErrorLogPath
45+
If (($LASTEXITCODE -ne 0) -and ($LASTEXITCODE -ne $null))
46+
{
47+
$FailedTasks += "Dependency"
48+
}
49+
.("$toolsDirectory/ExecuteCIStep.ps1") -StaticAnalysisSignature @Parameters 2>>$ErrorLogPath
50+
If (($LASTEXITCODE -ne 0) -and ($LASTEXITCODE -ne $null))
51+
{
52+
$FailedTasks += "Signature"
53+
}
54+
.("$toolsDirectory/ExecuteCIStep.ps1") -StaticAnalysisHelp @Parameters 2>>$ErrorLogPath
55+
If (($LASTEXITCODE -ne 0) -and ($LASTEXITCODE -ne $null))
56+
{
57+
$FailedTasks += "Help"
58+
}
59+
.("$toolsDirectory/ExecuteCIStep.ps1") -StaticAnalysisUX @Parameters 2>>$ErrorLogPath
60+
If (($LASTEXITCODE -ne 0) -and ($LASTEXITCODE -ne $null))
61+
{
62+
$FailedTasks += "UXMetadata"
63+
}
64+
.("$toolsDirectory/ExecuteCIStep.ps1") -StaticAnalysisCmdletDiff @Parameters 2>>$ErrorLogPath
65+
If (($LASTEXITCODE -ne 0) -and ($LASTEXITCODE -ne $null))
66+
{
67+
$FailedTasks += "CmdletDiff"
68+
}
69+
If ($FailedTasks.Length -ne 0)
70+
{
71+
Write-Host "There are failed tasks: $FailedTasks"
72+
$ErrorLog = Get-Content -Path $ErrorLogPath | Join-String -Separator "`n"
73+
Write-Error $ErrorLog
74+
$result.Status = "Failed"
75+
$result.Error = "Failed tasks: $($FailedTasks -join ', ')"
76+
$result.FailedTasks = $FailedTasks
77+
}
78+
} catch {
79+
Write-Warning "Failed to analyse module: $moduleName"
80+
Write-Warning "Error message: $($_.Exception.Message)"
81+
$result.Status = "Failed"
82+
$result.Error = $_.Exception.Message
83+
} finally {
84+
$endTine = Get-Date
85+
$result.DurationSeconds = ($endTine - $startTime).TotalSeconds
86+
$results += $result
87+
}
88+
}
89+
90+
$reportPath = Join-Path $RepoRoot "artifacts" "AnalyseReport-$MatrixKey.json"
91+
$results | ConvertTo-Json -Depth 5 | Out-File -FilePath $reportPath -Encoding utf8

.azure-pipelines/PipelineSteps/BatchGeneration/batch-generate-modules.ps1

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ param (
33
[string]$RepoRoot
44
)
55

6-
Write-Host "Matrix Key: $MatrixKey"
7-
86
$generateTargetsOutputFile = Join-Path $RepoRoot "artifacts" "generateTargets.json"
97
$generateTargets = Get-Content -Path $generateTargetsOutPutFile -Raw | ConvertFrom-Json
108
$moduleGroup = $generateTargets.$MatrixKey
9+
Write-Host "##[group]Generating module group $MatrixKey"
10+
foreach ($key in $moduleGroup.PSObject.Properties.Name | Sort-Object) {
11+
$values = $moduleGroup.$key -join ', '
12+
Write-Output "$key : $values"
13+
}
14+
Write-Host "##[endgroup]"
15+
Write-Host
1116
$sortedModuleNames = $moduleGroup.PSObject.Properties.Name | Sort-Object
1217

1318
$AutorestOutputDir = Join-Path $RepoRoot "artifacts" "autorest"
@@ -57,6 +62,7 @@ foreach ($moduleName in $sortedModuleNames) {
5762

5863
} catch {
5964
Write-Warning "Failed to regenerate module: $moduleName, sub module: $subModuleName"
65+
Write-Warning "Error message: $($_.Exception.Message)"
6066
$subModuleResult.Status = "Failed"
6167
$subModuleResult.Error = $_.Exception.Message
6268
} finally {
@@ -71,6 +77,7 @@ foreach ($moduleName in $sortedModuleNames) {
7177
}
7278

7379
$ArtifactOutputDir = Join-Path $RepoRoot "artifacts"
80+
Set-Location $RepoRoot
7481

7582
git add .
7683
$patchPath = Join-Path $ArtifactOutputDir "changed-$MatrixKey.patch"

.azure-pipelines/PipelineSteps/BatchGeneration/build-module.ps1 renamed to .azure-pipelines/PipelineSteps/BatchGeneration/build-modules.ps1

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ param (
33
[string]$RepoRoot
44
)
55

6-
Write-Host "Matrix Key: $MatrixKey"
7-
8-
$buildTargetsOutputFile = Join-Path $RepoRoot "artifacts" "buildTargets.json"
9-
$buildTargets = Get-Content -Path $buildTargetsOutputFile -Raw | ConvertFrom-Json
10-
$moduleGroup = $buildTargets.$MatrixKey
6+
$utilFilePath = Join-Path $RepoRoot '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'util.psm1'
7+
Import-Module $utilFilePath -Force
8+
$moduleGroup = Get-Targets -RepoRoot $RepoRoot -TargetsOutputFileName "buildTargets.json" -MatrixKey $MatrixKey
119
$buildModulesPath = Join-Path $RepoRoot 'tools' 'BuildScripts' 'BuildModules.ps1'
1210

1311
$results = @()
@@ -27,6 +25,7 @@ foreach ($moduleName in $moduleGroup) {
2725
& $buildModulesPath -TargetModule $moduleName -InvokedByPipeline
2826
} catch {
2927
Write-Warning "Failed to build module: $moduleName"
28+
Write-Warning "Error message: $($_.Exception.Message)"
3029
$result.Status = "Failed"
3130
$result.Error = $_.Exception.Message
3231
} finally {

.azure-pipelines/PipelineSteps/BatchGeneration/test-module.ps1

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ param (
66
[string]$ArtifactRoot
77
)
88

9-
Write-Host "Matrix Key: $MatrixKey"
10-
Write-Host "Test $($TestEnvName): $Target"
9+
$utilFilePath = Join-Path $RepoRoot '.azure-pipelines' 'PipelineSteps' 'BatchGeneration' 'util.psm1'
10+
Import-Module $utilFilePath -Force
11+
$subModuleGroup = Get-Targets -RepoRoot $RepoRoot -TargetsOutputFileName "testWindowsTargets.json" -MatrixKey $MatrixKey
1112

12-
$modules = $Target -split ','
1313
$results = @()
1414

15-
foreach ($module in $modules) {
15+
foreach ($subModule in $subModuleGroup) {
1616
$startTime = Get-Date
1717
$result = @{
1818
Module = $module
@@ -31,6 +31,7 @@ foreach ($module in $modules) {
3131
}
3232
catch {
3333
Write-Warning "Failed to test module: $module"
34+
Write-Warning "Error message: $($_.Exception.Message)"
3435
$result.Status = "Failed"
3536
$result.Error = $_.Exception.Message
3637
}

.azure-pipelines/PipelineSteps/BatchGeneration/util.psm1

+17
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,20 @@ function Write-Matrix {
5858
$targetsOutputFile = Join-Path $targetsOutputDir "$VariableName.json"
5959
$targets | ConvertTo-Json -Depth 5 | Out-File -FilePath $targetsOutputFile -Encoding utf8
6060
}
61+
62+
function Get-Targets {
63+
param (
64+
[string]$RepoRoot,
65+
[string]$TargetsOutputFileName,
66+
[string]$MatrixKey
67+
)
68+
69+
$targetsOutputFile = Join-Path $RepoRoot "artifacts" $TargetsOutputFileName
70+
$targetGroups = Get-Content -Path $targetsOutputFile -Raw | ConvertFrom-Json
71+
$targetGroup = $targetGroups.$MatrixKey
72+
Write-Host "##[group]Target group: $MatrixKey"
73+
$targetGroup | ForEach-Object { Write-Host $_ }
74+
Write-Host "##[endgroup]"
75+
Write-Host
76+
return $targetGroup
77+
}

0 commit comments

Comments
 (0)