| 
1 |  | -echo "build: Build started"  | 
 | 1 | +Write-Output "build: Tool versions follow"  | 
 | 2 | + | 
 | 3 | +dotnet --version  | 
 | 4 | +dotnet --list-sdks  | 
 | 5 | + | 
 | 6 | +Write-Output "build: Build started"  | 
2 | 7 | 
 
  | 
3 | 8 | Push-Location $PSScriptRoot  | 
 | 9 | +try {  | 
 | 10 | +    if(Test-Path .\artifacts) {  | 
 | 11 | +        Write-Output "build: Cleaning ./artifacts"  | 
 | 12 | +        Remove-Item ./artifacts -Force -Recurse  | 
 | 13 | +    }  | 
4 | 14 | 
 
  | 
5 |  | -if(Test-Path .\artifacts) {  | 
6 |  | -	echo "build: Cleaning .\artifacts"  | 
7 |  | -	Remove-Item .\artifacts -Force -Recurse  | 
8 |  | -}  | 
 | 15 | +    & dotnet restore --no-cache  | 
 | 16 | + | 
 | 17 | +    $dbp = [Xml] (Get-Content .\Directory.Version.props)  | 
 | 18 | +    $versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix  | 
 | 19 | + | 
 | 20 | +    Write-Output "build: Package version prefix is $versionPrefix"  | 
 | 21 | + | 
 | 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 ""]  | 
9 | 27 | 
 
  | 
10 |  | -& dotnet restore --no-cache  | 
 | 28 | +    Write-Output "build: Package version suffix is $suffix"  | 
 | 29 | +    Write-Output "build: Build version suffix is $buildSuffix"  | 
11 | 30 | 
 
  | 
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"]  | 
15 |  | -$commitHash = $(git rev-parse --short HEAD)  | 
16 |  | -$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]  | 
 | 31 | +    & dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true  | 
 | 32 | +    if($LASTEXITCODE -ne 0) { throw "Build failed" }  | 
17 | 33 | 
 
  | 
18 |  | -echo "build: Package version suffix is $suffix"  | 
19 |  | -echo "build: Build version suffix is $buildSuffix"   | 
 | 34 | +    foreach ($src in Get-ChildItem src/*) {  | 
 | 35 | +        Push-Location $src  | 
20 | 36 | 
 
  | 
21 |  | -foreach ($src in ls src/*) {  | 
22 |  | -    Push-Location $src  | 
 | 37 | +        Write-Output "build: Packaging project in $src"  | 
23 | 38 | 
 
  | 
24 |  | -	echo "build: Packaging project in $src"  | 
 | 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" }  | 
25 | 45 | 
 
  | 
26 |  | -    & dotnet build -c Release --version-suffix=$buildSuffix -p:EnableSourceLink=true  | 
27 |  | -    if ($suffix) {  | 
28 |  | -        & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --no-build  | 
29 |  | -    } else {  | 
30 |  | -        & dotnet pack -c Release -o ..\..\artifacts --no-build  | 
 | 46 | +        Pop-Location  | 
31 | 47 |     }  | 
32 |  | -    if($LASTEXITCODE -ne 0) { throw "build failed" }      | 
33 | 48 | 
 
  | 
34 |  | -    Pop-Location  | 
35 |  | -}  | 
 | 49 | +    foreach ($test in Get-ChildItem test/*.Tests) {  | 
 | 50 | +        Push-Location $test  | 
36 | 51 | 
 
  | 
37 |  | -foreach ($test in ls test/*.Tests) {  | 
38 |  | -    Push-Location $test  | 
 | 52 | +        Write-Output "build: Testing project in $test"  | 
39 | 53 | 
 
  | 
40 |  | -	echo "build: Testing project in $test"  | 
 | 54 | +        & dotnet test -c Release --no-build --no-restore  | 
 | 55 | +        if($LASTEXITCODE -ne 0) { throw "Testing failed" }  | 
41 | 56 | 
 
  | 
42 |  | -    & dotnet test -c Release  | 
43 |  | -    if($LASTEXITCODE -ne 0) { throw "tests failed" }      | 
 | 57 | +        Pop-Location  | 
 | 58 | +    }  | 
44 | 59 | 
 
  | 
45 |  | -    Pop-Location  | 
46 |  | -}  | 
 | 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).  | 
47 | 63 | 
 
  | 
48 |  | -foreach ($test in ls test/*.PerformanceTests) {  | 
49 |  | -    Push-Location $test  | 
 | 64 | +        Write-Output "build: Publishing NuGet packages"  | 
50 | 65 | 
 
  | 
51 |  | -	echo "build: Building project in $test"  | 
 | 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 | +        }  | 
52 | 70 | 
 
  | 
53 |  | -    & dotnet build -c Release  | 
54 |  | -    if($LASTEXITCODE -ne 0) { throw "performance test build failed" }      | 
 | 71 | +        if (!($suffix)) {  | 
 | 72 | +            Write-Output "build: Creating release for version $versionPrefix"  | 
55 | 73 | 
 
  | 
 | 74 | +            iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"  | 
 | 75 | +        }  | 
 | 76 | +    }  | 
 | 77 | +} finally {  | 
56 | 78 |     Pop-Location  | 
57 | 79 | }  | 
58 |  | - | 
59 |  | -Pop-Location  | 
 | 
0 commit comments