forked from json-api-dotnet/JsonApiDotNetCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.ps1
110 lines (89 loc) · 4.01 KB
/
Build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function CheckLastExitCode {
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)
if ($SuccessCodes -notcontains $LastExitCode) {
throw "Executable returned exit code $LastExitCode"
}
}
function RunInspectCode {
$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
dotnet jb inspectcode JsonApiDotNetCore.sln --output="$outputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=SolutionPersonal -dsl=ProjectPersonal
CheckLastExitCode
[xml]$xml = Get-Content "$outputPath"
if ($xml.report.Issues -and $xml.report.Issues.Project) {
foreach ($project in $xml.report.Issues.Project) {
if ($project.Issue.Count -gt 0) {
$project.ForEach({
Write-Output "`nProject $($project.Name)"
$failed = $true
$_.Issue.ForEach({
$issueType = $xml.report.IssueTypes.SelectSingleNode("IssueType[@Id='$($_.TypeId)']")
$severity = $_.Severity ?? $issueType.Severity
Write-Output "[$severity] $($_.File):$($_.Line) $($_.Message)"
})
})
}
}
if ($failed) {
throw "One or more projects failed code inspection.";
}
}
}
function RunCleanupCode {
# When running in cibuild for a pull request, this reformats only the files changed in the PR and fails if the reformat produces changes.
if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) {
Write-Output "Running code cleanup on changed files in pull request"
# 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.
# 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.
# To prevent failing the build for unobvious reasons we use HEAD, which is always the latest version.
$mergeCommitHash = git rev-parse "HEAD"
$targetCommitHash = git rev-parse "$env:APPVEYOR_REPO_BRANCH"
dotnet regitlint -s JsonApiDotNetCore.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
CheckLastExitCode
}
}
function ReportCodeCoverage {
if ($env:APPVEYOR) {
if ($IsWindows) {
dotnet codecov -f "**\coverage.cobertura.xml"
}
}
else {
dotnet reportgenerator -reports:**\coverage.cobertura.xml -targetdir:artifacts\coverage
}
CheckLastExitCode
}
function CreateNuGetPackage {
if ($env:APPVEYOR_REPO_TAG -eq $true) {
# Get the version suffix from the repo tag. Example: v1.0.0-preview1-final => preview1-final
$segments = $env:APPVEYOR_REPO_TAG_NAME -split "-"
$suffixSegments = $segments[1..2]
$versionSuffix = $suffixSegments -join "-"
}
else {
# Get the version suffix from the auto-incrementing build number. Example: "123" => "pre-0123".
if ($env:APPVEYOR_BUILD_NUMBER) {
$revision = "{0:D4}" -f [convert]::ToInt32($env:APPVEYOR_BUILD_NUMBER, 10)
$versionSuffix = "pre-$revision"
}
else {
$versionSuffix = "pre-0001"
}
}
if ([string]::IsNullOrWhitespace($versionSuffix)) {
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts
}
else {
dotnet pack .\src\JsonApiDotNetCore -c Release -o .\artifacts --version-suffix=$versionSuffix
}
CheckLastExitCode
}
dotnet tool restore
CheckLastExitCode
dotnet build -c Release
CheckLastExitCode
RunInspectCode
RunCleanupCode
dotnet test -c Release --no-build --collect:"XPlat Code Coverage"
CheckLastExitCode
ReportCodeCoverage
CreateNuGetPackage