Skip to content

Commit 50b7362

Browse files
committed
improving AppVeyor's version calculation init (PowerShell) script
1 parent d3d91d8 commit 50b7362

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

appveyor.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ environment:
2828

2929
init:
3030
- ps: |
31-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
32-
$github_last_release=(Invoke-WebRequest -Uri https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/releases/latest) -join '`n' | ConvertFrom-Json
33-
$github_tag_name=$github_last_release.tag_name
34-
$env:VERSION_SIMPLE = "$github_tag_name.$env:APPVEYOR_BUILD_NUMBER"
35-
$env:VERSION_INFORMATIONAL = $github_tag_name
31+
$env:VERSION_INFORMATIONAL = $env:APPVEYOR_BUILD_VERSION
32+
$env:VERSION_SIMPLE = "$env:APPVEYOR_BUILD_VERSION.$env:APPVEYOR_BUILD_NUMBER"
3633
3734
if ($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_REPO_TAG_NAME)
3835
{
@@ -47,12 +44,28 @@ init:
4744
}
4845
else
4946
{
47+
try {
48+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
49+
$github_last_release=(Invoke-WebRequest -Uri https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/releases/latest) -join '`n' | ConvertFrom-Json
50+
$github_tag_name=$github_last_release.tag_name
51+
if ($github_tag_name -match '^([0-9]+\.[0-9]+\.[0-9]+)$')
52+
{
53+
$github_tag_ver = [version]$github_tag_name
54+
$github_tag_name = "{0}.{1}.{2}" -f $github_tag_ver.Major, $github_tag_ver.Minor, ($github_tag_ver.Build + 1)
55+
}
56+
$env:VERSION_INFORMATIONAL = $github_tag_name
57+
} catch {
58+
$env:VERSION_INFORMATIONAL = "1.0.0"
59+
Write-Host "Failed to get version from the last GitHub release falling back on '$env:VERSION_INFORMATIONAL' base version";
60+
}
61+
5062
$env:VERSION_INFORMATIONAL = "$env:VERSION_INFORMATIONAL$env:VERSION_SUFFIX"
5163
}
5264
5365
Update-AppveyorBuild -Version $env:VERSION_INFORMATIONAL
5466
Write-Host "Using build version: $env:APPVEYOR_BUILD_VERSION";
5567
68+
5669
dotnet_csproj:
5770
patch: true
5871
file: '**\*.csproj'

0 commit comments

Comments
 (0)