Skip to content

Commit

Permalink
updating AppVeyor's version-related PowerShell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
salaros committed Jun 18, 2018
1 parent 37c6bdc commit 47bfd6a
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,35 @@ install:
environment:
VERSION_SIMPLE: '{version}'
VERSION_INFORMATIONAL: '{version}'
VERSION_UNSTABLE_SUFFIX: '-preview-$(APPVEYOR_BUILD_NUMBER)'
VERSION_UNSTABLE_SUFFIX: 'preview'
APPVEYOR_TOKEN:
secure: LtoVAPATN9iTCl1zkCvEktqP92QSEEngyS3vqG3GphE=

init:
- ps: |
$env:VERSION_INFORMATIONAL = $env:APPVEYOR_BUILD_VERSION
$env:VERSION_SIMPLE = "$env:APPVEYOR_BUILD_VERSION.$env:APPVEYOR_BUILD_NUMBER"
$env:VERSION_SIMPLE = $env:APPVEYOR_BUILD_VERSION.TrimStart("v")
$env:VERSION_INFORMATIONAL = "$env:VERSION_SIMPLE"
$env:GITHUB_REPO_API = "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/tags"
if ($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_REPO_TAG_NAME) {
### CHECK IF A IT'S A TAGGED BUILD
$git_current_tag = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
$env:APPVEYOR_REPO_TAG_NAME = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
Write-Host "Building a tagged Git commit: $git_current_tag";
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]+)') {
$env:VERSION_INFORMATIONAL = "$git_current_tag"
if ($env:APPVEYOR_REPO_TAG_NAME -match '^([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)$') {
$tag_ver = [version]$env:APPVEYOR_REPO_TAG_NAME
$env:VERSION_INFORMATIONAL = "{0}.{1}.{2}" -f $tag_ver.Major, $tag_ver.Minor, $tag_ver.Build
$env:VERSION_SIMPLE = "$env:VERSION_INFORMATIONAL.$env:APPVEYOR_BUILD_NUMBER"
}
} else {
### OTHERWISE IT'S A REGULAR BUILD
try {
### TRY TO GET VERSION FROM THE LATEST GITHUB TAG/REALEASE
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$github_latest_tags=(Invoke-WebRequest -Uri $env:GITHUB_REPO_API) -join '`n' | ConvertFrom-Json
$github_last_tag=$github_latest_tags[0].name.TrimStart("v")
if ($github_last_tag -match '^([0-9]+\.[0-9]+\.[0-9]+)$') {
$github_tag_ver = [version]$github_last_tag
$github_last_tag = "{0}.{1}.{2}" -f $github_tag_ver.Major, $github_tag_ver.Minor, ($github_tag_ver.Build + 1)
}
$env:VERSION_INFORMATIONAL = $github_last_tag
} catch {
$env:VERSION_INFORMATIONAL = "1.0.0"
Write-Host "Failed to get version from the last GitHub release falling back on '$env:VERSION_INFORMATIONAL' base version";
}
$env:VERSION_INFORMATIONAL = "$env:VERSION_INFORMATIONAL$env:VERSION_UNSTABLE_SUFFIX"
} elseif ($env:VERSION_INFORMATIONAL -match '^([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)$') {
$current_ver = [version]$env:VERSION_INFORMATIONAL
$env:VERSION_INFORMATIONAL = "{0}.{1}.{2}" -f $current_ver.Major, $current_ver.Minor, $current_ver.Build
$env:VERSION_INFORMATIONAL = "{0}-{1}{2}" -f $env:VERSION_INFORMATIONAL, $env:VERSION_UNSTABLE_SUFFIX, $env:APPVEYOR_BUILD_NUMBER
}
### MAKE CALCULATED INFORMATIONAL VERSION THE ACTUAL BUILD VERSION
Update-AppveyorBuild -Version $env:VERSION_INFORMATIONAL
Write-Host "Using build version: $env:APPVEYOR_BUILD_VERSION";
Write-Host "Using build version: $env:VERSION_SIMPLE"
Write-Host "Using (informational) build version: $env:VERSION_INFORMATIONAL"
dotnet_csproj:
patch: true
Expand Down Expand Up @@ -125,22 +113,24 @@ deploy:
api_key:
secure: 3zmnmVBweTgdk4SBM/rWHdC9JOM9s0pxm1bw1d+WHDo=
artifact: NuGet_Files


after_deploy:
- ps: |
- ps: |
if ($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_REPO_TAG_NAME) {
$apiUrl = 'https://ci.appveyor.com/api'
$headers = @{
"Authorization" = "Bearer $env:APPVEYOR_TOKEN"
"Content-type" = "application/json"
"Accept" = "application/json"
}
$build = @{
nextBuildNumber = 1
Invoke-RestMethod -Method Put "$apiUrl/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings/build-number" -Body '{"nextBuildNumber": 1 }' -Headers $headers
$env:APPVEYOR_REPO_TAG_NAME = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v")
if ($env:APPVEYOR_REPO_TAG_NAME -match '^([0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)$') {
$tag_ver = [version]$env:APPVEYOR_REPO_TAG_NAME
$ver_format = "version: {0}.{1}.{2}.{3}" -f $tag_ver.Major, $tag_ver.Minor, ($tag_ver.Build + 1), '{build}'
$headers."Content-type" = "text/plain";
Invoke-RestMethod -Method Put "$apiUrl/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings/yaml" -Body $ver_format -Headers $headers
}
$json = $build | ConvertTo-Json
Invoke-RestMethod -Method Put "$apiUrl/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/settings/build-number" -Body $json -Headers $headers
}
# Start builds on tags only (GitHub and BitBucket)
Expand Down

0 comments on commit 47bfd6a

Please sign in to comment.