2018-02-08 00:24:34 +01:00
|
|
|
param(
|
|
|
|
[Parameter(HelpMessage='ReleaseTag from the job. Set to "fromBranch" or $null to update using the branch name')]
|
|
|
|
[string]$ReleaseTag,
|
|
|
|
|
|
|
|
[Parameter(HelpMessage='The branch name used to update the release tag.')]
|
|
|
|
[string]$Branch=$env:BUILD_SOURCEBRANCH,
|
|
|
|
|
|
|
|
[Parameter(HelpMessage='The variable name to put the new release tagin.')]
|
|
|
|
[string]$Variable='ReleaseTag'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Script to set the release tag based on the branch name if it is not set or it is "fromBranch"
|
2018-03-12 20:31:34 +01:00
|
|
|
# the branch name is expected to be release-<semver> or <previewname>
|
2018-02-08 00:24:34 +01:00
|
|
|
# VSTS passes it as 'refs/heads/release-v6.0.2'
|
|
|
|
|
2018-03-12 20:31:34 +01:00
|
|
|
$branchOnly = $Branch -replace '^refs/heads/';
|
2018-05-18 04:04:20 +02:00
|
|
|
$branchOnly = $branchOnly -replace '[_\-]'
|
2018-03-12 20:31:34 +01:00
|
|
|
|
2018-02-08 00:24:34 +01:00
|
|
|
if($ReleaseTag -eq 'fromBranch' -or !$ReleaseTag)
|
|
|
|
{
|
2018-03-12 20:31:34 +01:00
|
|
|
# Branch is named release-<semver>
|
|
|
|
if($Branch -match '^.*(release-)')
|
|
|
|
{
|
2018-06-06 19:55:28 +02:00
|
|
|
Write-verbose "release branch:" -verbose
|
|
|
|
$releaseTag = $Branch -replace '^.*(release-)'
|
2018-03-12 20:31:34 +01:00
|
|
|
$vstsCommandString = "vso[task.setvariable variable=$Variable]$releaseTag"
|
|
|
|
Write-Verbose -Message "setting $Variable to $releaseTag" -Verbose
|
|
|
|
Write-Host -Object "##$vstsCommandString"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-06 19:55:28 +02:00
|
|
|
Write-verbose "non-release branch" -verbose
|
2018-03-12 20:31:34 +01:00
|
|
|
# Branch is named <previewname>
|
|
|
|
# Get version from metadata and append -<previewname>
|
|
|
|
$metaDataJsonPath = Join-Path $PSScriptRoot -ChildPath '..\metadata.json'
|
|
|
|
$metadata = Get-content $metaDataJsonPath | ConvertFrom-Json
|
2018-09-08 03:12:10 +02:00
|
|
|
$versionPart = $metadata.PreviewReleaseTag
|
2018-03-12 20:31:34 +01:00
|
|
|
if($versionPart -match '-.*$')
|
|
|
|
{
|
|
|
|
$versionPart = $versionPart -replace '-.*$'
|
|
|
|
}
|
|
|
|
|
|
|
|
$releaseTag = "$versionPart-$branchOnly"
|
|
|
|
$vstsCommandString = "vso[task.setvariable variable=$Variable]$releaseTag"
|
|
|
|
Write-Verbose -Message "setting $Variable to $releaseTag" -Verbose
|
|
|
|
Write-Host -Object "##$vstsCommandString"
|
|
|
|
}
|
2018-02-08 00:24:34 +01:00
|
|
|
}
|
2019-02-01 00:10:19 +01:00
|
|
|
|
|
|
|
Write-Output $releaseTag
|