UpdateRepos.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/env pwsh
  2. <#
  3. .SYNOPSIS
  4. Updates each repo Universe builds to new dependencies.props.
  5. .PARAMETER Source
  6. The NuGet package source to find the lineup on.
  7. .PARAMETER LineupID
  8. The ID of the Lineup to determine which versions to use.
  9. .PARAMETER LineupVersion
  10. The version of the Lineup to be used.
  11. .PARAMETER NoPush
  12. Make commits without pusing.
  13. .PARAMETER GitAuthorName
  14. The author name to use in the commit message. (Optional)
  15. .PARAMETER GitAuthorEmail
  16. The author email to use in the commit message. (Optional)
  17. .PARAMETER Force
  18. Specified this to push commits without prompting.
  19. .PARAMETER GitCommitArgs
  20. Any remaining arguments are passed as arguments to 'git commit' actions in each repo.
  21. #>
  22. [cmdletbinding(SupportsShouldProcess = $true)]
  23. param(
  24. [Parameter(Mandatory = $true)]
  25. [string]$Source,
  26. [Parameter(Mandatory = $true)]
  27. [string]$LineupID,
  28. [Parameter(Mandatory = $true)]
  29. [string]$LineupVersion,
  30. [switch]$NoPush,
  31. [string]$GitAuthorName = $null,
  32. [string]$GitAuthorEmail = $null,
  33. [switch]$Force,
  34. [string[]]$GitCommitArgs = @()
  35. )
  36. $ErrorActionPreference = 'Stop'
  37. Set-StrictMode -Version 2
  38. Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force
  39. $RepoRoot = Resolve-Path "$PSScriptRoot\.."
  40. $ModuleDirectory = Join-Path $RepoRoot "modules"
  41. $gitConfigArgs = @()
  42. if ($GitAuthorName) {
  43. $gitConfigArgs += '-c', "user.name=$GitAuthorName"
  44. }
  45. if ($GitAuthorEmail) {
  46. $gitConfigArgs += '-c', "user.email=$GitAuthorEmail"
  47. }
  48. Push-Location $ModuleDirectory
  49. try {
  50. $build_errors = @()
  51. # Get-Submodules also update --init's them
  52. $submodules = Get-Submodules $RepoRoot
  53. foreach ($submodule in $submodules) {
  54. Push-Location $submodule.path
  55. try {
  56. $depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
  57. if (!(Test-Path $depsFile)) {
  58. Write-Warning "No build\dependencies.props file exists for '$($submodule.module)'."
  59. continue
  60. }
  61. $koreBuildLock = "korebuild-lock.txt"
  62. $universeKoreBuildLock = (Join-Path $RepoRoot $koreBuildLock)
  63. $submoduleKoreBuildLock = (Join-Path $submodule.path $koreBuildLock)
  64. Copy-Item $universeKoreBuildLock $submoduleKoreBuildLock -Force
  65. Write-Verbose "About to update dependencies.props for $($submodule.module)"
  66. & .\run.ps1 upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile
  67. Invoke-Block { & git @gitConfigArgs add $depsFile $koreBuildLock }
  68. # If there were any changes test and push.
  69. & git diff --cached --quiet ./
  70. if ($LASTEXITCODE -ne 0) {
  71. Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
  72. # Prepare this submodule for push
  73. $sshUrl = "[email protected]:aspnet/$($submodule.module)"
  74. Invoke-Block { & git remote set-url --push origin $sshUrl }
  75. # Test the submodule
  76. try {
  77. Invoke-Block { & .\run.ps1 default-build }
  78. }
  79. catch {
  80. Write-Warning "Error in $($submodule.module): $_"
  81. $build_errors += @{
  82. Repo = $submodule.module
  83. Message = $_
  84. }
  85. continue
  86. }
  87. # Push the changes
  88. if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue("Pushing updates to repos.", 'Push the changes to these repos?')))) {
  89. try {
  90. Invoke-Block { & git @gitConfigArgs push origin HEAD:$submodule.branch}
  91. }
  92. catch {
  93. Write-Warning "Error in pushing $($submodule.module): $_"
  94. continue
  95. }
  96. }
  97. }
  98. else {
  99. Write-Host "No changes in $($submodule.module)"
  100. }
  101. }
  102. catch {
  103. Write-Warning "Error in $($submodule.module)"
  104. }
  105. finally {
  106. Pop-Location
  107. }
  108. }
  109. if ($build_errors.Count -gt 0 ) {
  110. throw "Failed to build"
  111. }
  112. }
  113. finally {
  114. Pop-Location
  115. }