|
| 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 |
0 commit comments