Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix build version number generation
Browse files Browse the repository at this point in the history
  • Loading branch information
tocsoft committed Aug 1, 2018
1 parent fa868db commit 4101024
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 34 deletions.
13 changes: 1 addition & 12 deletions appveyor.yml
@@ -1,19 +1,16 @@
version: 0.0.{build}
image: Visual Studio 2017

install:
- choco install gitversion.portable -pre -y

before_build:
- cmd: dotnet --version
- ps: c:\ProgramData\chocolatey\lib\gitversion.portable\tools\gitversion.exe /l console /output buildserver

build_script:
- cmd: build.cmd
- cmd: tests\CodeCoverage\CodeCoverage.cmd

after_build:
- cmd: appveyor PushArtifact "artifacts\SixLabors.Core.%GitVersion_NuGetVersion%.nupkg"
- cmd: appveyor PushArtifact "artifacts\SixLabors.Core.%APPVEYOR_BUILD_VERSION%.nupkg"

deploy:
- provider: NuGet
Expand All @@ -24,14 +21,6 @@ deploy:
artifact: /.*\.nupkg/
on:
branch: master
- provider: NuGet
server: https://www.myget.org/F/sixlabors-unstable/api/v2/package
symbol_server: https://www.myget.org/F/sixlabors-unstable/symbols/api/v2/package
api_key:
secure: V/lEHP0UeMWIpWd0fiNlY2IgbCnJKQlGdRksECdJbOBdaE20Fl0RNL7WyqHe02o4
artifact: /.*\.nupkg/
on:
branch: develop

# prevent the double build when a branch has an active PR
skip_branch_with_pr: true
Expand Down
23 changes: 1 addition & 22 deletions build.cmd
@@ -1,27 +1,6 @@
@echo Off

if not "%GitVersion_NuGetVersion%" == "" (
dotnet restore /p:packageversion=%GitVersion_NuGetVersion%
)ELSE (
dotnet restore
)

ECHO Building nuget packages
if not "%GitVersion_NuGetVersion%" == "" (
dotnet build -c Release /p:packageversion=%GitVersion_NuGetVersion%
)ELSE (
dotnet build -c Release
)
if not "%errorlevel%"=="0" goto failure

dotnet test ./tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj


if not "%GitVersion_NuGetVersion%" == "" (
dotnet pack ./src/SixLabors.Core/ -c Release --output ../../artifacts --no-build /p:packageversion=%GitVersion_NuGetVersion%
)ELSE (
dotnet pack ./src/SixLabors.Core/ -c Release --output ../../artifacts --no-build
)
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"

if not "%errorlevel%"=="0" goto failure

Expand Down
110 changes: 110 additions & 0 deletions build.ps1
@@ -0,0 +1,110 @@

# lets calulat the correct version here
$fallbackVersion = "1.0.0";
$version = ''

$tagRegex = '^v?(\d+\.\d+\.\d+)(-([a-zA-Z]+)\.?(\d*))?$'

# we are running on the build server
$isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex

if($isVersionTag){

Write-Debug "Building commit tagged with a compatable version number"

$version = $matches[1]
$postTag = $matches[3]
$count = $matches[4]
Write-Debug "version number: ${version} post tag: ${postTag} count: ${count}"
if("$postTag" -ne ""){
$version = "${version}-${postTag}"
}
if("$count" -ne ""){
# for consistancy with previous releases we pad the counter to only 4 places
$padded = $count.Trim().Trim('0').PadLeft(4,"0");
Write-Debug "count '$count', padded '${padded}'"

$version = "${version}${padded}"
}
}else {

Write-Debug "Untagged"
$lastTag = (git tag --list --sort=-taggerdate) | Out-String
$list = $lastTag.Split("`n")
foreach ($tag in $list) {

Write-Debug "testing ${tag}"
$tag = $tag.Trim();
if($tag -match $tagRegex){
Write-Debug "matched ${tag}"
$version = $matches[1];
break;
}
}

if("$version" -eq ""){
$version = $fallbackVersion
Write-Debug "Failed to discover base version Fallback to '${version}'"
}else{

Write-Debug "Discovered base version from tags '${version}'"
}

$buildNumber = $env:APPVEYOR_BUILD_NUMBER

# build number replacement is padded to 6 places
$buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(6,"0");
if("$env:APPVEYOR_PULL_REQUEST_NUMBER" -ne ""){
Write-Debug "building a PR"

$prNumber = "$env:APPVEYOR_PULL_REQUEST_NUMBER".Trim().Trim('0').PadLeft(5,"0");
# this is a PR
$version = "${version}-PullRequest${prNumber}${buildNumber}";
}else{
Write-Debug "building a branch commit"

# this is a general branch commit
$branch = $env:APPVEYOR_REPO_BRANCH

if("$branch" -eq ""){
$branch = ((git rev-parse --abbrev-ref HEAD) | Out-String).Trim()

if("$branch" -eq ""){
$branch = "unknown"
}
}

$branch = $branch.Replace("/","-").ToLower()

if($branch.ToLower() -eq "master"){
$branch = "dev"
}

$version = "${version}-${branch}${buildNumber}";
}
}

if("$env:APPVEYOR_API_URL" -ne ""){
# update appveyor build number for this build
Invoke-RestMethod -Method "PUT" `
-Uri "${env:APPVEYOR_API_URL}api/build" `
-Body "{version:'${version}'}" `
-ContentType "application/json"
}

Write-Host "Building version '${version}'"
dotnet restore /p:packageversion=$version

Write-Host "Building projects"
dotnet build -c Release /p:packageversion=$version

if ($LASTEXITCODE ){ Exit $LASTEXITCODE }

if ( $env:CI -ne "True") {
dotnet test ./tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj --no-build -c Release
}
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }

Write-Host "Packaging projects"
dotnet pack ./src/SixLabors.Core/ -c Release --output ../../artifacts --no-build /p:packageversion=$version
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }

0 comments on commit 4101024

Please sign in to comment.