Fix UpdateRepos.ps1
This commit is contained in:
parent
f276890f62
commit
639d49713e
|
|
@ -9,20 +9,22 @@
|
||||||
The ID of the Lineup to determine which versions to use.
|
The ID of the Lineup to determine which versions to use.
|
||||||
.PARAMETER LineupVersion
|
.PARAMETER LineupVersion
|
||||||
The version of the Lineup to be used.
|
The version of the Lineup to be used.
|
||||||
|
.PARAMETER NoPush
|
||||||
|
Make commits without pusing.
|
||||||
.PARAMETER GitAuthorName
|
.PARAMETER GitAuthorName
|
||||||
The author name to use in the commit message. (Optional)
|
The author name to use in the commit message. (Optional)
|
||||||
.PARAMETER GitAuthorEmail
|
.PARAMETER GitAuthorEmail
|
||||||
The author email to use in the commit message. (Optional)
|
The author email to use in the commit message. (Optional)
|
||||||
.PARAMETER NoPush
|
.PARAMETER GitCommitArgs
|
||||||
Make commits without pusing.
|
Any remaining arguments are passed as arguments to 'git commit' actions in each repo.
|
||||||
#>
|
#>
|
||||||
[cmdletbinding(SupportsShouldProcess = $true)]
|
[cmdletbinding(SupportsShouldProcess = $true)]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$Source,
|
[string]$Source,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$LineupID,
|
[string]$LineupID,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[string]$LineupVersion,
|
[string]$LineupVersion,
|
||||||
[switch]$NoPush,
|
[switch]$NoPush,
|
||||||
[string]$GitAuthorName = $null,
|
[string]$GitAuthorName = $null,
|
||||||
|
|
@ -40,46 +42,44 @@ $ModuleDirectory = Join-Path $RepoRoot "modules"
|
||||||
|
|
||||||
$gitConfigArgs = @()
|
$gitConfigArgs = @()
|
||||||
if ($GitAuthorName) {
|
if ($GitAuthorName) {
|
||||||
$gitConfigArgs += '-c',"user.name=$GitAuthorName"
|
$gitConfigArgs += '-c', "user.name=$GitAuthorName"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($GitAuthorEmail) {
|
if ($GitAuthorEmail) {
|
||||||
$gitConfigArgs += '-c',"user.email=$GitAuthorEmail"
|
$gitConfigArgs += '-c', "user.email=$GitAuthorEmail"
|
||||||
}
|
}
|
||||||
|
|
||||||
Push-Location $ModuleDirectory
|
Push-Location $ModuleDirectory
|
||||||
try {
|
try {
|
||||||
# Init all submodules
|
# Init all submodules
|
||||||
Invoke-Block { & git submodule update --init }
|
Write-Verbose "Updating submodules..."
|
||||||
|
Invoke-Block { & git submodule update --init } | Out-Null
|
||||||
|
Write-Verbose "Submodules updated."
|
||||||
|
|
||||||
$update_errors = @()
|
$update_errors = @()
|
||||||
$submodules = Get-Submodules $RepoRoot
|
$submodules = Get-Submodules $RepoRoot
|
||||||
$updated_submodules = @()
|
$updated_submodules = @()
|
||||||
foreach($submodule in $submodules)
|
foreach ($submodule in $submodules) {
|
||||||
{
|
|
||||||
Push-Location $submodule.path
|
Push-Location $submodule.path
|
||||||
try {
|
try {
|
||||||
$depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
|
$depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props"
|
||||||
|
|
||||||
if (!Test-Path $depsFile)
|
if (!(Test-Path $depsFile)) {
|
||||||
{
|
Write-Warning "No build\dependencies.props file exists for $($submodule.module)."
|
||||||
Write-Warning "No build\dependencies.props file exists for $($submodule.module). "
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
# Move to latest commit on tracked branch
|
Write-Verbose "About to update dependencies.props for $($submodule.module)"
|
||||||
Invoke-Block { & git checkout --quiet $submodule.branch }
|
& .\run.ps1 -Update upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile
|
||||||
|
|
||||||
Invoke-Block { & .\run.ps1 -Update upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile }
|
|
||||||
Invoke-Block { & git add $depsFile }
|
|
||||||
|
|
||||||
Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
|
Invoke-Block { & git @gitConfigArgs commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs }
|
||||||
|
|
||||||
$sshUrl = "git@github.com:aspnet/$($submodule.module)"
|
$sshUrl = "git@github.com:aspnet/$($submodule.module)"
|
||||||
Invoke-Block { & git remote set-url --push origin $sshUrl }
|
Invoke-Block { & git remote set-url --push origin $sshUrl }
|
||||||
$updated_submodules += $submodule
|
$updated_submodules += $submodule
|
||||||
}
|
}
|
||||||
catch
|
catch {
|
||||||
{
|
Write-Warning "Error in $($submodule.module)"
|
||||||
$update_errors += $_
|
$update_errors += $_
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
@ -87,22 +87,25 @@ try {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($update_errors.Count -gt 0 )
|
if ($update_errors.Count -gt 0 ) {
|
||||||
{
|
foreach ($update_error in $update_errors) {
|
||||||
|
Write-Error "$update_error"
|
||||||
|
}
|
||||||
|
|
||||||
throw 'Failed to update'
|
throw 'Failed to update'
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Write-Verbose "All updates successful!"
|
||||||
|
}
|
||||||
|
|
||||||
if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Push the changes to these repos?'))))
|
if (-not $NoPush -and ($Force -or ($PSCmdlet.ShouldContinue($shortMessage, 'Push the changes to these repos?')))) {
|
||||||
{
|
|
||||||
$push_errors = @()
|
$push_errors = @()
|
||||||
foreach($submodule in $updated_submodules)
|
foreach ($submodule in $updated_submodules) {
|
||||||
{
|
|
||||||
Push-Location $submodule.path
|
Push-Location $submodule.path
|
||||||
try {
|
try {
|
||||||
Invoke-Block { & git @gitConfigArgs push origin $submodule.branch}
|
Invoke-Block { & git @gitConfigArgs push origin HEAD:$submodule.branch}
|
||||||
}
|
}
|
||||||
catch
|
catch {
|
||||||
{
|
|
||||||
$push_errors += $_
|
$push_errors += $_
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
@ -110,8 +113,7 @@ try {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($push_errors.Count -gt 0 )
|
if ($push_errors.Count -gt 0 ) {
|
||||||
{
|
|
||||||
throw 'Failed to push'
|
throw 'Failed to push'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ function Invoke-Block([scriptblock]$cmd) {
|
||||||
# - $?: did the powershell script block throw an error
|
# - $?: did the powershell script block throw an error
|
||||||
# - $lastexitcode: did a windows command executed by the script block end in error
|
# - $lastexitcode: did a windows command executed by the script block end in error
|
||||||
if ((-not $?) -or ($lastexitcode -ne 0)) {
|
if ((-not $?) -or ($lastexitcode -ne 0)) {
|
||||||
|
Write-Warning $error[0]
|
||||||
throw "Command failed to execute: $cmd"
|
throw "Command failed to execute: $cmd"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue