Auto update package versions upon release generation (#52)
* Auto update package versions upon release generation - Adapted from .Net package incrementing - https://github.com/Azure/azure-sdk-for-net/blob/master/eng/Update-PkgVersion.ps1 - Seed Changelog file to allow updates to happen * Spelling fix
This commit is contained in:
Родитель
f8c45dab61
Коммит
00b8ba52b3
|
@ -0,0 +1,142 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Bumps up package versions after release
|
||||
|
||||
.DESCRIPTION
|
||||
This script bumps up package versions following conventions defined at https://github.com/Azure/azure-sdk/blob/master/docs/policies/releases.md#incrementing-after-release-cpp
|
||||
|
||||
.PARAMETER RepoRoot
|
||||
The Root of the repo
|
||||
|
||||
.PARAMETER ServiceDirectory
|
||||
The Name of the Service Directory
|
||||
|
||||
.PARAMETER PackageName
|
||||
The Name of the Package
|
||||
|
||||
.PARAMETER PackageDirName
|
||||
Used in the case where the package directory name is different from the package name. e.g in cognitiveservice packages
|
||||
|
||||
.PARAMETER NewVersionString
|
||||
Use this to overide version incement logic and set a version specified by this parameter
|
||||
|
||||
|
||||
.EXAMPLE
|
||||
Updating package version for Azure.Core
|
||||
Update-PkgVersion.ps1 -ServiceDirectory core -PackageName Azure.Core
|
||||
|
||||
Updating package version for Azure.Core with a specified verion
|
||||
Update-PkgVersion.ps1 -ServiceDirectory core -PackageName Azure.Core -NewVersionString 2.0.5
|
||||
|
||||
Updating package version for Microsoft.Azure.CognitiveServices.AnomalyDetector
|
||||
Update-PkgVersion.ps1 -ServiceDirectory cognitiveservices -PackageName Microsoft.Azure.CognitiveServices.AnomalyDetector -PackageDirName AnomalyDetector
|
||||
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string] $RepoRoot = "${PSScriptRoot}/..",
|
||||
[Parameter(Mandatory=$True)]
|
||||
[string] $ServiceDirectory,
|
||||
[Parameter(Mandatory=$True)]
|
||||
[string] $PackageName,
|
||||
[string] $PackageDirName,
|
||||
[string] $NewVersionString
|
||||
)
|
||||
# Regular expression as specified in https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||
$VERSION_REGEX = "^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
|
||||
|
||||
# Updated Version in csproj and changelog using computed or set NewVersionString
|
||||
function Update-Version($Unreleased=$True, $ReplaceVersion=$False)
|
||||
{
|
||||
Write-Verbose "New Version: ${NewPackageVersion}"
|
||||
Set-Content -Path $PackageVersionPath -Value ${NewPackageVersion}
|
||||
|
||||
# Increment Version in ChangeLog file
|
||||
& "${PSScriptRoot}/common/Update-Change-Log.ps1" -Version $NewPackageVersion -ChangeLogPath $ChangelogPath -Unreleased $Unreleased -ReplaceVersion $ReplaceVersion
|
||||
}
|
||||
|
||||
# Parse a VersionString to verify that it is right
|
||||
function Parse-Version($VersionString)
|
||||
{
|
||||
if ([System.String]::IsNullOrEmpty($VersionString))
|
||||
{
|
||||
Write-Error "Missing or Empty Version property ${VersionString}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($VersionString -Match $VERSION_REGEX)
|
||||
{
|
||||
if($Matches[4] -eq $null){$Pre = @()}
|
||||
else{$Pre = $Matches[4].Split(".")}
|
||||
$VersionTable = @{
|
||||
major = [int]$Matches[1]
|
||||
minor = [int]$Matches[2]
|
||||
patch = [int]$Matches[3]
|
||||
pretag = [string]$Pre[0]
|
||||
prever = [int]$Pre[1]
|
||||
}
|
||||
|
||||
if ($VersionTable['pretag'] -ne '' -and $VersionTable['pretag'] -ne 'preview')
|
||||
{
|
||||
Write-Error "Unexpected pre-release identifier '$($VersionTable['pretag'])', should be 'preview'"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if ($VersionTable['pretag'] -eq 'preview' -and $VersionTable['prever'] -lt 1)
|
||||
{
|
||||
Write-Error "Unexpected pre-release version '$($VersionTable['prever'])', should be greater than '1'"
|
||||
exit 1
|
||||
}
|
||||
return $VersionTable
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Error "Version property contains incorrect format. It should be in format 'X.Y.Z[-preview.N]'"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Obtain Current Package Version
|
||||
|
||||
if ([System.String]::IsNullOrEmpty($PackageDirName)) {$PackageDirName = $PackageName}
|
||||
$PackageVersionPath = Join-Path $RepoRoot "sdk" $ServiceDirectory $PackageDirName "version.txt"
|
||||
$ChangelogPath = Join-Path $RepoRoot "sdk" $ServiceDirectory $PackageDirName "CHANGELOG.md"
|
||||
$PackageVersion = Get-Content -Path $PackageVersionPath
|
||||
|
||||
|
||||
if ([System.String]::IsNullOrEmpty($NewVersionString))
|
||||
{
|
||||
$VersionTable = Parse-Version($PackageVersion)
|
||||
Write-Verbose "Current Version: ${PackageVersion}"
|
||||
# Increment Version
|
||||
if ([System.String]::IsNullOrEmpty($VersionTable['pretag']))
|
||||
{
|
||||
$VersionTable['pretag'] = 'preview'
|
||||
$VersionTable['prever'] = 1
|
||||
$VersionTable['minor']++
|
||||
$VersionTable['patch'] = 0
|
||||
}
|
||||
else
|
||||
{
|
||||
$VersionTable['prever']++
|
||||
}
|
||||
|
||||
$NewPackageVersion = "{0}.{1}.{2}-{3}.{4}" -F $VersionTable['major'], $VersionTable['minor'], $VersionTable['patch'], $VersionTable['pretag'], $VersionTable['prever']
|
||||
Update-Version
|
||||
}
|
||||
else
|
||||
{
|
||||
# Use specified VersionString
|
||||
$VersionTable = Parse-Version($NewVersionString)
|
||||
if ($VersionTable['pretag'] -eq '')
|
||||
{
|
||||
$NewPackageVersion = "{0}.{1}.{2}" -F $VersionTable['major'], $VersionTable['minor'], $VersionTable['patch']
|
||||
}
|
||||
else
|
||||
{
|
||||
$NewPackageVersion = "{0}.{1}.{2}-{3}.{4}" -F $VersionTable['major'], $VersionTable['minor'], $VersionTable['patch'], $VersionTable['pretag'], $VersionTable['prever']
|
||||
}
|
||||
Update-Version -Unreleased $False -ReplaceVersion $True
|
||||
}
|
|
@ -65,3 +65,28 @@ stages:
|
|||
TargetLanguage: 'cpp'
|
||||
# we override the regular script path because we have cloned the build tools repo as a separate artifact.
|
||||
ScriptPath: '$(Pipeline.Workspace)/azure-sdk-build-tools/scripts/copy-docs-to-blobstorage.ps1'
|
||||
|
||||
- ${{if ne(artifact.options.skipUpdatePackageVersion, 'true')}}:
|
||||
- deployment: UpdatePackageVersion
|
||||
displayName: "Update Package Version"
|
||||
condition: and(succeeded(), ne(variables['Skip.UpdatePackageVersion'], 'true'))
|
||||
environment: github
|
||||
|
||||
pool:
|
||||
vmImage: windows-2019
|
||||
|
||||
strategy:
|
||||
runOnce:
|
||||
deploy:
|
||||
steps:
|
||||
- checkout: self
|
||||
- pwsh: |
|
||||
eng/Update-PkgVersion.ps1 -ServiceDirectory '${{parameters.ServiceDirectory}}' -PackageName '${{artifact.name}}'
|
||||
displayName: Increment package version
|
||||
- template: tools/clone-buildtools/clone-buildtools.yml@azure-sdk-build-tools
|
||||
- template: pipelines/steps/create-pull-request.yml@azure-sdk-build-tools
|
||||
parameters:
|
||||
RepoName: azure-sdk-for-cpp
|
||||
PRBranchName: increment-package-version-${{ parameters.ServiceDirectory }}-$(Build.BuildId)
|
||||
CommitMsg: "Increment package version after release of ${{ artifact.name }}"
|
||||
PRTitle: "Increment version for ${{ parameters.ServiceDirectory }} releases"
|
|
@ -0,0 +1,5 @@
|
|||
# Release History
|
||||
|
||||
## 1.0.0-preview.1 (Unreleased)
|
||||
|
||||
* Testing. Validating automation.
|
|
@ -1 +1 @@
|
|||
1.0.0-dev.1
|
||||
1.0.0-preview.1
|
||||
|
|
Загрузка…
Ссылка в новой задаче