Add script for setting and pushing tags (#919)
This commit is contained in:
parent
9dc18f864a
commit
4dc2c17f04
|
|
@ -0,0 +1,106 @@
|
||||||
|
#!/usr/bin/env pwsh
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Generates a tag on this repo and adds a tag for each submodule that corresponds
|
||||||
|
to the value in version.props
|
||||||
|
.PARAMETER Push
|
||||||
|
Push the tag to origin
|
||||||
|
.PARAMETER WhatIf
|
||||||
|
Dry run
|
||||||
|
#>
|
||||||
|
[cmdletbinding(PositionalBinding = $false, SupportsShouldProcess = $true)]
|
||||||
|
param(
|
||||||
|
[switch]$Push
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
|
||||||
|
Set-StrictMode -Version 1
|
||||||
|
|
||||||
|
function New-GitTag {
|
||||||
|
[cmdletbinding(SupportsShouldProcess = $true)]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$Repo,
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$Tag
|
||||||
|
)
|
||||||
|
|
||||||
|
Push-Location $Repo
|
||||||
|
try {
|
||||||
|
git show-ref --tags --verify "refs/tags/$Tag" -q
|
||||||
|
$existingTag = $?
|
||||||
|
|
||||||
|
if ($existingTag) {
|
||||||
|
Write-Warning "${Repo}: Tag '$Tag' already exists. Skipped adding tag"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ($PSCmdlet.ShouldProcess($Repo, "Tag $Tag")) {
|
||||||
|
Invoke-Block { & git tag -m "v$Tag" $Tag HEAD }
|
||||||
|
Write-Host -f Magenta "${Repo}: added tag '$Tag'"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Push -and $PSCmdlet.ShouldProcess($Repo, "Push tag $Tag to origin")) {
|
||||||
|
Invoke-Block { & git push origin refs/tags/$Tag }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Gets the package version by invoking KoreBuild on a repo with a custom target that spits out the package version
|
||||||
|
#
|
||||||
|
function Get-PackageVersion([string]$repoRoot) {
|
||||||
|
$buildScript = if (-not $IsCoreCLR -or $IsWindows) { 'build.ps1' } else { 'build.sh' }
|
||||||
|
$inspectTarget = "/p:CustomAfterKoreBuildTargets=$PSScriptRoot/GetPackageVersion.targets"
|
||||||
|
# Add the /t:Noop target which may be used by the bootstrapper to skip unimportant initialization
|
||||||
|
$output = & "$repoRoot/$buildScript" $inspectTarget /v:m /p:IsFinalBuild=true /t:Noop /t:GetPackageVersion
|
||||||
|
$output | out-string | Write-Verbose
|
||||||
|
if (-not $? -or $LASTEXITCODE -ne 0) {
|
||||||
|
throw "$buildScript failed on $repoRoot. Exit code $LASTEXITCODE"
|
||||||
|
}
|
||||||
|
$packageVersion = $output | where-object { $_ -like '*PackageVersion=*' } | select-object -first 1
|
||||||
|
$packageVersion = $packageVersion -replace 'PackageVersion=',''
|
||||||
|
if ($packageVersion) { $packageVersion = $packageVersion.Trim() }
|
||||||
|
if (-not $packageVersion) {
|
||||||
|
throw "Could not determine final package version for $repoRoot"
|
||||||
|
}
|
||||||
|
return $packageVersion.Trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
$repoRoot = Resolve-Path "$PSScriptRoot/../"
|
||||||
|
|
||||||
|
Write-Warning "Make sure you have run ``git submodule update`` first to pin the submodules to the correct commit"
|
||||||
|
if (-not $PSCmdlet.ShouldContinue("Continue?", "This will apply tags to all submodules")) {
|
||||||
|
Write-Host "Exiting"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$universeTag = Get-PackageVersion $repoRoot
|
||||||
|
New-GitTag $repoRoot $universeTag -WhatIf:$WhatIfPreference
|
||||||
|
|
||||||
|
Get-Submodules $repoRoot | ForEach-Object {
|
||||||
|
$modPath = $_.path
|
||||||
|
$module = $_.module
|
||||||
|
if (-not (Test-Path (Join-Path $_.path 'version.props'))) {
|
||||||
|
Write-Warning "$module does not have a version.props file. Skipping"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$tag = Get-PackageVersion $_.path
|
||||||
|
if ($tag -ne $universeTag) {
|
||||||
|
Write-Warning "${module}: version ($tag) does not match universe ($universeTag)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning "${module}: Could not automatically determine tag for $modPath. Skipping"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
New-GitTag $_.path $tag -WhatIf:$WhatIfPreference
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<Project>
|
||||||
|
<Target Name="GetPackageVersion">
|
||||||
|
<Message Importance="high" Text="PackageVersion=$(PackageVersion)" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
|
|
@ -32,27 +32,31 @@ function Get-Submodules {
|
||||||
$repos = $submoduleConfig.Project.ItemGroup.Repository | % { $_.Include }
|
$repos = $submoduleConfig.Project.ItemGroup.Repository | % { $_.Include }
|
||||||
|
|
||||||
Get-ChildItem "$RepoRoot/modules/*" -Directory `
|
Get-ChildItem "$RepoRoot/modules/*" -Directory `
|
||||||
| ? { (-not $Shipping) -or $($repos -contains $($_.Name)) -or $_.Name -eq 'Templating' } `
|
| ? { (-not $Shipping) -or $($repos -contains $($_.Name)) -or $_.Name -eq 'Templating' } `
|
||||||
| % {
|
| % {
|
||||||
Push-Location $_ | Out-Null
|
Push-Location $_ | Out-Null
|
||||||
Write-Verbose "Attempting to get submodule info for $_"
|
Write-Verbose "Attempting to get submodule info for $_"
|
||||||
|
|
||||||
if (Test-Path 'version.props') {
|
if (Test-Path 'version.props') {
|
||||||
[xml] $versionXml = Get-Content 'version.props'
|
[xml] $versionXml = Get-Content 'version.props'
|
||||||
$versionPrefix = $versionXml.Project.PropertyGroup.VersionPrefix
|
$versionPrefix = $versionXml.Project.PropertyGroup.VersionPrefix | select-object -first 1
|
||||||
} else {
|
$versionSuffix = $versionXml.Project.PropertyGroup.VersionSuffix | select-object -first 1
|
||||||
|
}
|
||||||
|
else {
|
||||||
$versionPrefix = ''
|
$versionPrefix = ''
|
||||||
|
$versionSuffix = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$data = [PSCustomObject] @{
|
$data = [PSCustomObject] @{
|
||||||
path = $_
|
path = $_
|
||||||
module = $_.Name
|
module = $_.Name
|
||||||
commit = $(git rev-parse HEAD)
|
commit = $(git rev-parse HEAD)
|
||||||
newCommit = $null
|
newCommit = $null
|
||||||
changed = $false
|
changed = $false
|
||||||
branch = $(git config -f $moduleConfigFile --get submodule.modules/$($_.Name).branch )
|
branch = $(git config -f $moduleConfigFile --get submodule.modules/$($_.Name).branch )
|
||||||
versionPrefix = $versionPrefix
|
versionPrefix = $versionPrefix
|
||||||
|
versionSuffix = $versionSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
$submodules += $data
|
$submodules += $data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue