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
|
|
|
|
)
|
|
|
|
|
2019-11-07 21:10:06 +01:00
|
|
|
$blobName = $ReleaseTag -replace '\.', '-'
|
2019-08-28 18:44:02 +02:00
|
|
|
|
|
|
|
$isPreview = $ReleaseTag -like '*-*'
|
|
|
|
|
|
|
|
$filename = 'stable.json'
|
|
|
|
if($isPreview)
|
|
|
|
{
|
|
|
|
$filename = 'preview.json'
|
|
|
|
}
|
|
|
|
if($IsDaily.IsPresent)
|
|
|
|
{
|
|
|
|
$filename = 'daily.json'
|
|
|
|
}
|
|
|
|
|
2019-11-07 21:10:06 +01:00
|
|
|
## Get the UTC time and round up to the second.
|
|
|
|
$dateTime = [datetime]::UtcNow
|
|
|
|
$dateTime = [datetime]::new($dateTime.Ticks - ($dateTime.Ticks % [timespan]::TicksPerSecond), $dateTime.Kind)
|
|
|
|
|
2019-08-28 18:44:02 +02:00
|
|
|
@{
|
|
|
|
ReleaseTag = $ReleaseTag
|
2019-11-07 21:10:06 +01:00
|
|
|
ReleaseDate = $dateTime
|
2019-08-28 18:44:02 +02:00
|
|
|
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
|
|
|
|
2020-05-29 19:26:30 +02:00
|
|
|
$msixType = 'preview'
|
|
|
|
|
2020-02-05 01:21:59 +01:00
|
|
|
$isDaily = $false
|
|
|
|
|
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>
|
2019-02-19 19:47:39 +01:00
|
|
|
if($Branch -match '^.*(release[-/])')
|
2018-03-12 20:31:34 +01:00
|
|
|
{
|
2020-05-29 19:26:30 +02:00
|
|
|
$msixType = 'release'
|
2020-05-07 14:00:30 +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
|
|
|
|
}
|
|
|
|
}
|
2019-09-13 00:04:09 +02:00
|
|
|
elseif($branchOnly -eq 'master' -or $branchOnly -like '*dailytest*')
|
2019-08-28 18:44:02 +02:00
|
|
|
{
|
|
|
|
$isDaily = $true
|
2020-05-07 14:00:30 +02:00
|
|
|
Write-Verbose "daily build" -Verbose
|
2019-08-28 18:44:02 +02:00
|
|
|
$metaDataJsonPath = Join-Path $PSScriptRoot -ChildPath '..\metadata.json'
|
2020-05-07 14:00:30 +02:00
|
|
|
$metadata = Get-Content $metaDataJsonPath | ConvertFrom-Json
|
2019-08-28 18:44:02 +02:00
|
|
|
$versionPart = $metadata.PreviewReleaseTag
|
|
|
|
if($versionPart -match '-.*$')
|
|
|
|
{
|
|
|
|
$versionPart = $versionPart -replace '-.*$'
|
|
|
|
}
|
|
|
|
|
2020-05-07 14:00:30 +02:00
|
|
|
$releaseTag = "$versionPart-daily.$((Get-Date).ToString('yyyyMMdd'))"
|
2019-08-28 18:44:02 +02:00
|
|
|
$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
|
|
|
|
{
|
2020-05-07 14:00:30 +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'
|
2020-05-07 14:00:30 +02:00
|
|
|
$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"
|
|
|
|
|
2020-05-29 19:26:30 +02:00
|
|
|
$vstsCommandString = "vso[task.setvariable variable=MSIX_TYPE]$msixType"
|
|
|
|
Write-Verbose -Message "$vstsCommandString" -Verbose
|
|
|
|
Write-Host -Object "##$vstsCommandString"
|
|
|
|
|
2019-02-01 00:10:19 +01:00
|
|
|
Write-Output $releaseTag
|