From 6652182b586a9e918e36d37fecaec712a89afb82 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 26 Oct 2017 16:18:42 -0700 Subject: [PATCH] Add script to update each Repo --- scripts/UpdateRepos.ps1 | 100 +++++++++++++++++++++++++++++++++++ scripts/UpdateSubmodules.ps1 | 25 ++------- scripts/common.psm1 | 29 ++++++++++ 3 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 scripts/UpdateRepos.ps1 diff --git a/scripts/UpdateRepos.ps1 b/scripts/UpdateRepos.ps1 new file mode 100644 index 0000000000..ce4bd276d8 --- /dev/null +++ b/scripts/UpdateRepos.ps1 @@ -0,0 +1,100 @@ +#!/usr/bin/env powershell + +<# +.SYNOPSIS + Updates each repo Universe builds to new dependencies.props +.PARAMETER Source + The NuGet package source to find the lineup on. +.PARAMETER LineupID + The ID of the Lineup to determine which versions to use. +.PARAMETER LineupVersion + The version of the Lineup to be used. +#> +[cmdletbinding(SupportsShouldProcess = $true)] +param( + [Parameter(Mandatory=$true)] + [string]$Source, + [Parameter(Mandatory=$true)] + [string]$LineupID, + [Parameter(Mandatory=$true)] + [string]$LineupVersion, + [string[]]$GitCommitArgs = @() +) + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version 2 + +Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force + +$RepoRoot = Resolve-Path "$PSScriptRoot\.." +$ModuleDirectory = Join-Path $RepoRoot "modules" + +Push-Location $ModuleDirectory +try { + # Init all submodules + Invoke-Block { & git submodule update --init } + + $update_errors = @() + $submodules = Get-Submodules $ModuleDirectory + $updated_submodules = @() + foreach($submodule in $submodules) + { + Push-Location $submodule.path + try { + $depsFile = Join-Path (Join-Path $($submodule.path) "build") "dependencies.props" + + if (!Test-Path $depsFile) + { + Write-Warning "No build\dependencies.props file exists for $($submodule.module). " + continue + } + + # Move to latest commit on tracked branch + Invoke-Block { & git checkout --quiet $submodule.branch } + + Invoke-Block { & .\run.ps1 upgrade deps --source $Source --id $LineupID --version $LineupVersion --deps-file $depsFile } + Invoke-Block { & git add $depsFile } + + Invoke-Block { & git commit --quiet -m "Update dependencies.props`n`n[auto-updated: dependencies]" @GitCommitArgs } + $sshUrl = "git@github.com:aspnet/$($submodule.module)" + Invoke-Block { & git remote set-url --push origin $sshUrl } + $updated_submodules += $submodule + } + catch + { + $update_errors += $_ + } + finally { + Pop-Location + } + } + + if ($update_errors.Count -gt 0 ) + { + throw 'Failed to update' + } + + $push_errors = @() + foreach($submodule in $updated_submodules) + { + Push-Location $submodule.path + try { + Invoke-Block { & git push origin $submodule.branch} + } + catch + { + $push_errors += $_ + } + finally { + Pop-Location + } + } + + if ($push_errors.Count -gt 0 ) + { + throw 'Failed to push' + } +} +finally { + Pop-Location +} diff --git a/scripts/UpdateSubmodules.ps1 b/scripts/UpdateSubmodules.ps1 index eb78545934..2ccdc8cdb9 100755 --- a/scripts/UpdateSubmodules.ps1 +++ b/scripts/UpdateSubmodules.ps1 @@ -21,6 +21,7 @@ $ErrorActionPreference = 'Stop' Set-StrictMode -Version 2 $RepoRoot = Resolve-Path "$PSScriptRoot\.." +$ModuleDirectory = Join-Path $RepoRoot "modules" Import-Module "$PSScriptRoot/common.psm1" -Scope Local -Force @@ -38,32 +39,12 @@ function Get-GitChanges([string]$Path) { try { Assert-Git - if (Get-GitChanges "$RepoRoot/modules") { + if (Get-GitChanges $ModuleDirectory) { Write-Error "$RepoRoot/modules is in an unclean state. Reset submodules first by running ``git submodule update``" exit 1 } - Invoke-Block { & git submodule update --init } - - $submodules = @() - - Get-ChildItem "$RepoRoot/modules/*" -Directory | % { - Push-Location $_ - try { - $data = @{ - path = $_ - module = $_.Name - commit = $(git rev-parse HEAD) - newCommit = $null - changed = $false - } - Write-Verbose "$($data.module) is at $($data.commit)" - $submodules += $data - } - finally { - Pop-Location - } - } + $submodules = Get-Submodules $ModuleDirectory $changes = $submodules ` | % { diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 9606f327a2..9c08953171 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -15,3 +15,32 @@ function Invoke-Block([scriptblock]$cmd) { throw "Command failed to execute: $cmd" } } + +function Get-Submodules([string]$ModuleDirectory) +{ + Invoke-Block { & git submodule update --init } + + $gitModules = Join-Path $RepoRoot ".gitmodules" + $submodules = @() + + Get-ChildItem "$ModuleDirectory/*" -Directory | % { + Push-Location $_ + try { + $data = @{ + path = $_ + module = $_.Name + commit = $(git rev-parse HEAD) + newCommit = $null + changed = $false + branch = $(git config -f $gitModules --get submodule.modules/$($_.Name).branch ) + } + + $submodules += $data + } + finally { + Pop-Location + } + } + + return $submodules +}