Просмотр исходного кода

Add script to update each Repo

Ryan Brandenburg 8 лет назад
Родитель
Сommit
6652182b58
3 измененных файлов с 132 добавлено и 22 удалено
  1. 100 0
      scripts/UpdateRepos.ps1
  2. 3 22
      scripts/UpdateSubmodules.ps1
  3. 29 0
      scripts/common.psm1

+ 100 - 0
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 = "[email protected]: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
+}

+ 3 - 22
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 `
     | % {

+ 29 - 0
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
+}