|
1 | | -# This script originally (c) 2016 Serilog Contributors - license Apache 2.0 |
2 | | - |
3 | | -echo "build: Build started" |
| 1 | +Write-Output "build: Build started" |
4 | 2 |
|
5 | 3 | Push-Location $PSScriptRoot |
6 | 4 |
|
| 5 | +Write-Output "build: Tool versions follow" |
| 6 | + |
| 7 | +dotnet --version |
| 8 | +dotnet --list-sdks |
| 9 | + |
7 | 10 | if(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 |
10 | 13 | } |
11 | 14 |
|
12 | 15 | & dotnet restore --no-cache |
13 | | -if($LASTEXITCODE -ne 0) { exit 1 } |
14 | 16 |
|
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"] |
| 17 | +$dbp = [Xml] (Get-Content .\Directory.Build.props) |
| 18 | +$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix |
18 | 19 |
|
19 | | -echo "build: Version suffix is $suffix" |
| 20 | +Write-Output "build: Package version prefix is $versionPrefix" |
20 | 21 |
|
21 | | -foreach ($src in ls src/*) { |
| 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"] |
| 25 | + |
| 26 | +Write-Output "build: Package version suffix is $suffix" |
| 27 | + |
| 28 | +foreach ($src in Get-ChildItem src/*) { |
22 | 29 | Push-Location $src |
23 | 30 |
|
24 | | - echo "build: Packaging project in $src" |
| 31 | + Write-Output "build: Packaging project in $src" |
25 | 32 |
|
26 | 33 | if ($suffix) { |
27 | 34 | & dotnet publish -c Release -o ./obj/publish --version-suffix=$suffix |
28 | | - & dotnet pack -c Release -o ..\..\artifacts --no-build --version-suffix=$suffix |
| 35 | + & dotnet pack -c Release -o ../../artifacts --no-build --version-suffix=$suffix |
29 | 36 | } else { |
30 | 37 | & dotnet publish -c Release -o ./obj/publish |
31 | | - & dotnet pack -c Release -o ..\..\artifacts --no-build |
| 38 | + & dotnet pack -c Release -o ../../artifacts --no-build |
32 | 39 | } |
33 | | - if($LASTEXITCODE -ne 0) { exit 1 } |
| 40 | + if($LASTEXITCODE -ne 0) { throw "Packaging failed" } |
34 | 41 |
|
35 | 42 | Pop-Location |
36 | 43 | } |
37 | 44 |
|
38 | | -foreach ($test in ls test/*.Tests) { |
| 45 | +Write-Output "build: Checking complete solution builds" |
| 46 | +& dotnet build |
| 47 | +if($LASTEXITCODE -ne 0) { throw "Solution build failed" } |
| 48 | + |
| 49 | +foreach ($test in Get-ChildItem test/*.Tests) { |
39 | 50 | Push-Location $test |
40 | 51 |
|
41 | | - echo "build: Testing project in $test" |
| 52 | + Write-Output "build: Testing project in $test" |
42 | 53 |
|
43 | 54 | & dotnet test -c Release |
44 | | - if($LASTEXITCODE -ne 0) { exit 3 } |
| 55 | + if($LASTEXITCODE -ne 0) { throw "Testing failed" } |
45 | 56 |
|
46 | 57 | Pop-Location |
47 | 58 | } |
48 | 59 |
|
49 | 60 | Pop-Location |
| 61 | + |
| 62 | +if ($env:NUGET_API_KEY) { |
| 63 | + # GitHub Actions will only supply this to branch builds and not PRs. We publish |
| 64 | + # builds from any branch this action targets (i.e. main and dev). |
| 65 | + |
| 66 | + Write-Output "build: Publishing NuGet packages" |
| 67 | + |
| 68 | + foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) { |
| 69 | + & dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg" |
| 70 | + if($LASTEXITCODE -ne 0) { throw "Publishing failed" } |
| 71 | + } |
| 72 | + |
| 73 | + if (!($suffix)) { |
| 74 | + Write-Output "build: Creating release for version $versionPrefix" |
| 75 | + |
| 76 | + iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)" |
| 77 | + } |
| 78 | +} |
0 commit comments