|
1 |
| -# This script originally (c) 2016 Serilog Contributors - license Apache 2.0 |
| 1 | +Write-Output "build: Tool versions follow" |
2 | 2 |
|
3 |
| -echo "build: Build started" |
| 3 | +dotnet --version |
| 4 | +dotnet --list-sdks |
| 5 | + |
| 6 | +Write-Output "build: Build started" |
4 | 7 |
|
5 | 8 | Push-Location $PSScriptRoot
|
| 9 | +try { |
| 10 | + if(Test-Path .\artifacts) { |
| 11 | + Write-Output "build: Cleaning ./artifacts" |
| 12 | + Remove-Item ./artifacts -Force -Recurse |
| 13 | + } |
6 | 14 |
|
7 |
| -if(Test-Path .\artifacts) { |
8 |
| - echo "build: Cleaning .\artifacts" |
9 |
| - Remove-Item .\artifacts -Force -Recurse |
10 |
| -} |
| 15 | + & dotnet restore --no-cache |
| 16 | + |
| 17 | + $dbp = [Xml] (Get-Content .\Directory.Version.props) |
| 18 | + $versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix |
11 | 19 |
|
12 |
| -& dotnet restore --no-cache |
13 |
| -if($LASTEXITCODE -ne 0) { exit 1 } |
| 20 | + Write-Output "build: Package version prefix is $versionPrefix" |
14 | 21 |
|
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"] |
| 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 | + $commitHash = $(git rev-parse --short HEAD) |
| 26 | + $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] |
18 | 27 |
|
19 |
| -echo "build: Version suffix is $suffix" |
| 28 | + Write-Output "build: Package version suffix is $suffix" |
| 29 | + Write-Output "build: Build version suffix is $buildSuffix" |
20 | 30 |
|
21 |
| -foreach ($src in ls src/*) { |
22 |
| - Push-Location $src |
| 31 | + & dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true |
| 32 | + if($LASTEXITCODE -ne 0) { throw "Build failed" } |
23 | 33 |
|
24 |
| - echo "build: Packaging project in $src" |
| 34 | + foreach ($src in Get-ChildItem src/*) { |
| 35 | + Push-Location $src |
25 | 36 |
|
26 |
| - if ($suffix) { |
27 |
| - & dotnet publish -c Release -o ./obj/publish --version-suffix=$suffix |
28 |
| - & dotnet pack -c Release -o ..\..\artifacts --no-build --version-suffix=$suffix |
29 |
| - } else { |
30 |
| - & dotnet publish -c Release -o ./obj/publish |
31 |
| - & dotnet pack -c Release -o ..\..\artifacts --no-build |
| 37 | + Write-Output "build: Packaging project in $src" |
| 38 | + |
| 39 | + if ($suffix) { |
| 40 | + & dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix |
| 41 | + } else { |
| 42 | + & dotnet pack -c Release --no-build --no-restore -o ../../artifacts |
| 43 | + } |
| 44 | + if($LASTEXITCODE -ne 0) { throw "Packaging failed" } |
| 45 | + |
| 46 | + Pop-Location |
32 | 47 | }
|
33 |
| - if($LASTEXITCODE -ne 0) { exit 1 } |
34 | 48 |
|
35 |
| - Pop-Location |
36 |
| -} |
| 49 | + if(Test-Path .\test) { |
| 50 | + foreach ($test in Get-ChildItem test/*.Tests) { |
| 51 | + Push-Location $test |
37 | 52 |
|
38 |
| -foreach ($test in ls test/*.Tests) { |
39 |
| - Push-Location $test |
| 53 | + Write-Output "build: Testing project in $test" |
40 | 54 |
|
41 |
| - echo "build: Testing project in $test" |
| 55 | + & dotnet test -c Release --no-build --no-restore |
| 56 | + if($LASTEXITCODE -ne 0) { throw "Testing failed" } |
42 | 57 |
|
43 |
| - & dotnet test -c Release |
44 |
| - if($LASTEXITCODE -ne 0) { exit 3 } |
| 58 | + Pop-Location |
| 59 | + } |
| 60 | + } |
| 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 | + } |
45 | 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 | + } |
| 79 | +} finally { |
46 | 80 | Pop-Location
|
47 | 81 | }
|
48 |
| - |
49 |
| -Pop-Location |
|
0 commit comments