|
| 1 | +#------------------------------------------------------------------------------------------------------- |
| 2 | +# Copyright (C) Microsoft. All rights reserved. |
| 3 | +# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
| 4 | +#------------------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +# Compose Build script |
| 7 | +# |
| 8 | +# Aggregate metadata about a build and produce a file with useful information about the build |
| 9 | +# for tools to consume and get a quick overview of the status of a completed build. |
| 10 | + |
| 11 | +param ( |
| 12 | + [Parameter(Mandatory=$True)] |
| 13 | + [string]$rootPath |
| 14 | +) |
| 15 | + |
| 16 | +# |
| 17 | +# Clean up the sentinel which previously marked this build as incomplete. |
| 18 | +# |
| 19 | + |
| 20 | +$buildIncompleteFile = Join-Path $rootPath "build.incomplete" |
| 21 | +if (Test-Path $buildIncompleteFile) { |
| 22 | + Remove-Item -Path $buildIncompleteFile -Force |
| 23 | +} |
| 24 | + |
| 25 | +# |
| 26 | +# Aggregate build metadata and produce build.json |
| 27 | +# |
| 28 | + |
| 29 | +$outputJsonFile = Join-Path -Path $rootPath -ChildPath "build.json" |
| 30 | +$buildInfo = New-Object System.Object |
| 31 | + |
| 32 | +$changeJson = (Get-ChildItem -Path $rootPath "change.json" -Recurse)[0] | % { $_.FullName } |
| 33 | +$changeInfo = (Get-Content $changeJson) -join "`n" | ConvertFrom-Json |
| 34 | + |
| 35 | +# Determine the overall build status. Mark the build as "passed" until "failed" is encountered. |
| 36 | +$overallBuildStatus = "passed" |
| 37 | + |
| 38 | +$files = Get-ChildItem -Path $rootPath "*.json" -Recurse ` |
| 39 | + | ? { ($_.Name -ne "change.json") -and ($_.Name -ne "build.json") } ` |
| 40 | + | % { $_.FullName } |
| 41 | +$builds = New-Object System.Collections.ArrayList |
| 42 | +foreach ($file in $files) { |
| 43 | + $json = (Get-Content $file) -join "`n" | ConvertFrom-Json |
| 44 | + $_ = $builds.Add($json) |
| 45 | + |
| 46 | + if ($json.status -eq "failed") { |
| 47 | + $overallBuildStatus = "failed" |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +$buildInfo | Add-Member -type NoteProperty -name status -value $overallBuildStatus |
| 52 | +$buildInfo | Add-Member -type NoteProperty -name change -value $changeInfo |
| 53 | +$buildInfo | Add-Member -type NoteProperty -name builds -value $builds |
| 54 | + |
| 55 | +$buildInfo | ConvertTo-Json | Write-Output |
| 56 | +$buildInfo | ConvertTo-Json | Out-File $outputJsonFile -Encoding ascii |
0 commit comments