compose_build.ps1 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # Compose Build script
  6. #
  7. # Aggregate metadata about a build and produce a file with useful information about the build
  8. # for tools to consume and get a quick overview of the status of a completed build.
  9. param (
  10. [Parameter(Mandatory=$True)]
  11. [string]$rootPath
  12. )
  13. #
  14. # Aggregate build metadata and produce build.json
  15. #
  16. $outputJsonFile = Join-Path -Path $rootPath -ChildPath "build.json"
  17. $buildInfo = New-Object System.Object
  18. $changeJson = (Get-ChildItem -Path $rootPath "change.json" -Recurse)[0] | % { $_.FullName }
  19. $changeInfo = (Get-Content $changeJson) -join "`n" | ConvertFrom-Json
  20. # Determine the overall build status. Mark the build as "passed" until "failed" is encountered.
  21. $overallBuildStatus = "passed"
  22. $files = Get-ChildItem -Path $rootPath "*.json" -Recurse `
  23. | ? { ($_.Name -ne "change.json") -and ($_.Name -ne "build.json") } `
  24. | % { $_.FullName }
  25. $builds = New-Object System.Collections.ArrayList
  26. foreach ($file in $files) {
  27. $json = (Get-Content $file) -join "`n" | ConvertFrom-Json
  28. $_ = $builds.Add($json)
  29. if ($json.status -eq "failed") {
  30. $overallBuildStatus = "failed"
  31. }
  32. }
  33. $buildInfo | Add-Member -type NoteProperty -name status -value $overallBuildStatus
  34. $buildInfo | Add-Member -type NoteProperty -name change -value $changeInfo
  35. $buildInfo | Add-Member -type NoteProperty -name builds -value $builds
  36. $buildInfo | ConvertTo-Json | Write-Output
  37. $buildInfo | ConvertTo-Json | Out-File $outputJsonFile -Encoding ascii