diff options
Diffstat (limited to 'scripts/TagRepos.ps1')
-rwxr-xr-x | scripts/TagRepos.ps1 | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/TagRepos.ps1 b/scripts/TagRepos.ps1 new file mode 100755 index 0000000000..bd21163c6e --- /dev/null +++ b/scripts/TagRepos.ps1 @@ -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 + } +} + + |