From 4907fa844b9ee6e603904c419ea7809cff4f4d2d Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 09:41:07 +0000 Subject: [PATCH 1/7] update version number generation system to remove gitversion --- appveyor.yml | 6 +-- build.cmd | 24 +--------- build.ps1 | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ gitversion.yml | 31 ------------- 4 files changed, 121 insertions(+), 59 deletions(-) create mode 100644 build.ps1 delete mode 100644 gitversion.yml diff --git a/appveyor.yml b/appveyor.yml index 5c548a71c..580b9a1df 100644 --- a/appveyor.yml +++ b/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 diff --git a/build.cmd b/build.cmd index 1ba1b3742..6372b4125 100644 --- a/build.cmd +++ b/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 diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 000000000..14610c1cc --- /dev/null +++ b/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 } diff --git a/gitversion.yml b/gitversion.yml deleted file mode 100644 index 9fae0d8c2..000000000 --- a/gitversion.yml +++ /dev/null @@ -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: '[/-](?\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: [] \ No newline at end of file From 8fd7d1f158d19a9d5bd6336bd7483d42ca5de67f Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 09:42:58 +0000 Subject: [PATCH 2/7] remove erroneous '=' --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 14610c1cc..3cdb8f3d4 100644 --- a/build.ps1 +++ b/build.ps1 @@ -89,7 +89,7 @@ if("$env:APPVEYOR_API_URL" -ne ""){ Invoke-RestMethod -Method "PUT" ` -Uri "${env:APPVEYOR_API_URL}api/build" ` -Body "{version:'${version}'}" ` - -ContentType = "application/json" + -ContentType "application/json" } From 847e50755ed653fd144310037f927376c380e67d Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 09:45:52 +0000 Subject: [PATCH 3/7] update padding rules and master build tag --- build.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build.ps1 b/build.ps1 index 3cdb8f3d4..618e839f7 100644 --- a/build.ps1 +++ b/build.ps1 @@ -21,6 +21,7 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $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}'" @@ -51,8 +52,8 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex } $buildNumber = $env:APPVEYOR_BUILD_NUMBER - - $buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(4,"0"); + # 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" @@ -77,7 +78,7 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $branch = $branch.Replace("/","-").ToLower() if($branch.ToLower() -eq "master"){ - $branch = "ci" + $branch = "dev" } $version = "${version}-${branch}${buildNumber}"; From 90c66b6fb1259dd8a727ec4967691527d1fb4988 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 10:12:24 +0000 Subject: [PATCH 4/7] build version in artefact path --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 580b9a1df..832120990 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,8 +15,8 @@ test_script: - tests\CodeCoverage\CodeCoverage.cmd after_test: - - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.%GitVersion_NuGetVersion%.nupkg" - - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.Drawing.%GitVersion_NuGetVersion%.nupkg" + - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.%APPVEYOR_BUILD_VERSION%.nupkg" + - cmd: appveyor PushArtifact "artifacts\SixLabors.ImageSharp.Drawing.%APPVEYOR_BUILD_VERSION%.nupkg" deploy: # MyGet Deployment for builds & releases From 157cb96bd305a14681970c78409af2dfe2526ab6 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 10:47:18 +0000 Subject: [PATCH 5/7] fix version number build argument --- build.ps1 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/build.ps1 b/build.ps1 index 618e839f7..cf92f1854 100644 --- a/build.ps1 +++ b/build.ps1 @@ -3,7 +3,6 @@ $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 @@ -84,7 +83,6 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $version = "${version}-${branch}${buildNumber}"; } } -} if("$env:APPVEYOR_API_URL" -ne ""){ Invoke-RestMethod -Method "PUT" ` @@ -96,12 +94,10 @@ if("$env:APPVEYOR_API_URL" -ne ""){ Write-Host "Building version '${version}'" -$versionCmd ="/p:packageversion=${$version}" - -dotnet restore ${versionCmd} +dotnet restore /p:packageversion=$version Write-Host "Building projects" -dotnet build -c Release ${versionCmd} +dotnet build -c Release /p:packageversion=$version if ($LASTEXITCODE ){ Exit $LASTEXITCODE } @@ -112,9 +108,9 @@ if ( $env:CI -ne "True") { if ($LASTEXITCODE ){ Exit $LASTEXITCODE } # ECHO Packaging projects -dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build ${versionCmd} +dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build /p:packageversion=$version if ($LASTEXITCODE ){ Exit $LASTEXITCODE } -dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build ${versionCmd} +dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build /p:packageversion=$version if ($LASTEXITCODE ){ Exit $LASTEXITCODE } From 6ab5f7288ff566522f5ab46b14cbee29a650bcbf Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 11:47:58 +0000 Subject: [PATCH 6/7] cleanup --- build.ps1 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/build.ps1 b/build.ps1 index cf92f1854..c1e882f9c 100644 --- a/build.ps1 +++ b/build.ps1 @@ -51,19 +51,17 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex } $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" # 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 ""){ @@ -85,15 +83,14 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex } 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" @@ -102,15 +99,13 @@ dotnet build -c Release /p:packageversion=$version 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 +Write-Host "Packaging projects" dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build /p:packageversion=$version if ($LASTEXITCODE ){ Exit $LASTEXITCODE } dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build /p:packageversion=$version - if ($LASTEXITCODE ){ Exit $LASTEXITCODE } From ac27a4783a527fb219ed592556a682426a552406 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 20 Dec 2017 12:51:55 +0000 Subject: [PATCH 7/7] fix pr build number --- build.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index c1e882f9c..2f4d1c949 100644 --- a/build.ps1 +++ b/build.ps1 @@ -56,8 +56,10 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $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${env:APPVEYOR_PULL_REQUEST_NUMBER}_${buildNumber}"; + $version = "${version}-PullRequest${prNumber}${buildNumber}"; }else{ Write-Debug "building a branch commit"