Skip to content

Commit b607d2d

Browse files
committed
Testing new warning capability in script as well as better DevOps console output
1 parent 7561e51 commit b607d2d

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

PipelineScripts/pre-build-validation.ps1

+64-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ImodSpecInfo {
99
[Boolean]$IsObsolete
1010
[Dependency[]]$Dependencies
1111
[string]$ReleaseNotes
12+
[string]$Tags
1213

1314
ImodSpecInfo([string]$filePath, [xml]$content) {
1415
$this.FilePath = $filePath
@@ -21,6 +22,7 @@ class ImodSpecInfo {
2122
$this.IsObsolete = $this.Description.ToLower().Contains("obsolete")
2223
$this.Dependencies = $content.package.dependencies.dependency | Where-Object { $null -ne $_.Id } | ForEach-Object { [Dependency]::new($_.id, $_.version) }
2324
$this.ReleaseNotes = $content.package.releaseNotes
25+
$this.Tags = $content.package.tags
2426
}
2527
}
2628

@@ -73,7 +75,44 @@ class VersionInfo {
7375
}
7476
}
7577

78+
function PrintError {
79+
param (
80+
[string]$Message,
81+
[Boolean]$DevOps
82+
)
83+
if ($DevOps) {
84+
Write-Host "##vso[task.logissue type=error;]$($Message)"
85+
} else {
86+
Write-Host "$($Message)" -ForegroundColor Red
87+
}
88+
}
89+
90+
function PrintWarning {
91+
param (
92+
[string]$Message,
93+
[Boolean]$DevOps
94+
)
95+
if ($DevOps) {
96+
Write-Host "##vso[task.logissue type=warning;]$($Message)"
97+
} else {
98+
Write-Host "$($Message)" -ForegroundColor DarkYellow
99+
}
100+
}
101+
102+
function PrintAffectedFileName {
103+
param (
104+
[string]$Name,
105+
[Boolean]$DevOps
106+
)
107+
if ($DevOps) {
108+
Write-Host "##[section]$($Name)"
109+
} else {
110+
Write-Host "# $($Name)" -ForegroundColor Green
111+
}
112+
}
113+
76114
$projectName = $args[0]
115+
$DevOps = [bool]$args[1]
77116
$imodSpecInfos = New-Object 'System.Collections.Generic.Dictionary[string, ImodSpecInfo]'
78117
$global:hasError = $false
79118

@@ -89,7 +128,7 @@ Get-ChildItem -Path Modules -Filter *.imodspec -Recurse -Depth 2 | ForEach-Objec
89128

90129
$spec = [ImodSpecInfo]::new($_.FullName, $content)
91130
if ($imodSpecInfos.ContainsKey($spec.Id)) {
92-
Write-Host "There is a duplicate Module Id found: $($spec.Id)"
131+
PrintError "There is a duplicate Module Id found: $($spec.Id)" $DevOps
93132
Write-Host " - $($file)"
94133
Write-Host " - $($imodSpecInfos[$spec.Id].FilePath)"
95134
$global:hasError = $true
@@ -164,20 +203,40 @@ $validationRules = @{
164203
}
165204
}
166205

206+
$validationWarnings = @{
207+
Tags = {
208+
param([ImodSpecInfo]$info)
209+
if (-not [System.String]::IsNullOrWhiteSpace($info.Tags)) {
210+
return "No tags specified"
211+
}
212+
}
213+
}
214+
167215
foreach ($info in $imodSpecInfos.Values) {
168216
$reportedFileName = $false
169217

170-
foreach ($rule in $validationRules.GetEnumerator()) {
171-
$result = & $rule.Value $info
218+
foreach ($validation in $validationRules.GetEnumerator()) {
219+
$result = & $validation.Value $info
172220
if ($result) {
173221
if (-not $reportedFileName) {
174-
Write-Host "# $($info.FilePath)"
222+
PrintAffectedFileName "$($info.FilePath)" $DevOps
175223
$reportedFileName = $true
176224
}
177-
Write-Host " - $($result)"
225+
PrintError " - $($result)" $DevOps
178226
$global:hasError = $true
179227
}
180228
}
229+
230+
foreach ($validation in $validationWarnings.GetEnumerator()) {
231+
$result = & $validation.Value $info
232+
if ($result) {
233+
if (-not $reportedFileName) {
234+
PrintAffectedFileName "$($info.FilePath)" $DevOps
235+
$reportedFileName = $true
236+
}
237+
PrintWarning " - $($result)" $DevOps
238+
}
239+
}
181240
}
182241

183242
if ($global:hasError) {

azure-pipelines.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ steps:
5555
inputs:
5656
pwsh: true
5757
filePath: 'PipelineScripts/pre-build-validation.ps1'
58-
arguments: '"Intent.Modules.NET"'
58+
arguments: '"Intent.Modules.NET" true'
5959

6060
# Required for entry in NuGet.Config that is generated as part of 'dotnet pack'.
6161
- task: NuGetAuthenticate@1

0 commit comments

Comments
 (0)