compose_build.ps1 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. $buildJsonFile = Join-Path $rootPath "build.json"
  17. $buildInfo = New-Object System.Object
  18. $changeJson = (Get-ChildItem -Path $rootPath "change.json" -Recurse)[0].FullName
  19. $changeText = (Get-ChildItem -Path $rootPath "change.txt" -Recurse)[0].FullName
  20. # Copy files found in a build metadata directory, protecting against the possibility that this
  21. # build was previously composed and that those files may already be in the destination dir.
  22. if (-not ($changeJson -eq (Join-Path $rootPath "change.json"))) {
  23. Copy-Item -Verbose -Force -Path $changeJson -Destination $rootPath
  24. }
  25. if (-not ($changeText -eq (Join-Path $rootPath "change.txt"))) {
  26. Copy-Item -Verbose -Force -Path $changeText -Destination $rootPath
  27. }
  28. $changeInfo = (Get-Content $changeJson) -join "`n" | ConvertFrom-Json
  29. # Recursively locate ${arch}_${flavor}.json and move to $rootPath.
  30. # This ensures that in the rebuild scenario, we don't have duplication of *.json files
  31. # between the partially-composed root and the metadata directories.
  32. # Exclude change.json and build.json, the results of a previous composition already in the root.
  33. Get-ChildItem -Path $rootPath "*.json" -Recurse `
  34. | ? { -not ($_.Name -in @("change.json", "build.json")) } `
  35. | % { Move-Item -Verbose -Force -Path $_.FullName -Destination $rootPath }
  36. # Determine the overall build status. Mark the build as "passed" until "failed" is encountered.
  37. $overallBuildStatus = "passed"
  38. $files = Get-ChildItem -Path $rootPath "*.json" -Recurse `
  39. | ? { -not ($_.Name -in @("change.json", "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. if ($json.status -eq "failed") {
  46. $overallBuildStatus = "failed"
  47. }
  48. }
  49. $buildInfo | Add-Member -type NoteProperty -name status -value $overallBuildStatus
  50. $buildInfo | Add-Member -type NoteProperty -name change -value $changeInfo
  51. $buildInfo | Add-Member -type NoteProperty -name builds -value $builds
  52. $buildInfo | ConvertTo-Json | Write-Output
  53. $buildInfo | ConvertTo-Json | Out-File $buildJsonFile -Encoding utf8