|
| 1 | +function Assert-Git { |
| 2 | + if (!(Get-Command git -ErrorAction Ignore)) { |
| 3 | + Write-Error 'git is required to execute this script' |
| 4 | + exit 1 |
| 5 | + } |
| 6 | +} |
| 7 | + |
| 8 | +function Invoke-Block([scriptblock]$cmd) { |
| 9 | + $cmd | Out-String | Write-Verbose |
| 10 | + & $cmd |
| 11 | + |
| 12 | + # Need to check both of these cases for errors as they represent different items |
| 13 | + # - $?: did the powershell script block throw an error |
| 14 | + # - $lastexitcode: did a windows command executed by the script block end in error |
| 15 | + if ((-not $?) -or ($lastexitcode -ne 0)) { |
| 16 | + Write-Warning $error[0] |
| 17 | + throw "Command failed to execute: $cmd" |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +function Get-Submodules { |
| 22 | + param( |
| 23 | + [Parameter(Mandatory = $true)] |
| 24 | + [string]$RepoRoot, |
| 25 | + [switch]$Shipping |
| 26 | + ) |
| 27 | + |
| 28 | + $moduleConfigFile = Join-Path $RepoRoot ".gitmodules" |
| 29 | + $submodules = @() |
| 30 | + |
| 31 | + [xml] $submoduleConfig = Get-Content "$RepoRoot/build/submodules.props" |
| 32 | + $repos = $submoduleConfig.Project.ItemGroup.Repository | % { $_.Include } |
| 33 | + |
| 34 | + Get-ChildItem "$RepoRoot/modules/*" -Directory ` |
| 35 | + | ? { (-not $Shipping) -or $($repos -contains $($_.Name)) -or $_.Name -eq 'Templating' } ` |
| 36 | + | % { |
| 37 | + Push-Location $_ | Out-Null |
| 38 | + Write-Verbose "Attempting to get submodule info for $_" |
| 39 | + |
| 40 | + if (Test-Path 'version.props') { |
| 41 | + [xml] $versionXml = Get-Content 'version.props' |
| 42 | + $versionPrefix = $versionXml.Project.PropertyGroup.VersionPrefix |
| 43 | + } else { |
| 44 | + $versionPrefix = '' |
| 45 | + } |
| 46 | + |
| 47 | + try { |
| 48 | + $data = @{ |
| 49 | + path = $_ |
| 50 | + module = $_.Name |
| 51 | + commit = $(git rev-parse HEAD) |
| 52 | + newCommit = $null |
| 53 | + changed = $false |
| 54 | + branch = $(git config -f $moduleConfigFile --get submodule.modules/$($_.Name).branch ) |
| 55 | + versionPrefix = $versionPrefix |
| 56 | + } |
| 57 | + |
| 58 | + $submodules += $data |
| 59 | + } |
| 60 | + finally { |
| 61 | + Pop-Location | Out-Null |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + return $submodules |
| 66 | +} |
0 commit comments