1- # This script originally (c) 2016 Serilog Contributors - license Apache 2.0
2-
3- echo " build: Build started"
1+ Write-Output " build: Build started"
42
53Push-Location $PSScriptRoot
64
5+ Write-Output " build: Tool versions follow"
6+
7+ dotnet -- version
8+ dotnet -- list- sdks
9+
710if (Test-Path .\artifacts) {
8- echo " build: Cleaning .\ artifacts"
9- Remove-Item .\ artifacts - Force - Recurse
11+ Write-Output " build: Cleaning ./ artifacts"
12+ Remove-Item ./ artifacts - Force - Recurse
1013}
1114
1215& dotnet restore -- no- cache
13- if ($LASTEXITCODE -ne 0 ) { exit 1 }
1416
15- $branch = @ { $true = $env: APPVEYOR_REPO_BRANCH ; $false = $ (git symbolic- ref -- short - q HEAD) }[$env: APPVEYOR_REPO_BRANCH -ne $NULL ];
16- $revision = @ { $true = " {0:00000}" -f [convert ]::ToInt32(" 0" + $env: APPVEYOR_BUILD_NUMBER , 10 ); $false = " local" }[$env: APPVEYOR_BUILD_NUMBER -ne $NULL ];
17- $suffix = @ { $true = " " ; $false = " $ ( $branch.Substring (0 , [math ]::Min(10 , $branch.Length ))) -$revision " }[$branch -eq " main" -and $revision -ne " local" ]
18-
19- echo " build: Version suffix is $suffix "
20-
21- foreach ($src in ls src/ Seq.App.* ) {
22- Push-Location $src
17+ $dbp = [Xml ] (Get-Content .\Directory.Build.props)
18+ $versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix
2319
24- echo " build: Packaging app project in $src "
20+ Write-Output " build: Package version prefix is $versionPrefix "
2521
26- if (Test-Path ./ obj/ publish) {
27- Remove-Item - Recurse - Force ./ obj/ publish
28- }
29-
30- if ($suffix ) {
31- & dotnet publish - c Release - o ./ obj/ publish -- version- suffix= $suffix
32- & dotnet pack - c Release - o ..\..\artifacts -- no- build -- version- suffix= $suffix
33- } else {
34- & dotnet publish - c Release - o ./ obj/ publish
35- & dotnet pack - c Release - o ..\..\artifacts -- no- build
36- }
37- if ($LASTEXITCODE -ne 0 ) { throw " Build failed" }
22+ $branch = @ { $true = $env: CI_TARGET_BRANCH ; $false = $ (git symbolic- ref -- short - q HEAD) }[$NULL -ne $env: CI_TARGET_BRANCH ];
23+ $revision = @ { $true = " {0:00000}" -f [convert ]::ToInt32(" 0" + $env: CI_BUILD_NUMBER , 10 ); $false = " local" }[$NULL -ne $env: CI_BUILD_NUMBER ];
24+ $suffix = @ { $true = " " ; $false = " $ ( $branch.Substring (0 , [math ]::Min(10 , $branch.Length )) -replace ' ([^a-zA-Z0-9\-]*)' , ' ' ) -$revision " }[$branch -eq " main" -and $revision -ne " local" ]
3825
39- Pop-Location
40- }
26+ Write-Output " build: Package version suffix is $suffix "
4127
42- foreach ($src in @ ( " src/Seq.Syntax " , " src/Seq.Mail " , " src/Seq.Apps.Testing " ) ) {
28+ foreach ($src in Get-ChildItem src/* ) {
4329 Push-Location $src
4430
45- echo " build: Packaging library in $src "
46-
31+ Write-Output " build: Packaging project in $src "
32+
4733 if ($suffix ) {
48- & dotnet pack - c Release - o ..\..\ artifacts -- version- suffix= $suffix
34+ & dotnet pack - c Release - o ../ .. / artifacts -- version- suffix= $suffix
4935 } else {
50- & dotnet pack - c Release - o ..\..\ artifacts
36+ & dotnet pack - c Release - o ../ .. / artifacts
5137 }
52- if ($LASTEXITCODE -ne 0 ) { throw " Build failed" }
38+ if ($LASTEXITCODE -ne 0 ) { throw " Packaging failed" }
5339
5440 Pop-Location
5541}
5642
57- foreach ($test in ls test/* .Tests) {
43+ Write-Output " build: Checking complete solution builds"
44+ & dotnet build
45+ if ($LASTEXITCODE -ne 0 ) { throw " Solution build failed" }
46+
47+ foreach ($test in Get-ChildItem test/* .Tests) {
5848 Push-Location $test
5949
60- echo " build: Testing project in $test "
50+ Write-Output " build: Testing project in $test "
6151
6252 & dotnet test - c Release
6353 if ($LASTEXITCODE -ne 0 ) { throw " Testing failed" }
6454
6555 Pop-Location
6656}
6757
68- Pop-Location
58+ Pop-Location
59+
60+ if ($env: NUGET_API_KEY ) {
61+ # GitHub Actions will only supply this to branch builds and not PRs. We publish
62+ # builds from any branch this action targets (i.e. main and dev).
63+
64+ Write-Output " build: Publishing NuGet packages"
65+
66+ foreach ($nupkg in Get-ChildItem artifacts/* .nupkg) {
67+ & dotnet nuget push - k $env: NUGET_API_KEY - s https:// api.nuget.org/ v3/ index.json " $nupkg "
68+ if ($LASTEXITCODE -ne 0 ) { throw " Publishing failed" }
69+ }
70+
71+ if (! ($suffix )) {
72+ Write-Output " build: Creating release for version $versionPrefix "
73+
74+ iex " gh release create v$versionPrefix --title v$versionPrefix --generate-notes $ ( get-item ./ artifacts/* .nupkg) $ ( get-item ./ artifacts/* .snupkg) "
75+ }
76+ }
0 commit comments