Skip to content

Commit 47bfd6a

Browse files
committed
updating AppVeyor's version-related PowerShell scripts
1 parent 37c6bdc commit 47bfd6a

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

appveyor.yml

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,35 @@ install:
2020
environment:
2121
VERSION_SIMPLE: '{version}'
2222
VERSION_INFORMATIONAL: '{version}'
23-
VERSION_UNSTABLE_SUFFIX: '-preview-$(APPVEYOR_BUILD_NUMBER)'
23+
VERSION_UNSTABLE_SUFFIX: 'preview'
2424
APPVEYOR_TOKEN:
2525
secure: LtoVAPATN9iTCl1zkCvEktqP92QSEEngyS3vqG3GphE=
26-
26+
2727
init:
2828
- ps: |
29-
$env:VERSION_INFORMATIONAL = $env:APPVEYOR_BUILD_VERSION
30-
$env:VERSION_SIMPLE = "$env:APPVEYOR_BUILD_VERSION.$env:APPVEYOR_BUILD_NUMBER"
29+
$env:VERSION_SIMPLE = $env:APPVEYOR_BUILD_VERSION.TrimStart("v")
30+
$env:VERSION_INFORMATIONAL = "$env:VERSION_SIMPLE"
3131
$env:GITHUB_REPO_API = "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/tags"
3232
3333
if ($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_REPO_TAG_NAME) {
3434
### CHECK IF A IT'S A TAGGED BUILD
35-
$git_current_tag = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
35+
$env:APPVEYOR_REPO_TAG_NAME = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
3636
Write-Host "Building a tagged Git commit: $git_current_tag";
37-
38-
if ($git_current_tag -match '^([0-9]+\.[0-9]+\.[0-9]+)$' -Or $git_current_tag -match '([0-9]+[\.-][0-9]+[\.-][0-9]+-[-A-Za-z0-9]+)') {
39-
$env:VERSION_INFORMATIONAL = "$git_current_tag"
37+
if ($env:APPVEYOR_REPO_TAG_NAME -match '^([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)$') {
38+
$tag_ver = [version]$env:APPVEYOR_REPO_TAG_NAME
39+
$env:VERSION_INFORMATIONAL = "{0}.{1}.{2}" -f $tag_ver.Major, $tag_ver.Minor, $tag_ver.Build
40+
$env:VERSION_SIMPLE = "$env:VERSION_INFORMATIONAL.$env:APPVEYOR_BUILD_NUMBER"
4041
}
41-
} else {
42-
### OTHERWISE IT'S A REGULAR BUILD
43-
try {
44-
### TRY TO GET VERSION FROM THE LATEST GITHUB TAG/REALEASE
45-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
46-
$github_latest_tags=(Invoke-WebRequest -Uri $env:GITHUB_REPO_API) -join '`n' | ConvertFrom-Json
47-
$github_last_tag=$github_latest_tags[0].name.TrimStart("v")
48-
if ($github_last_tag -match '^([0-9]+\.[0-9]+\.[0-9]+)$') {
49-
$github_tag_ver = [version]$github_last_tag
50-
$github_last_tag = "{0}.{1}.{2}" -f $github_tag_ver.Major, $github_tag_ver.Minor, ($github_tag_ver.Build + 1)
51-
}
52-
$env:VERSION_INFORMATIONAL = $github_last_tag
53-
} catch {
54-
$env:VERSION_INFORMATIONAL = "1.0.0"
55-
Write-Host "Failed to get version from the last GitHub release falling back on '$env:VERSION_INFORMATIONAL' base version";
56-
}
57-
58-
$env:VERSION_INFORMATIONAL = "$env:VERSION_INFORMATIONAL$env:VERSION_UNSTABLE_SUFFIX"
42+
} elseif ($env:VERSION_INFORMATIONAL -match '^([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)$') {
43+
$current_ver = [version]$env:VERSION_INFORMATIONAL
44+
$env:VERSION_INFORMATIONAL = "{0}.{1}.{2}" -f $current_ver.Major, $current_ver.Minor, $current_ver.Build
45+
$env:VERSION_INFORMATIONAL = "{0}-{1}{2}" -f $env:VERSION_INFORMATIONAL, $env:VERSION_UNSTABLE_SUFFIX, $env:APPVEYOR_BUILD_NUMBER
5946
}
6047
6148
### MAKE CALCULATED INFORMATIONAL VERSION THE ACTUAL BUILD VERSION
6249
Update-AppveyorBuild -Version $env:VERSION_INFORMATIONAL
63-
Write-Host "Using build version: $env:APPVEYOR_BUILD_VERSION";
50+
Write-Host "Using build version: $env:VERSION_SIMPLE"
51+
Write-Host "Using (informational) build version: $env:VERSION_INFORMATIONAL"
6452
6553
dotnet_csproj:
6654
patch: true
@@ -125,22 +113,24 @@ deploy:
125113
api_key:
126114
secure: 3zmnmVBweTgdk4SBM/rWHdC9JOM9s0pxm1bw1d+WHDo=
127115
artifact: NuGet_Files
128-
129116

130117
after_deploy:
131-
- ps: |
118+
- ps: |
132119
if ($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_REPO_TAG_NAME) {
133120
$apiUrl = 'https://ci.appveyor.com/api'
134121
$headers = @{
135122
"Authorization" = "Bearer $env:APPVEYOR_TOKEN"
136123
"Content-type" = "application/json"
137-
"Accept" = "application/json"
138124
}
139-
$build = @{
140-
nextBuildNumber = 1
125+
Invoke-RestMethod -Method Put "$apiUrl/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings/build-number" -Body '{"nextBuildNumber": 1 }' -Headers $headers
126+
127+
$env:APPVEYOR_REPO_TAG_NAME = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
128+
if ($env:APPVEYOR_REPO_TAG_NAME -match '^([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)$') {
129+
$tag_ver = [version]$env:APPVEYOR_REPO_TAG_NAME
130+
$ver_format = "version: {0}.{1}.{2}.{3}" -f $tag_ver.Major, $tag_ver.Minor, ($tag_ver.Build + 1), '{build}'
131+
$headers."Content-type" = "text/plain";
132+
Invoke-RestMethod -Method Put "$apiUrl/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings/yaml" -Body $ver_format -Headers $headers
141133
}
142-
$json = $build | ConvertTo-Json
143-
Invoke-RestMethod -Method Put "$apiUrl/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings/build-number" -Body $json -Headers $headers
144134
}
145135
146136
# Start builds on tags only (GitHub and BitBucket)

0 commit comments

Comments
 (0)