Browse Source

update version number generation system to remove gitversion

af/merge-core
Scott Williams 8 years ago
parent
commit
4907fa844b
  1. 6
      appveyor.yml
  2. 24
      build.cmd
  3. 119
      build.ps1
  4. 31
      gitversion.yml

6
appveyor.yml

@ -4,14 +4,10 @@ image: Visual Studio 2017
# prevent the double build when a branch has an active PR
skip_branch_with_pr: true
install:
- choco install gitversion.portable -pre -y
before_build:
- git submodule -q update --init
- cmd: dotnet --version
- ps: c:\ProgramData\chocolatey\lib\gitversion.portable\tools\gitversion.exe /l console /output buildserver
build_script:
- cmd: build.cmd

24
build.cmd

@ -1,29 +1,7 @@
@echo Off
SET versionCommand=
if not "%GitVersion_NuGetVersion%" == "" (
SET versionCommand=/p:packageversion=%GitVersion_NuGetVersion%
@echo building with version set to '%GitVersion_NuGetVersion%'
)
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"
dotnet restore %versionCommand%
ECHO Building projects
dotnet build -c Release %versionCommand%
if not "%errorlevel%"=="0" goto failure
if not "%CI%" == "True" (
ECHO NOT on CI server running tests
dotnet test ./tests/ImageSharp.Tests/ImageSharp.Tests.csproj --no-build -c Release
)
if not "%errorlevel%"=="0" goto failure
ECHO Packaging projects
dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build %versionCommand%
if not "%errorlevel%"=="0" goto failure
dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build %versionCommand%
if not "%errorlevel%"=="0" goto failure
:success

119
build.ps1

@ -0,0 +1,119 @@
# lets calulat the correct version here
$fallbackVersion = "1.0.0";
$version = ''
if($env:APPVEYOR -eq "true"){
$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 ""){
$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
$buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(4,"0");
if("$env:APPVEYOR_PULL_REQUEST_NUMBER" -ne ""){
Write-Debug "building a PR"
# this is a PR
$version = "${version}-PullRequest${env:APPVEYOR_PULL_REQUEST_NUMBER}_${buildNumber}";
}else{
Write-Debug "building a branch commit"
# this is a general branch commit
# if master use 'ci' prefix
# if other branch use 'branch'
$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 = "ci"
}
$version = "${version}-${branch}${buildNumber}";
}
}
}
if("$env:APPVEYOR_API_URL" -ne ""){
Invoke-RestMethod -Method "PUT" `
-Uri "${env:APPVEYOR_API_URL}api/build" `
-Body "{version:'${version}'}" `
-ContentType = "application/json"
}
Write-Host "Building version '${version}'"
$versionCmd ="/p:packageversion=${$version}"
dotnet restore ${versionCmd}
Write-Host "Building projects"
dotnet build -c Release ${versionCmd}
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
if ( $env:CI -ne "True") {
#ECHO NOT on CI server running tests
dotnet test ./tests/ImageSharp.Tests/ImageSharp.Tests.csproj --no-build -c Release
}
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
# ECHO Packaging projects
dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build ${versionCmd}
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }
dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build ${versionCmd}
if ($LASTEXITCODE ){ Exit $LASTEXITCODE }

31
gitversion.yml

@ -1,31 +0,0 @@
# to create a new package you create a new release/tag
# in github appveyor will build it without the -cixxx tag
# it will then be deployable cleanly to nuget.org
branches:
master:
tag: ci
mode: ContinuousDeployment
increment: Minor
prevent-increment-of-merged-branch-version: false
track-merge-target: true
pull-request:
regex: (pull|pull\-requests|pr)[/-]
mode: ContinuousDelivery
tag: PullRequest
increment: Inherit
prevent-increment-of-merged-branch-version: false
tag-number-pattern: '[/-](?<number>\d+)[-/]'
track-merge-target: false
tracks-release-branches: false
is-release-branch: false
otherbranches:
regex: '.*'
mode: ContinuousDeployment
tag: ci
increment: Patch
prevent-increment-of-merged-branch-version: false
track-merge-target: true
is-release-branch: false
ignore:
sha: []
Loading…
Cancel
Save