Skip to content

Commit

Permalink
more refactoring + formatting to AppVeyor's init (PowerShell) script
Browse files Browse the repository at this point in the history
  • Loading branch information
salaros committed Jun 5, 2018
1 parent 50b7362 commit 2804b24
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 2804b24

Please sign in to comment.