Last active
          June 5, 2018 21:03 
        
      - 
      
- 
        Save salaros/ff2ad993a6cf00dd0672485226fb293f to your computer and use it in GitHub Desktop. 
    AppVeyor + semantic versioning
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # ... | |
| environment: | |
| VERSION_SIMPLE: '{version}' | |
| VERSION_INFORMATIONAL: '{version}' | |
| VERSION_UNSTABLE_SUFFIX: '-preview-$(APPVEYOR_BUILD_NUMBER)' | |
| init: | |
| - ps: .\scripts\init.ps1 | |
| # Use this block if your project uses .NET Core | |
| dotnet_csproj: | |
| patch: true | |
| file: '**\*.csproj' | |
| assembly_version: $(VERSION_SIMPLE) | |
| file_version: $(VERSION_SIMPLE) | |
| version: $(VERSION_INFORMATIONAL) | |
| package_version: $(VERSION_INFORMATIONAL) | |
| informational_version: $(VERSION_INFORMATIONAL) | |
| # Use this block if your project uses .NET Framework | |
| assembly_info: | |
| patch: true | |
| file: '**\AssemblyInfo.*' | |
| assembly_version: $(VERSION_SIMPLE) | |
| assembly_file_version: $(VERSION_SIMPLE) | |
| assembly_informational_version: $(VERSION_INFORMATIONAL) | |
| # ... | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $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) | |
| { | |
| ### 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 ($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 { | |
| ### 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 $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]+)$') | |
| { | |
| ### IF LAST TAG NAME IS A VALID VERSION OBJECT, INCREMENT ITS LAST PART | |
| $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 { | |
| ### FALLBACK ON 1.0.0 VERSION IF GITHUB REPO HAS NO RELEASES / TAGS | |
| $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"; | |
| } | |
| # PREPEND THE SUFFIX OF UNSTABLE VERSIONS e.g. preview-%BUILD_BUMBER%, alpha-%BUILD_BUMBER%, RC-%BUILD_BUMBER% | |
| $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"; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment