Skip to content

Instantly share code, notes, and snippets.

@dstockhammer
Created December 22, 2016 13:34
Show Gist options
  • Save dstockhammer/e5b8858c9318db7970532cc35f520294 to your computer and use it in GitHub Desktop.
Save dstockhammer/e5b8858c9318db7970532cc35f520294 to your computer and use it in GitHub Desktop.
Set-ProjectVersion for AppVeyor
<#
.Synopsis
Updates project.json version
.Description
Updates the project.json version to include the build number as pre-release suffix.
If the current build is a tag, the the build number is *NOT* appended.
.Parameter Path
The path to the project.json file.
.Parameter SetAppveyorVersion
Flag that indicates whether the script should also set the AppVeyor version number.
.Returns
The determined build number.
.Example
> Set-ProjectVersion -path "src\MyApp\project.json"
> 1.0.0
.Example
> Set-ProjectVersion -path "src\MyApp\project.json" -setAppveyorVersion
> 1.0.0-ci321
#>
function Set-ProjectVersion {
param(
[string] $path,
[switch] $setAppveyorVersion = $false
)
$str = Get-Content -Raw -Path $path
$json = ConvertFrom-Json $str
$version = $buildVersion = $json.version
if ($env:APPVEYOR_REPO_TAG -eq $false) {
$buildVersion = "$version-ci$($env:APPVEYOR_BUILD_NUMBER)"
$str.Replace("""version"": ""$version"",", """version"": ""$buildVersion"",") | Set-Content $path
}
if ($setAppveyorVersion -eq $true) {
Update-AppveyorBuild -Version $buildVersion
}
return $buildVersion
}
Export-ModuleMember -Function Set-ProjectVersion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment