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-
111function CheckLastExitCode {
122 param ([int []]$SuccessCodes = @ (0 ), [scriptblock ]$CleanupScript = $null )
133
144 if ($SuccessCodes -notcontains $LastExitCode ) {
15- $msg = " EXE RETURNED EXIT CODE $LastExitCode "
16- throw $msg
5+ throw " Executable returned exit code $LastExitCode "
176 }
187}
198
209function RunInspectCode {
2110 $outputPath = [System.IO.Path ]::Combine([System.IO.Path ]::GetTempPath(), ' jetbrains-inspectcode-results.xml' )
22- dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln -- output= " $outputPath " -- profile= JsonApiDotNetCore - WarningSeverities.DotSettings -- properties:Configuration= Release -- severity= WARNING -- verbosity= WARN - dsl= GlobalAll - dsl= SolutionPersonal - dsl= ProjectPersonal
11+ dotnet jb inspectcode JsonApiDotNetCore.MongoDb.sln -- output= " $outputPath " -- profile= WarningSeverities.DotSettings -- properties:Configuration= Release -- severity= WARNING -- verbosity= WARN - dsl= GlobalAll - dsl= SolutionPersonal - dsl= ProjectPersonal
2312 CheckLastExitCode
2413
2514 [xml ]$xml = Get-Content " $outputPath "
@@ -50,22 +39,24 @@ function RunCleanupCode {
5039 # When running in cibuild for a pull request, this reformats only the files changed in the PR and fails if the reformat produces changes.
5140
5241 if ($env: APPVEYOR_PULL_REQUEST_HEAD_COMMIT ) {
53- Write-Output " Running code cleanup in cibuild for pull request"
42+ Write-Output " Running code cleanup on changed files in pull request"
5443
55- $sourceCommitHash = $env: APPVEYOR_PULL_REQUEST_HEAD_COMMIT
44+ # In the past, we used $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT for the merge commit hash. That is the pinned hash at the time the build is enqueued.
45+ # When a force-push happens after that, while the build hasn't yet started, this hash becomes invalid during the build, resulting in a lookup error.
46+ # To prevent failing the build for unobvious reasons we use HEAD, which is always the latest version.
47+ $mergeCommitHash = git rev- parse " HEAD"
5648 $targetCommitHash = git rev- parse " $env: APPVEYOR_REPO_BRANCH "
5749
58- Write-Output " Source commit hash = $sourceCommitHash "
59- Write-Output " Target commit hash = $targetCommitHash "
60-
61- dotnet regitlint - s JsonApiDotNetCore.MongoDb.sln -- print- command -- jb -- profile -- jb -- profile= ' \"JADNC Full Cleanup\"' -- jb -- properties:Configuration= Release -- jb -- verbosity= WARN -f commits - a $sourceCommitHash - b $targetCommitHash -- fail- on- diff -- print- diff
50+ dotnet regitlint - s JsonApiDotNetCore.MongoDb.sln -- print- command -- jb -- profile -- jb -- profile= ' \"JADNC Full Cleanup\"' -- jb -- properties:Configuration= Release -- jb -- verbosity= WARN -f commits - a $mergeCommitHash - b $targetCommitHash -- fail- on- diff -- print- diff
6251 CheckLastExitCode
6352 }
6453}
6554
6655function ReportCodeCoverage {
6756 if ($env: APPVEYOR ) {
68- dotnet codecov -f " **\coverage.cobertura.xml"
57+ if ($IsWindows ) {
58+ dotnet codecov -f " **\coverage.cobertura.xml"
59+ }
6960 }
7061 else {
7162 dotnet reportgenerator - reports:** \coverage.cobertura.xml - targetdir:artifacts\coverage
@@ -74,8 +65,33 @@ function ReportCodeCoverage {
7465 CheckLastExitCode
7566}
7667
77- $revision = @ { $true = $env: APPVEYOR_BUILD_NUMBER ; $false = 1 }[$env: APPVEYOR_BUILD_NUMBER -ne $NULL ];
78- $revision = " {0:D4}" -f [convert ]::ToInt32($revision , 10 )
68+ function CreateNuGetPackage {
69+ if ($env: APPVEYOR_REPO_TAG -eq $true ) {
70+ # Get the version suffix from the repo tag. Example: v1.0.0-preview1-final => preview1-final
71+ $segments = $env: APPVEYOR_REPO_TAG_NAME -split " -"
72+ $suffixSegments = $segments [1 .. 2 ]
73+ $versionSuffix = $suffixSegments -join " -"
74+ }
75+ else {
76+ # Get the version suffix from the auto-incrementing build number. Example: "123" => "pre-0123".
77+ if ($env: APPVEYOR_BUILD_NUMBER ) {
78+ $revision = " {0:D4}" -f [convert ]::ToInt32($env: APPVEYOR_BUILD_NUMBER , 10 )
79+ $versionSuffix = " pre-$revision "
80+ }
81+ else {
82+ $versionSuffix = " pre-0001"
83+ }
84+ }
85+
86+ if ([string ]::IsNullOrWhitespace($versionSuffix )) {
87+ dotnet pack .\src\JsonApiDotNetCore.MongoDb - c Release - o .\artifacts
88+ }
89+ else {
90+ dotnet pack .\src\JsonApiDotNetCore.MongoDb - c Release - o .\artifacts -- version- suffix= $versionSuffix
91+ }
92+
93+ CheckLastExitCode
94+ }
7995
8096dotnet tool restore
8197CheckLastExitCode
@@ -91,27 +107,4 @@ CheckLastExitCode
91107
92108ReportCodeCoverage
93109
94- Write-Output " APPVEYOR_REPO_TAG: $env: APPVEYOR_REPO_TAG "
95-
96- if ($env: APPVEYOR_REPO_TAG -eq $true ) {
97- $revision = Get-Version - Suffix- From- Tag
98- Write-Output " VERSION-SUFFIX: $revision "
99-
100- if ([string ]::IsNullOrWhitespace($revision )) {
101- Write-Output " RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts"
102- dotnet pack .\src\JsonApiDotNetCore.MongoDb - c Release - o .\artifacts
103- CheckLastExitCode
104- }
105- else {
106- Write-Output " RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$revision "
107- dotnet pack .\src\JsonApiDotNetCore.MongoDb - c Release - o .\artifacts -- version- suffix= $revision
108- CheckLastExitCode
109- }
110- }
111- else {
112- $packageVersionSuffix = " pre-$revision "
113- Write-Output " VERSION-SUFFIX: $packageVersionSuffix "
114- Write-Output " RUNNING dotnet pack .\src\JsonApiDotNetCore.MongoDb -c Release -o .\artifacts --version-suffix=$packageVersionSuffix "
115- dotnet pack .\src\JsonApiDotNetCore.MongoDb - c Release - o .\artifacts -- version- suffix= $packageVersionSuffix
116- CheckLastExitCode
117- }
110+ CreateNuGetPackage
0 commit comments