UpdateRepos.ps1 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env pwsh
  2. <#
  3. .SYNOPSIS
  4. Updates each submodule this repo 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. $submodules = Get-Submodules $RepoRoot
  52. foreach ($submodule in $submodules) {
  53. Push-Location $submodule.path
  54. try {
  55. Invoke-Block { & git fetch }
  56. Invoke-Block { & git checkout origin/$($submodule.branch) }
  57. $depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
  58. if (!(Test-Path $depsFile)) {
  59. Write-Warning "No build\dependencies.props file exists for '$($submodule.module)'."
  60. continue
  61. }
  62. $koreBuildLock = "korebuild-lock.txt"
  63. $repoKoreBuildLock = (Join-Path $RepoRoot $koreBuildLock)
  64. $submoduleKoreBuildLock = (Join-Path $submodule.path $koreBuildLock)
  65. Copy-Item $repoKoreBuildLock $submoduleKoreBuildLock -Force
  66. Write-Verbose "About to update dependencies.props for $($submodule.module)"
  67. & .\run.ps1 upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile
  68. Invoke-Block { & git @gitConfigArgs add $depsFile $koreBuildLock }
  69. # If there were any changes test and push.
  70. & git diff --cached --quiet ./
  71. if ($LASTEXITCODE -ne 0) {
  72. Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
  73. # Prepare this submodule for push
  74. $sshUrl = "[email protected]:aspnet/$($submodule.module)"
  75. Invoke-Block { & git remote set-url --push origin $sshUrl }
  76. # Test the submodule
  77. try {
  78. Invoke-Block { & .\run.ps1 default-build /p:SkipTests=true }
  79. }
  80. catch {
  81. Write-Warning "Error in $($submodule.module): $_"
  82. $build_errors += @{
  83. Repo = $submodule.module
  84. Message = $_
  85. }
  86. continue
  87. }
  88. # Push the changes
  89. if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue("Pushing updates to repos.", 'Push the changes to these repos?')))) {
  90. try {
  91. Invoke-Block { & git @gitConfigArgs push origin HEAD:$($submodule.branch)}
  92. }
  93. catch {
  94. Write-Warning "Error in pushing $($submodule.module): $_"
  95. $build_errors += @{
  96. Repo = $submodule.module
  97. Message = $_
  98. }
  99. continue
  100. }
  101. }
  102. }
  103. else {
  104. Write-Host "No changes in $($submodule.module)"
  105. }
  106. }
  107. catch {
  108. Write-Warning "Error in $($submodule.module): $_"
  109. $build_errors += @{
  110. Repo = $submodule.module
  111. Message = $_
  112. }
  113. }
  114. finally {
  115. Pop-Location
  116. }
  117. }
  118. if ($build_errors.Count -gt 0 ) {
  119. Write-Warning "The following repos failed:"
  120. foreach ($error in $build_errors) {
  121. Write-Warning " - $($error.Repo)"
  122. }
  123. throw "Failed to build"
  124. }
  125. }
  126. finally {
  127. Pop-Location
  128. }