-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nate McMaster
committed
Nov 14, 2017
1 parent
7235918
commit d7785d6
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env pwsh | ||
|
||
<# | ||
.SYNOPSIS | ||
Tags each repo according to VersionPrefix in version.props of that repo | ||
.PARAMETER Push | ||
Push all updated tags | ||
.PARAMETER ForceUpdateTag | ||
This will call git tag --force | ||
#> | ||
[cmdletbinding(SupportsShouldProcess = $true)] | ||
param( | ||
[switch]$Push = $false, | ||
[switch]$ForceUpdateTag = $false | ||
) | ||
|
||
Set-StrictMode -Version 2 | ||
$ErrorActionPreference = 'Stop' | ||
|
||
Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1" | ||
|
||
Assert-Git | ||
|
||
$RepoRoot = Resolve-Path "$PSScriptRoot/../" | ||
|
||
Get-Submodules $RepoRoot -Shipping | % { | ||
Push-Location $_.path | Out-Null | ||
try { | ||
|
||
if (-not $_.versionPrefix) { | ||
Write-Warning "Could not determine tag version for $(_.path)" | ||
} | ||
else { | ||
$tag = $_.versionPrefix | ||
Write-Host "$($_.module) => $tag" | ||
|
||
$gitTagArgs = @() | ||
if ($ForceUpdateTag) { | ||
$gitTagArgs += '--force' | ||
} | ||
|
||
Invoke-Block { & git tag @gitTagArgs $tag } | ||
|
||
if ($Push) { | ||
$gitPushArgs = @() | ||
if ($WhatIfPreference) { | ||
$gitPushArgs += '--dry-run' | ||
} | ||
Invoke-Block { & git push --dry-run @gitPushArgs origin "refs/tags/${tag}" } | ||
} | ||
|
||
if ($WhatIfPreference) { | ||
Invoke-Block { & git tag -d $tag } | Out-Null | ||
} | ||
} | ||
} | ||
catch { | ||
Write-Host -ForegroundColor Red "Could not update $_" | ||
throw | ||
} | ||
finally { | ||
Pop-Location | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
function Assert-Git { | ||
if (!(Get-Command git -ErrorAction Ignore)) { | ||
Write-Error 'git is required to execute this script' | ||
exit 1 | ||
} | ||
} | ||
|
||
function Invoke-Block([scriptblock]$cmd) { | ||
$cmd | Out-String | Write-Verbose | ||
& $cmd | ||
|
||
# Need to check both of these cases for errors as they represent different items | ||
# - $?: did the powershell script block throw an error | ||
# - $lastexitcode: did a windows command executed by the script block end in error | ||
if ((-not $?) -or ($lastexitcode -ne 0)) { | ||
Write-Warning $error[0] | ||
throw "Command failed to execute: $cmd" | ||
} | ||
} | ||
|
||
function Get-Submodules { | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$RepoRoot, | ||
[switch]$Shipping | ||
) | ||
|
||
$moduleConfigFile = Join-Path $RepoRoot ".gitmodules" | ||
$submodules = @() | ||
|
||
[xml] $submoduleConfig = Get-Content "$RepoRoot/build/submodules.props" | ||
$repos = $submoduleConfig.Project.ItemGroup.Repository | % { $_.Include } | ||
|
||
Get-ChildItem "$RepoRoot/modules/*" -Directory ` | ||
| ? { (-not $Shipping) -or $($repos -contains $($_.Name)) -or $_.Name -eq 'Templating' } ` | ||
| % { | ||
Push-Location $_ | Out-Null | ||
Write-Verbose "Attempting to get submodule info for $_" | ||
|
||
if (Test-Path 'version.props') { | ||
[xml] $versionXml = Get-Content 'version.props' | ||
$versionPrefix = $versionXml.Project.PropertyGroup.VersionPrefix | ||
} else { | ||
$versionPrefix = '' | ||
} | ||
|
||
try { | ||
$data = @{ | ||
path = $_ | ||
module = $_.Name | ||
commit = $(git rev-parse HEAD) | ||
newCommit = $null | ||
changed = $false | ||
branch = $(git config -f $moduleConfigFile --get submodule.modules/$($_.Name).branch ) | ||
versionPrefix = $versionPrefix | ||
} | ||
|
||
$submodules += $data | ||
} | ||
finally { | ||
Pop-Location | Out-Null | ||
} | ||
} | ||
|
||
return $submodules | ||
} |