From 2804b24f6b58ec8166cd6d36615f4bd3777c523b Mon Sep 17 00:00:00 2001 From: salaros Date: Wed, 6 Jun 2018 00:04:34 +0300 Subject: [PATCH] more refactoring + formatting to AppVeyor's init (PowerShell) script --- appveyor.yml | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 639ec44..0df7b1d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,49 +23,46 @@ cache: environment: VERSION_SIMPLE: '{version}' VERSION_INFORMATIONAL: '{version}' - VERSION_SUFFIX: '-preview-$(APPVEYOR_BUILD_NUMBER)' - VERSION_SUFFIX_TAG: '-beta-$(APPVEYOR_BUILD_NUMBER)' + VERSION_UNSTABLE_SUFFIX: '-preview-$(APPVEYOR_BUILD_NUMBER)' init: - ps: | $env:VERSION_INFORMATIONAL = $env:APPVEYOR_BUILD_VERSION $env:VERSION_SIMPLE = "$env:APPVEYOR_BUILD_VERSION.$env:APPVEYOR_BUILD_NUMBER" + $env:GITHUB_REPO_API = "https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/releases/latest" - if ($env:APPVEYOR_REPO_TAG -eq "true" -and $env:APPVEYOR_REPO_TAG_NAME) - { - $env:VERSION_SUFFIX = $env:VERSION_SUFFIX_TAG - $tag_version = $env:APPVEYOR_REPO_TAG_NAME.TrimStart("v") - Write-Host "Building a tag: $tag_version"; + 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") + Write-Host "Building a tagged Git commit: $git_current_tag"; - if ($tag_version -match '^([0-9]+\.[0-9]+\.[0-9]+)$' -Or $tag_version -match '([0-9]+[\.-][0-9]+[\.-][0-9]+-[-A-Za-z0-9]+)') - { - $env:VERSION_INFORMATIONAL = "$tag_version" + 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" } - } - else - { + } 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_last_release=(Invoke-WebRequest -Uri https://api.github.com/repos/$env:APPVEYOR_REPO_NAME/releases/latest) -join '`n' | ConvertFrom-Json - $github_tag_name=$github_last_release.tag_name - if ($github_tag_name -match '^([0-9]+\.[0-9]+\.[0-9]+)$') - { - $github_tag_ver = [version]$github_tag_name - $github_tag_name = "{0}.{1}.{2}" -f $github_tag_ver.Major, $github_tag_ver.Minor, ($github_tag_ver.Build + 1) + $github_last_release=(Invoke-WebRequest -Uri $env:GITHUB_REPO_API) -join '`n' | ConvertFrom-Json + $github_last_tag=$github_last_release.tag_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_tag_name + $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_SUFFIX" + $env:VERSION_INFORMATIONAL = "$env:VERSION_INFORMATIONAL$env:VERSION_UNSTABLE_SUFFIX" } + ### MAKE CALCULATED INFORMATIONAL VERSION THE ACTUAL BUILD VERSION Update-AppveyorBuild -Version $env:VERSION_INFORMATIONAL Write-Host "Using build version: $env:APPVEYOR_BUILD_VERSION"; - dotnet_csproj: patch: true file: '**\*.csproj'