VisualStudio/scripts/Bump-Version.ps1

94 строки
2.3 KiB
PowerShell
Исходник Обычный вид История

<#
.SYNOPSIS
Bumps the version number of GitHub for Visual Studio
.DESCRIPTION
By default, just bumps the last component of the version number by one. An
alternate version number can be specified on the command line.
The new version number is committed to the local repository and pushed to
GitHub.
#>
Param(
# It would be nice to use our Validate-Version function here, but we
# can't because this Param definition has to come before any other code in the
# file.
2017-10-28 19:57:41 +03:00
[ValidateScript({ ($_.Major -ge 0) -and ($_.Minor -ge 0) -and ($_.Build -ge 0) })]
[System.Version]
$NewVersion = $null
,
[switch]
$BumpMajor = $false
,
[switch]
$BumpMinor = $false
,
[switch]
$BumpPatch = $false
,
2017-10-31 05:09:45 +03:00
[switch]
$BumpBuild = $false
,
[int]
$BuildNumber = -1
,
[switch]
2017-10-31 05:09:45 +03:00
$Commit = $false
,
[switch]
2017-10-31 05:09:45 +03:00
$Push = $false
,
[switch]
$Force = $false
2017-10-31 05:09:45 +03:00
,
[switch]
$Trace = $false
)
Set-StrictMode -Version Latest
2017-10-31 05:09:45 +03:00
if ($Trace) { Set-PSDebug -Trace 1 }
2017-10-31 05:09:45 +03:00
. $PSScriptRoot\modules.ps1 | out-null
. $scriptsDirectory\Modules\Versioning.ps1 | out-null
2017-10-31 05:09:45 +03:00
. $scriptsDirectory\Modules\Vsix.ps1 | out-null
. $scriptsDirectory\Modules\SolutionInfo.ps1 | out-null
. $scriptsDirectory\Modules\AppVeyor.ps1 | out-null
. $scriptsDirectory\Modules\DirectoryBuildProps.ps1 | out-null
if ($NewVersion -eq $null) {
if (!$BumpMajor -and !$BumpMinor -and !$BumpPatch -and !$BumpBuild){
Die -1 "You need to indicate which part of the version to update via -BumpMajor/-BumpMinor/-BumpPatch/-BumpBuild flags or a custom version via -NewVersion"
}
}
2017-10-31 05:09:45 +03:00
if ($Push -and !$Commit) {
Die 1 "Cannot push a version bump without -Commit"
}
2017-10-31 05:09:45 +03:00
if ($Commit -and !$Force){
Require-CleanWorkTree "bump version"
}
2017-10-31 05:09:45 +03:00
if (!$?) {
exit 1
}
2017-10-31 05:09:45 +03:00
if ($NewVersion -eq $null) {
$currentVersion = Read-Version
$NewVersion = Generate-Version $currentVersion $BumpMajor $BumpMinor $BumpPatch $BumpBuild $BuildNumber
}
Write-Output "Setting version to $NewVersion"
2017-10-31 05:09:45 +03:00
Write-Version $NewVersion
2017-10-31 05:09:45 +03:00
if ($Commit) {
Write-Output "Committing version change"
2017-10-31 05:09:45 +03:00
Commit-Version $NewVersion
2017-10-31 05:09:45 +03:00
if ($Push) {
Write-Output "Pushing version change"
2017-10-31 05:09:45 +03:00
$branch = & $git rev-parse --abbrev-ref HEAD
Push-Changes $branch
}
}