1
+ [CmdletBinding (PositionalBinding = $false )]
1
2
param (
2
- [parameter (Position = 0 )][string ] $PreReleaseSuffix = ' '
3
+ [string ] $Version ,
4
+ [string ] $BuildNumber ,
5
+ [bool ] $CreatePackages ,
6
+ [bool ] $RunTests = $true ,
7
+ [string ] $PullRequestNumber
3
8
)
4
9
10
+ function CalculateVersion () {
11
+ if ($version ) {
12
+ return $version
13
+ }
14
+
15
+ $semVersion = ' ' ;
16
+ $path = $pwd ;
17
+ while (! $semVersion ) {
18
+ if (Test-Path (Join-Path $path " semver.txt" )) {
19
+ $semVersion = Get-Content (Join-Path $path " semver.txt" )
20
+ break
21
+ }
22
+ if ($PSScriptRoot -eq $path ) {
23
+ break
24
+ }
25
+ $path = Split-Path $path - Parent
26
+ }
27
+
28
+ if (! $semVersion ) {
29
+ Write-Error " semver.txt was not found in $pwd or any parent directory"
30
+ Exit 1
31
+ }
32
+
33
+ return " $semVersion -$BuildNumber "
34
+ }
35
+
36
+ Write-Host " Run Parameters:" - ForegroundColor Cyan
37
+ Write-Host " Version: $Version "
38
+ Write-Host " BuildNumber: $BuildNumber "
39
+ Write-Host " CreatePackages: $CreatePackages "
40
+ Write-Host " RunTests: $RunTests "
41
+ Write-Host " Base Version: $ ( CalculateVersion) "
42
+
5
43
$packageOutputFolder = " $PSScriptRoot \.nupkgs"
44
+ $projectsToBuild =
45
+ ' Dapper' ,
46
+ ' Dapper.StrongName' ,
47
+ ' Dapper.Contrib' ,
48
+ ' Dapper.EntityFramework' ,
49
+ ' Dapper.EntityFramework.StrongName' ,
50
+ ' Dapper.Rainbow' ,
51
+ ' Dapper.SqlBuilder'
6
52
7
- # Restore packages and build product
8
- Write-Host " Restoring..." - ForegroundColor " Green"
9
- & dotnet restore - v Minimal # Restore all packages
10
- if ($LASTEXITCODE -ne 0 )
11
- {
12
- throw " dotnet restore failed with exit code $LASTEXITCODE "
53
+ $testsToRun =
54
+ ' Dapper.Tests' ,
55
+ ' Dapper.Tests.Contrib'
56
+
57
+ if (! $Version -and ! $BuildNumber ) {
58
+ Write-Host " ERROR: You must supply either a -Version or -BuildNumber argument. `
59
+ Use -Version `" 4.0.0`" for explicit version specification, or `
60
+ Use -BuildNumber `" 12345`" for generation using <semver.txt>-<buildnumber>" - ForegroundColor Yellow
61
+ Exit 1
13
62
}
14
63
15
- # Build all
16
- Write-Host " Building..." - ForegroundColor " Green"
17
- Get-ChildItem " Dapper*.csproj" - Recurse |
18
- ForEach-Object {
19
- if ($PreReleaseSuffix ) {
20
- & dotnet build " $_ " -- version- suffix " $PreReleaseSuffix "
21
- } else {
22
- & dotnet build " $_ "
64
+ if ($PullRequestNumber ) {
65
+ Write-Host " Building for a pull request (#$PullRequestNumber ), skipping packaging." - ForegroundColor Yellow
66
+ $CreatePackages = $false
67
+ }
68
+
69
+ if ($RunTests ) {
70
+ dotnet restore / ConsoleLoggerParameters:Verbosity= Quiet
71
+ foreach ($project in $testsToRun ) {
72
+ Write-Host " Running tests: $project (all frameworks)" - ForegroundColor " Magenta"
73
+ Push-Location " $project "
74
+
75
+ dotnet xunit
76
+ if ($LastExitCode -ne 0 ) {
77
+ Write-Host " Error with tests, aborting build." - Foreground " Red"
78
+ Pop-Location
79
+ Exit 1
80
+ }
81
+
82
+ Write-Host " Tests passed!" - ForegroundColor " Green"
83
+ Pop-Location
23
84
}
24
85
}
25
86
26
- # Run tests
27
- Write-Host " Running Tests..." - ForegroundColor " Green"
28
- Get-ChildItem " Dapper.Test*.csproj" - Recurse |
29
- ForEach-Object {
30
- & dotnet test " $_ "
87
+ if ($CreatePackages ) {
88
+ mkdir - Force $packageOutputFolder | Out-Null
89
+ Write-Host " Clearing existing $packageOutputFolder ..." - NoNewline
90
+ Get-ChildItem $packageOutputFolder | Remove-Item
91
+ Write-Host " done." - ForegroundColor " Green"
92
+
93
+ Write-Host " Building all packages" - ForegroundColor " Green"
31
94
}
32
95
33
- # Package all
34
- Write-Host " Packaging..." - ForegroundColor " Green"
35
- Get-ChildItem " Dapper*.csproj" - Recurse | Where-Object { $_.Name -NotLike " *.Tests*" } |
36
- ForEach-Object {
37
- if ($PreReleaseSuffix ) {
38
- & dotnet pack " $_ " - c Release - o " $packageOutputFolder " -- version- suffix " $PreReleaseSuffix "
39
- } else {
40
- & dotnet pack " $_ " - c Release - o " $packageOutputFolder "
96
+ foreach ($project in $projectsToBuild ) {
97
+ Write-Host " Working on $project `:" - ForegroundColor " Magenta"
98
+
99
+ Push-Location " .\$project "
100
+
101
+ $semVer = CalculateVersion
102
+
103
+ Write-Host " Restoring and packing $project ... (Version:" - NoNewline - ForegroundColor " Magenta"
104
+ Write-Host $semVer - NoNewline - ForegroundColor " Cyan"
105
+ Write-Host " )" - ForegroundColor " Magenta"
106
+
107
+ $targets = " Restore"
108
+ if ($CreatePackages ) {
109
+ $targets += " ;Pack"
41
110
}
42
- }
111
+
112
+ dotnet msbuild " /t:$targets " " /p:Configuration=Release" " /p:Version=$semVer " " /p:PackageOutputPath=$packageOutputFolder " " /p:CI=true" " /p:NuGetBuildTasksPackTargets='000'"
113
+
114
+ Pop-Location
115
+
116
+ Write-Host " Done." - ForegroundColor " Green"
117
+ Write-Host " "
118
+ }
119
+ Write-Host " Build Complete." - ForegroundColor " Green"
0 commit comments