|
| 1 | +# Gets the version suffix from the repo tag |
| 2 | +# example: v1.0.0-preview1-final => preview1-final |
| 3 | +function Get-Version-Suffix-From-Tag { |
| 4 | + $tag=$env:APPVEYOR_REPO_TAG_NAME |
| 5 | + $split=$tag -split "-" |
| 6 | + $suffix=$split[1..2] |
| 7 | + $final=$suffix -join "-" |
| 8 | + return $final |
| 9 | +} |
| 10 | + |
| 11 | +function CheckLastExitCode { |
| 12 | + param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null) |
| 13 | + |
| 14 | + if ($SuccessCodes -notcontains $LastExitCode) { |
| 15 | + $msg = "EXE RETURNED EXIT CODE $LastExitCode" |
| 16 | + throw $msg |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
| 21 | +$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10) |
| 22 | + |
| 23 | +dotnet restore |
| 24 | +CheckLastExitCode |
| 25 | + |
| 26 | +dotnet build -c Release |
| 27 | +CheckLastExitCode |
| 28 | + |
| 29 | +dotnet test -c Release --no-build |
| 30 | +CheckLastExitCode |
| 31 | + |
| 32 | +Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG" |
| 33 | + |
| 34 | +if ($env:APPVEYOR_REPO_TAG -eq $true) { |
| 35 | + $revision = Get-Version-Suffix-From-Tag |
| 36 | + Write-Output "VERSION-SUFFIX: $revision" |
| 37 | + |
| 38 | + if ([string]::IsNullOrWhitespace($revision)) { |
| 39 | + Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts" |
| 40 | + dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts |
| 41 | + CheckLastExitCode |
| 42 | + } |
| 43 | + else { |
| 44 | + Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$revision" |
| 45 | + dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$revision |
| 46 | + CheckLastExitCode |
| 47 | + } |
| 48 | +} |
| 49 | +else { |
| 50 | + $packageVersionSuffix="pre-$revision" |
| 51 | + Write-Output "VERSION-SUFFIX: $packageVersionSuffix" |
| 52 | + Write-Output "RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$packageVersionSuffix" |
| 53 | + dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$packageVersionSuffix |
| 54 | + CheckLastExitCode |
| 55 | +} |
0 commit comments