Skip to content

Commit 3e8f0b1

Browse files
Copilotjohlju
andcommitted
Improve output formatting for better readability in Azure Pipelines logs
Co-authored-by: johlju <7189721+johlju@users.noreply.github.com>
1 parent 3237291 commit 3e8f0b1

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

.build/Test-ShouldRunDscResourceIntegrationTests.ps1

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -306,30 +306,35 @@ function Test-ShouldRunDscResourceIntegrationTests
306306
$SourcePath = 'source'
307307
)
308308

309-
Write-Output -InputObject "Analyzing changes between $BaseBranch and $CurrentBranch..."
309+
Write-Host "Analyzing changes between $BaseBranch and $CurrentBranch..."
310+
Write-Host ""
310311

311312
# Get list of public commands used by DSC resources dynamically
312313
$PublicCommandsUsedByDscResources = Get-PublicCommandsUsedByDscResources -SourcePath $SourcePath
313-
Write-Output -InputObject "Discovered $($PublicCommandsUsedByDscResources.Count) public commands used by DSC resources and classes."
314+
Write-Host "Discovered $($PublicCommandsUsedByDscResources.Count) public commands used by DSC resources and classes."
315+
Write-Host ""
314316

315317
$changedFiles = Get-ChangedFiles -From $BaseBranch -To $CurrentBranch
316318

317319
if (-not $changedFiles)
318320
{
319-
Write-Output -InputObject "No changed files detected. DSC resource integration tests will run by default."
321+
Write-Host "No changed files detected. DSC resource integration tests will run by default."
322+
Write-Host ""
320323
return $true
321324
}
322325

323-
Write-Output -InputObject "Changed files:"
324-
$changedFiles | ForEach-Object -Process { Write-Output -InputObject " $_" }
326+
Write-Host "Changed files:"
327+
$changedFiles | ForEach-Object -Process { Write-Host " $_" }
328+
Write-Host ""
325329

326330
# Check if any DSC resources are directly changed
327331
$changedDscResources = $changedFiles | Where-Object -FilterScript { $_ -match '^source/DSCResources/' -or $_ -match '^source/Classes/' }
328332
if ($changedDscResources)
329333
{
330-
Write-Output -InputObject "DSC resources or classes have been modified. DSC resource integration tests will run."
331-
Write-Output -InputObject "Changed DSC resources/classes:"
332-
$changedDscResources | ForEach-Object -Process { Write-Output -InputObject " $_" }
334+
Write-Host "DSC resources or classes have been modified. DSC resource integration tests will run."
335+
Write-Host "Changed DSC resources/classes:"
336+
$changedDscResources | ForEach-Object -Process { Write-Host " $_" }
337+
Write-Host ""
333338
return $true
334339
}
335340

@@ -340,9 +345,10 @@ function Test-ShouldRunDscResourceIntegrationTests
340345
$affectedCommands = $changedPublicCommands | Where-Object -FilterScript { $_ -in $PublicCommandsUsedByDscResources }
341346
if ($affectedCommands)
342347
{
343-
Write-Output -InputObject "Public commands used by DSC resources have been modified. DSC resource integration tests will run."
344-
Write-Output -InputObject "Affected commands:"
345-
$affectedCommands | ForEach-Object -Process { Write-Output -InputObject " $_" }
348+
Write-Host "Public commands used by DSC resources have been modified. DSC resource integration tests will run."
349+
Write-Host "Affected commands:"
350+
$affectedCommands | ForEach-Object -Process { Write-Host " $_" }
351+
Write-Host ""
346352
return $true
347353
}
348354

@@ -359,33 +365,37 @@ function Test-ShouldRunDscResourceIntegrationTests
359365

360366
if ($affectedPrivateFunctions)
361367
{
362-
Write-Output -InputObject "Private functions used by DSC resource-related public commands have been modified. DSC resource integration tests will run."
363-
Write-Output -InputObject "Affected private functions:"
364-
$affectedPrivateFunctions | ForEach-Object -Process { Write-Output -InputObject " $_" }
368+
Write-Host "Private functions used by DSC resource-related public commands have been modified. DSC resource integration tests will run."
369+
Write-Host "Affected private functions:"
370+
$affectedPrivateFunctions | ForEach-Object -Process { Write-Host " $_" }
371+
Write-Host ""
365372
return $true
366373
}
367374

368375
# Check if integration test files themselves are changed
369376
$changedIntegrationTests = $changedFiles | Where-Object -FilterScript { $_ -match '^tests/Integration/Resources/' }
370377
if ($changedIntegrationTests)
371378
{
372-
Write-Output -InputObject "DSC resource integration test files have been modified. DSC resource integration tests will run."
373-
Write-Output -InputObject "Changed integration test files:"
374-
$changedIntegrationTests | ForEach-Object -Process { Write-Output -InputObject " $_" }
379+
Write-Host "DSC resource integration test files have been modified. DSC resource integration tests will run."
380+
Write-Host "Changed integration test files:"
381+
$changedIntegrationTests | ForEach-Object -Process { Write-Host " $_" }
382+
Write-Host ""
375383
return $true
376384
}
377385

378386
# Check if pipeline configuration is changed
379387
$changedPipelineFiles = $changedFiles | Where-Object -FilterScript { $_ -match 'azure-pipelines\.yml$|\.build/' }
380388
if ($changedPipelineFiles)
381389
{
382-
Write-Output -InputObject "Pipeline configuration has been modified. DSC resource integration tests will run."
383-
Write-Output -InputObject "Changed pipeline files:"
384-
$changedPipelineFiles | ForEach-Object -Process { Write-Output -InputObject " $_" }
390+
Write-Host "Pipeline configuration has been modified. DSC resource integration tests will run."
391+
Write-Host "Changed pipeline files:"
392+
$changedPipelineFiles | ForEach-Object -Process { Write-Host " $_" }
393+
Write-Host ""
385394
return $true
386395
}
387396

388-
Write-Output -InputObject "No changes detected that would affect DSC resources. DSC resource integration tests can be skipped."
397+
Write-Host "No changes detected that would affect DSC resources. DSC resource integration tests can be skipped."
398+
Write-Host ""
389399
return $false
390400
}
391401

@@ -398,6 +408,7 @@ if ($MyInvocation.InvocationName -ne '.')
398408
Write-Output -InputObject "##vso[task.setvariable variable=ShouldRunDscResourceIntegrationTests]$shouldRun"
399409

400410
# Also output as regular output for local testing
411+
Write-Output -InputObject ""
401412
Write-Output -InputObject "ShouldRunDscResourceIntegrationTests: $shouldRun"
402413

403414
# Set exit code based on result for script usage

0 commit comments

Comments
 (0)