|  | 
| 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 | 
| 15 | 19 | 
 | 
| 16 |  | -echo "build: Version suffix is $suffix" | 
|  | 20 | +Write-Output "build: Package version prefix is $versionPrefix" | 
| 17 | 21 | 
 | 
| 18 |  | -foreach ($src in ls src/*) { | 
| 19 |  | -    Push-Location $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"] | 
| 20 | 25 | 
 | 
| 21 |  | -    echo "build: Packaging project in $src" | 
|  | 26 | +Write-Output "build: Package version suffix is $suffix" | 
| 22 | 27 | 
 | 
| 23 |  | -    if ($suffix) { | 
| 24 |  | -        & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix | 
| 25 |  | -    } else { | 
| 26 |  | -        & dotnet pack -c Release -o ..\..\artifacts | 
| 27 |  | -    } | 
| 28 |  | -     | 
| 29 |  | -    if($LASTEXITCODE -ne 0) { exit 1 }     | 
| 30 |  | - | 
| 31 |  | -    Pop-Location | 
|  | 28 | +if ($suffix) { | 
|  | 29 | +    & dotnet build -c Release --version-suffix=$suffix /p:ContinuousIntegrationBuild=true | 
|  | 30 | +} else { | 
|  | 31 | +    & dotnet build -c Release /p:ContinuousIntegrationBuild=true | 
| 32 | 32 | } | 
| 33 | 33 | 
 | 
| 34 |  | -foreach ($test in ls test/*.PerformanceTests) { | 
| 35 |  | -    Push-Location $test | 
|  | 34 | +if($LASTEXITCODE -ne 0) { throw "Build failed" } | 
| 36 | 35 | 
 | 
| 37 |  | -    echo "build: Building performance test project in $test" | 
|  | 36 | +foreach ($src in Get-ChildItem src/*) { | 
|  | 37 | +    Push-Location $src | 
| 38 | 38 | 
 | 
| 39 |  | -    & dotnet build -c Release | 
| 40 |  | -    if($LASTEXITCODE -ne 0) { exit 2 } | 
|  | 39 | +	Write-Output "build: Packaging project in $src" | 
|  | 40 | +	if ($suffix) { | 
|  | 41 | +		& dotnet pack -c Release --no-build --no-restore  -o ../../artifacts --version-suffix=$suffix | 
|  | 42 | +	} else { | 
|  | 43 | +		& dotnet pack -c Release --no-build --no-restore  -o ../../artifacts | 
|  | 44 | +	} | 
|  | 45 | +    if($LASTEXITCODE -ne 0) { throw "Packaging failed" } | 
| 41 | 46 | 
 | 
| 42 | 47 |     Pop-Location | 
| 43 | 48 | } | 
| 44 | 49 | 
 | 
| 45 |  | -foreach ($test in ls test/*.Tests) { | 
|  | 50 | +foreach ($test in Get-ChildItem test/*.Tests) { | 
| 46 | 51 |     Push-Location $test | 
| 47 | 52 | 
 | 
| 48 |  | -    echo "build: Testing project in $test" | 
|  | 53 | +	Write-Output "build: Testing project in $test" | 
| 49 | 54 | 
 | 
| 50 | 55 |     & dotnet test -c Release | 
| 51 |  | -    if($LASTEXITCODE -ne 0) { exit 3 } | 
|  | 56 | +    if($LASTEXITCODE -ne 0) { throw "Testing failed" } | 
| 52 | 57 | 
 | 
| 53 | 58 |     Pop-Location | 
| 54 | 59 | } | 
| 55 | 60 | 
 | 
| 56 | 61 | Pop-Location | 
|  | 62 | + | 
|  | 63 | +if ($env:NUGET_API_KEY) { | 
|  | 64 | +    # GitHub Actions will only supply this to branch builds and not PRs. We publish | 
|  | 65 | +    # builds from any branch this action targets (i.e. main and dev). | 
|  | 66 | +     | 
|  | 67 | +    Write-Output "build: Publishing NuGet packages" | 
|  | 68 | +     | 
|  | 69 | +    foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) { | 
|  | 70 | +        & dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg" | 
|  | 71 | +        if($LASTEXITCODE -ne 0) { throw "Publishing failed" } | 
|  | 72 | +    } | 
|  | 73 | + | 
|  | 74 | +    if (!($suffix)) { | 
|  | 75 | +        Write-Output "build: Creating release for version $versionPrefix" | 
|  | 76 | + | 
|  | 77 | +        iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)" | 
|  | 78 | +    } | 
|  | 79 | +} | 
0 commit comments