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.')]
|
2019-08-28 18:44:02 +02:00
|
|
|
[string]$Variable='ReleaseTag',
|
|
|
|
|
|
|
|
[switch]$CreateJson
|
2018-02-08 00:24:34 +01:00
|
|
|
)
|
|
|
|
|
2019-08-28 18:44:02 +02:00
|
|
|
function New-BuildInfoJson {
|
|
|
|
param(
|
|
|
|
[parameter(Mandatory = $true)]
|
|
|
|
[string]
|
|
|
|
$ReleaseTag,
|
|
|
|
[switch] $IsDaily
|
|
|
|
)
|
|
|
|
|
|
|
|
$blobName = $ReleaseTag -replace '\.', '-'
|
|
|
|
|
|
|
|
$isPreview = $ReleaseTag -like '*-*'
|
|
|
|
|
|
|
|
$filename = 'stable.json'
|
|
|
|
if($isPreview)
|
|
|
|
{
|
|
|
|
$filename = 'preview.json'
|
|
|
|
}
|
|
|
|
if($IsDaily.IsPresent)
|
|
|
|
{
|
|
|
|
$filename = 'daily.json'
|
|
|
|
}
|
|
|
|
|
|
|
|
@{
|
|
|
|
ReleaseTag = $ReleaseTag
|
|
|
|
BlobName = $blobName
|
|
|
|
} | ConvertTo-Json | Out-File -Encoding ascii -Force -FilePath $filename
|
|
|
|
|
|
|
|
$resolvedPath = (Resolve-Path -Path $filename).ProviderPath
|
|
|
|
$vstsCommandString = "vso[task.setvariable variable=BuildInfoPath]$resolvedPath"
|
|
|
|
Write-Verbose -Message "$vstsCommandString" -Verbose
|
|
|
|
Write-Host -Object "##$vstsCommandString"
|
|
|
|
|
|
|
|
Write-Host "##vso[artifact.upload containerfolder=BuildInfoJson;artifactname=BuildInfoJson]$resolvedPath"
|
|
|
|
}
|
|
|
|
|
2018-02-08 00:24:34 +01:00
|
|
|
# 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)
|
|
|
|
{
|
2019-08-28 18:44:02 +02:00
|
|
|
$isDaily = $false
|
2018-03-12 20:31:34 +01:00
|
|
|
# Branch is named release-<semver>
|
2019-02-19 19:47:39 +01:00
|
|
|
if($Branch -match '^.*(release[-/])')
|
2018-03-12 20:31:34 +01:00
|
|
|
{
|
2018-06-06 19:55:28 +02:00
|
|
|
Write-verbose "release branch:" -verbose
|
2019-02-19 19:47:39 +01:00
|
|
|
$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"
|
2019-08-28 18:44:02 +02:00
|
|
|
|
|
|
|
if ($CreateJson.IsPresent)
|
|
|
|
{
|
|
|
|
New-BuildInfoJson -ReleaseTag $releaseTag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($Branch -eq 'master' -or $Branch -like '*dailytest*')
|
|
|
|
{
|
|
|
|
$isDaily = $true
|
|
|
|
Write-verbose "daily build" -verbose
|
|
|
|
$metaDataJsonPath = Join-Path $PSScriptRoot -ChildPath '..\metadata.json'
|
|
|
|
$metadata = Get-content $metaDataJsonPath | ConvertFrom-Json
|
|
|
|
$versionPart = $metadata.PreviewReleaseTag
|
|
|
|
if($versionPart -match '-.*$')
|
|
|
|
{
|
|
|
|
$versionPart = $versionPart -replace '-.*$'
|
|
|
|
}
|
|
|
|
|
|
|
|
$releaseTag = "$versionPart-daily.$((get-date).ToString('yyyyMMdd'))"
|
|
|
|
$vstsCommandString = "vso[task.setvariable variable=$Variable]$releaseTag"
|
|
|
|
Write-Verbose -Message "setting $Variable to $releaseTag" -Verbose
|
|
|
|
Write-Host -Object "##$vstsCommandString"
|
|
|
|
|
|
|
|
if ($CreateJson.IsPresent)
|
|
|
|
{
|
|
|
|
New-BuildInfoJson -ReleaseTag $releaseTag -IsDaily
|
|
|
|
}
|
2018-03-12 20:31:34 +01:00
|
|
|
}
|
|
|
|
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"
|
2019-08-28 18:44:02 +02:00
|
|
|
|
|
|
|
if ($CreateJson.IsPresent)
|
|
|
|
{
|
|
|
|
New-BuildInfoJson -ReleaseTag $releaseTag
|
|
|
|
}
|
2018-03-12 20:31:34 +01:00
|
|
|
}
|
2018-02-08 00:24:34 +01:00
|
|
|
}
|
2019-02-01 00:10:19 +01:00
|
|
|
|
2019-08-28 18:44:02 +02:00
|
|
|
$vstsCommandString = "vso[task.setvariable variable=IS_DAILY]$($isDaily.ToString().ToLowerInvariant())"
|
|
|
|
Write-Verbose -Message "$vstsCommandString" -Verbose
|
|
|
|
Write-Host -Object "##$vstsCommandString"
|
|
|
|
|
2019-02-01 00:10:19 +01:00
|
|
|
Write-Output $releaseTag
|