|
1 | | -echo "build: Build started" |
| 1 | +Write-Output "build: Build started" |
2 | 2 |
|
3 | 3 | Push-Location $PSScriptRoot |
4 | 4 |
|
| 5 | +Write-Output "build: Tool versions follow" |
| 6 | + |
| 7 | +dotnet --version |
| 8 | +dotnet --list-sdks |
| 9 | + |
5 | 10 | if(Test-Path .\artifacts) { |
6 | | - echo "build: Cleaning .\artifacts" |
7 | | - Remove-Item .\artifacts -Force -Recurse |
| 11 | + Write-Output "build: Cleaning ./artifacts" |
| 12 | + Remove-Item ./artifacts -Force -Recurse |
8 | 13 | } |
9 | 14 |
|
10 | 15 | & dotnet restore --no-cache |
11 | 16 |
|
12 | | -$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; |
13 | | -$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
14 | | -$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 |
| 19 | + |
| 20 | +Write-Output "build: Package version prefix is $versionPrefix" |
15 | 21 |
|
16 | | -echo "build: Version suffix is $suffix" |
| 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"] |
17 | 25 |
|
18 | | -foreach ($src in ls src/*) { |
| 26 | +Write-Output "build: Package version suffix is $suffix" |
| 27 | + |
| 28 | +foreach ($src in Get-ChildItem src/*) { |
19 | 29 | Push-Location $src |
20 | 30 |
|
21 | | - echo "build: Packaging project in $src" |
| 31 | + Write-Output "build: Packaging project in $src" |
22 | 32 |
|
23 | 33 | if ($suffix) { |
24 | | - & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix |
| 34 | + & dotnet publish -c Release -o ./obj/publish --version-suffix=$suffix |
| 35 | + & dotnet pack -c Release -o ../../artifacts --no-build --version-suffix=$suffix |
25 | 36 | } else { |
26 | | - & dotnet pack -c Release -o ..\..\artifacts |
| 37 | + & dotnet publish -c Release -o ./obj/publish |
| 38 | + & dotnet pack -c Release -o ../../artifacts --no-build |
27 | 39 | } |
28 | | - |
29 | | - if($LASTEXITCODE -ne 0) { exit 1 } |
| 40 | + if($LASTEXITCODE -ne 0) { throw "Packaging failed" } |
30 | 41 |
|
31 | 42 | Pop-Location |
32 | 43 | } |
33 | 44 |
|
34 | | -foreach ($test in ls test/*.PerformanceTests) { |
| 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) { |
35 | 50 | Push-Location $test |
36 | 51 |
|
37 | | - echo "build: Building performance test project in $test" |
| 52 | + Write-Output "build: Testing project in $test" |
38 | 53 |
|
39 | | - & dotnet build -c Release |
40 | | - if($LASTEXITCODE -ne 0) { exit 2 } |
| 54 | + & dotnet test -c Release |
| 55 | + if($LASTEXITCODE -ne 0) { throw "Testing failed" } |
41 | 56 |
|
42 | 57 | Pop-Location |
43 | 58 | } |
44 | 59 |
|
45 | | -foreach ($test in ls test/*.Tests) { |
46 | | - Push-Location $test |
| 60 | +Pop-Location |
47 | 61 |
|
48 | | - echo "build: Testing project in $test" |
| 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 | + } |
49 | 72 |
|
50 | | - & dotnet test -c Release |
51 | | - if($LASTEXITCODE -ne 0) { exit 3 } |
| 73 | + if (!($suffix)) { |
| 74 | + Write-Output "build: Creating release for version $versionPrefix" |
52 | 75 |
|
53 | | - Pop-Location |
| 76 | + iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)" |
| 77 | + } |
54 | 78 | } |
55 | | - |
56 | | -Pop-Location |
|
0 commit comments