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
1
function CheckLastExitCode {
12
2
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)
13
3
14
4
if ($SuccessCodes -notcontains $LastExitCode) {
15
- $msg = "EXE RETURNED EXIT CODE $LastExitCode"
16
- throw $msg
5
+ throw "Executable returned exit code $LastExitCode"
17
6
}
18
7
}
19
8
20
9
function RunInspectCode {
21
10
$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
23
12
CheckLastExitCode
24
13
25
14
[xml]$xml = Get-Content "$outputPath"
@@ -50,22 +39,24 @@ function RunCleanupCode {
50
39
# When running in cibuild for a pull request, this reformats only the files changed in the PR and fails if the reformat produces changes.
51
40
52
41
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"
54
43
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"
56
48
$targetCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"
57
49
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
62
51
CheckLastExitCode
63
52
}
64
53
}
65
54
66
55
function ReportCodeCoverage {
67
56
if ($env:APPVEYOR) {
68
- dotnet codecov -f "**\coverage.cobertura.xml"
57
+ if ($IsWindows) {
58
+ dotnet codecov -f "**\coverage.cobertura.xml"
59
+ }
69
60
}
70
61
else {
71
62
dotnet reportgenerator -reports:**\coverage.cobertura.xml -targetdir:artifacts\coverage
@@ -74,8 +65,33 @@ function ReportCodeCoverage {
74
65
CheckLastExitCode
75
66
}
76
67
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
+ }
79
95
80
96
dotnet tool restore
81
97
CheckLastExitCode
@@ -91,27 +107,4 @@ CheckLastExitCode
91
107
92
108
ReportCodeCoverage
93
109
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