@@ -7,85 +7,79 @@ Write-Output "build: Build started"
77
88Push-Location $PSScriptRoot
99
10- Write-Output " build: PR_TRIGGER value: $env: PR_TRIGGER "
11-
1210if ($env: PR_TRIGGER -eq " true" ) {
13- Write-Output " build: This is a PR build - skipping packaging and publishing steps"
1411 $skipPackaging = $true
1512} else {
1613 $skipPackaging = $false
1714}
1815
19- # try {
20- # if(Test-Path .\artifacts) {
21- # Write-Output "build: Cleaning ./artifacts"
22- # Remove-Item ./artifacts -Force -Recurse
23- # }
24-
25- # & dotnet restore --no-cache
26-
27- # $dvp = [Xml] (Get-Content .\Directory.Version.props)
28- # $versionPrefix = $dvp.Project.PropertyGroup.VersionPrefix
16+ try {
17+ if (Test-Path .\artifacts) {
18+ Write-Output " build: Cleaning ./artifacts"
19+ Remove-Item ./ artifacts - Force - Recurse
20+ }
2921
30- # Write-Output "build: Package base version is $versionPrefix"
22+ & dotnet restore -- no - cache
3123
32- # $branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
33- # $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
34- # $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "master" -and $revision -ne "local"]
35- # $commitHash = $(git rev-parse --short HEAD)
36- # $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
24+ $dvp = [Xml ] (Get-Content .\Directory.Version.props)
25+ $versionPrefix = $dvp.Project.PropertyGroup.VersionPrefix
3726
38- # Write-Output "build: Package version suffix is $suffix"
39- # Write-Output "build: Build version suffix is $buildSuffix"
27+ Write-Output " build: Package base version is $versionPrefix "
4028
41- # & dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
42- # if($LASTEXITCODE -ne 0) { throw "Build failed" }
29+ $branch = @ { $true = $env: CI_TARGET_BRANCH ; $false = $ (git symbolic- ref -- short - q HEAD) }[$NULL -ne $env: CI_TARGET_BRANCH ];
30+ $revision = @ { $true = " {0:00000}" -f [convert ]::ToInt32(" 0" + $env: CI_BUILD_NUMBER , 10 ); $false = " local" }[$NULL -ne $env: CI_BUILD_NUMBER ];
31+ $suffix = @ { $true = " " ; $false = " $ ( $branch.Substring (0 , [math ]::Min(10 , $branch.Length )) -replace ' ([^a-zA-Z0-9\-]*)' , ' ' ) -$revision " }[$branch -eq " master" -and $revision -ne " local" ]
32+ $commitHash = $ (git rev- parse -- short HEAD)
33+ $buildSuffix = @ { $true = " $ ( $suffix ) -$ ( $commitHash ) " ; $false = " $ ( $branch ) -$ ( $commitHash ) " }[$suffix -ne " " ]
4334
44- # foreach ($src in Get-ChildItem src/*) {
45- # Push-Location $src
35+ Write-Output " build: Package version suffix is $suffix "
36+ Write-Output " build: Build version suffix is $buildSuffix "
4637
47- # Write-Output "build: Packaging project in $src"
38+ & dotnet build - c Release -- version- suffix= $buildSuffix / p:ContinuousIntegrationBuild= true
39+ if ($LASTEXITCODE -ne 0 ) { throw " Build failed" }
4840
49- # if ($suffix) {
50- # & dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix
51- # } else {
52- # & dotnet pack -c Release --no-build --no-restore -o ../../artifacts
53- # }
54- # if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
41+ foreach ($src in Get-ChildItem src/* ) {
42+ Push-Location $src
5543
56- # Pop-Location
57- # }
44+ Write-Output " build: Packaging project in $src "
5845
59- # foreach ($test in Get-ChildItem tests/) {
60- # Push-Location $test
46+ if ($suffix ) {
47+ & dotnet pack - c Release -- no- build -- no- restore - o ../ ../ artifacts -- version- suffix= $suffix
48+ } else {
49+ & dotnet pack - c Release -- no- build -- no- restore - o ../ ../ artifacts
50+ }
51+ if ($LASTEXITCODE -ne 0 ) { throw " Packaging failed" }
6152
62- # Write-Output "build: Testing project in $test"
53+ Pop-Location
54+ }
6355
64- # & dotnet test -c Release --no-build --no-restore
65- # if($LASTEXITCODE -ne 0) { throw "Testing failed" }
56+ foreach ( $ test in Get-ChildItem tests / ) {
57+ Push-Location $test
6658
67- # Pop-Location
68- # }
59+ Write-Output " build: Testing project in $test "
6960
70- # if ($env:DUMMY) {
71- # # GitHub Actions will only supply this to branch builds and not PRs. We publish
72- # # builds from any branch this action targets (i.e. master and dev).
61+ & dotnet test - c Release -- no- build -- no- restore
62+ if ($LASTEXITCODE -ne 0 ) { throw " Testing failed" }
7363
74- # Write-Output "DUMMY value: $env:DUMMY"
64+ Pop-Location
65+ }
7566
76- # # Write-Output "build: Publishing NuGet package"
67+ if ($skipPackaging -eq $false ) {
68+ Write-Output " build: Publishing NuGet package"
7769
78- # # foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
79- # # & dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
80- # # if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
81- # # }
70+ foreach ($nupkg in Get-ChildItem artifacts/* .nupkg) {
71+ & dotnet nuget push - k $env: NUGET_API_KEY - s https:// api.nuget.org/ v3/ index.json " $nupkg "
72+ if ($LASTEXITCODE -ne 0 ) { throw " Publishing failed" }
73+ }
8274
83- # # if (!($suffix)) {
84- # # Write-Output "build: Creating release for version $versionPrefix"
75+ if (! ($suffix )) {
76+ Write-Output " build: Creating release for version $versionPrefix "
8577
86- # # iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
87- # # }
88- # }
89- # } finally {
90- # Pop-Location
91- # }
78+ iex " gh release create v$versionPrefix --title v$versionPrefix --generate-notes $ ( get-item ./ artifacts/* .nupkg) $ ( get-item ./ artifacts/* .snupkg) "
79+ }
80+ } else {
81+ Write-Output " build: Skipping publishing steps for PR build"
82+ }
83+ } finally {
84+ Pop-Location
85+ }
0 commit comments