Skip to content

Commit ccc505e

Browse files
committed
fixing publish in build script
1 parent 7187f57 commit ccc505e

File tree

1 file changed

+43
-40
lines changed

1 file changed

+43
-40
lines changed

build.ps1

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ param(
66
[Parameter(Mandatory = $false)]
77
[switch]$Test = $false,
88

9-
[Parameter(Mandatory = $false)]
10-
[switch]$Publish = $false,
11-
129
[Parameter(Mandatory = $false)]
1310
[string]$GitHubPat = "",
1411

@@ -20,20 +17,26 @@ param(
2017
[string]$LocalNugetPath = "G:\NuGetPackages"
2118
)
2219

20+
# Automatically enable publish mode if GitHubPat is provided
21+
$Publish = $false
22+
if ($GitHubPat -and $GitHubPat.Trim().Length -gt 0) {
23+
$Publish = $true
24+
}
25+
2326
# Display banner
2427
Write-Host "====================================================="
2528
Write-Host "Xcaciv.Loader Build Script"
2629
Write-Host "====================================================="
2730
if ($Publish) {
28-
Write-Host "Mode: Publish (building for .NET 8.0 and .NET 10.0)"
31+
Write-Host "Mode: Publish (building for .NET 8.0 and .NET 10.0)" -ForegroundColor Cyan
2932
} elseif ($UseNet10) {
30-
Write-Host "Building for both .NET 8.0 and .NET 10.0"
33+
Write-Host "Target Framework: Both .NET 8.0 and .NET 10.0"
3134
} else {
3235
Write-Host "Target Framework: .NET 8.0"
3336
}
3437
Write-Host "Run Tests: $( if ($Test) { "Yes" } else { "No" } )"
3538
Write-Host "Local NuGet path: $LocalNugetPath"
36-
if ($GitHubPat -and $GitHubPat.Trim().Length -gt 0) {
39+
if ($Publish) {
3740
Write-Host "NuGet Push: Enabled (GitHub PAT provided)" -ForegroundColor Green
3841
} else {
3942
Write-Host "NuGet Push: Disabled (no GitHub PAT)" -ForegroundColor Yellow
@@ -95,29 +98,33 @@ if ($Publish) {
9598
}
9699

97100
# Mandatory local copy to NuGet packages directory (only if directory exists)
98-
try {
99-
$targetLocal = $LocalNugetPath.TrimEnd('\', '/')
100-
if (-not (Test-Path -Path $targetLocal -PathType Container)) {
101-
Write-Host "ERROR: Local NuGet directory does not exist: $targetLocal" -ForegroundColor Red
101+
if ([string]::IsNullOrWhiteSpace($LocalNugetPath)) {
102+
Write-Host "Warning: LocalNugetPath is not specified, skipping local copy" -ForegroundColor Yellow
103+
} else {
104+
try {
105+
$targetLocal = $LocalNugetPath.TrimEnd('\', '/')
106+
if (-not (Test-Path -Path $targetLocal -PathType Container)) {
107+
Write-Host "ERROR: Local NuGet directory does not exist: $targetLocal" -ForegroundColor Red
108+
exit 1
109+
}
110+
Write-Host "Copying packages to local directory: $targetLocal" -ForegroundColor Cyan
111+
$localCopied = 0
112+
$publishPackages = Get-ChildItem -Path $publishDir -Filter "*.nupkg" -ErrorAction SilentlyContinue
113+
$publishSymbols = Get-ChildItem -Path $publishDir -Filter "*.snupkg" -ErrorAction SilentlyContinue
114+
foreach ($pkg in @($publishPackages + $publishSymbols)) {
115+
Copy-Item -Path $pkg.FullName -Destination $targetLocal -Force
116+
Write-Host " Copied locally: $($pkg.Name)" -ForegroundColor Green
117+
$localCopied++
118+
}
119+
if ($localCopied -eq 0) {
120+
Write-Host "No packages found to copy locally." -ForegroundColor Yellow
121+
} else {
122+
Write-Host "Copied $localCopied package(s) to local directory: $targetLocal" -ForegroundColor Green
123+
}
124+
} catch {
125+
Write-Host "Failed to copy packages locally: $($_.Exception.Message)" -ForegroundColor Red
102126
exit 1
103127
}
104-
Write-Host "Copying packages to local directory: $targetLocal" -ForegroundColor Cyan
105-
$localCopied = 0
106-
$publishPackages = Get-ChildItem -Path $publishDir -Filter "*.nupkg" -ErrorAction SilentlyContinue
107-
$publishSymbols = Get-ChildItem -Path $publishDir -Filter "*.snupkg" -ErrorAction SilentlyContinue
108-
foreach ($pkg in @($publishPackages + $publishSymbols)) {
109-
Copy-Item -Path $pkg.FullName -Destination $targetLocal -Force
110-
Write-Host " Copied locally: $($pkg.Name)" -ForegroundColor Green
111-
$localCopied++
112-
}
113-
if ($localCopied -eq 0) {
114-
Write-Host "No packages found to copy locally." -ForegroundColor Yellow
115-
} else {
116-
Write-Host "Copied $localCopied package(s) to local directory: $targetLocal" -ForegroundColor Green
117-
}
118-
} catch {
119-
Write-Host "Failed to copy packages locally: $($_.Exception.Message)" -ForegroundColor Red
120-
exit 1
121128
}
122129

123130
} else {
@@ -215,8 +222,8 @@ if ($Test) {
215222
}
216223
}
217224

218-
# Push packages to NuGet (GitHub Packages) only when publishing and PAT provided
219-
if ($Publish -and $GitHubPat -and $GitHubPat.Trim().Length -gt 0) {
225+
# Push packages to NuGet (GitHub Packages) only when publishing
226+
if ($Publish) {
220227
Write-Host "====================================================="
221228
Write-Host "Pushing packages to NuGet (GitHub Packages)..." -ForegroundColor Cyan
222229

@@ -243,23 +250,17 @@ if ($Publish -and $GitHubPat -and $GitHubPat.Trim().Length -gt 0) {
243250
'--api-key',$GitHubPat,
244251
'--skip-duplicate'
245252
)
246-
$loggingArgs = $pushArgs.Clone()
247-
for ($i = 0; $i -lt $loggingArgs.Length; $i++) {
248-
if ($loggingArgs[$i] -eq '--api-key' -and ($i + 1) -lt $loggingArgs.Length) {
249-
$loggingArgs[$i + 1] = '***REDACTED***'
250-
break
251-
}
252-
}
253-
Write-Host "Executing: dotnet $($loggingArgs -join ' ')" -ForegroundColor Gray
253+
Write-Host "Executing: dotnet nuget push [package] --source $sourceUrl --api-key ***REDACTED*** --skip-duplicate" -ForegroundColor Gray
254254
# Execute and capture output to detect specific warnings-as-errors
255255
$pushOutput = & dotnet $pushArgs 2>&1
256256
# Echo output to console
257257
if ($pushOutput) { $pushOutput | ForEach-Object { Write-Host $_ } }
258258

259259
if ($LASTEXITCODE -ne 0) {
260-
# NU1510 indicates a signing or trust issue; log explicit context but still treat as an error
260+
# Ignore NU1510 warnings treated as errors
261261
if ($pushOutput -match 'NU1510') {
262-
Write-Host "NuGet push reported NU1510 (signing or trust issue). Failing build; verify package signing and source trust configuration." -ForegroundColor Red
262+
Write-Host "NuGet push reported NU1510; treating as warning and continuing." -ForegroundColor Yellow
263+
continue
263264
}
264265
Write-Host "NuGet push failed for $($pkg.Name) with exit code $LASTEXITCODE" -ForegroundColor Red
265266
exit $LASTEXITCODE
@@ -274,7 +275,9 @@ if ($Publish) {
274275
Write-Host "====================================================="
275276
Write-Host "Publish completed successfully!" -ForegroundColor Green
276277
Write-Host "Packages available in: $(Join-Path $PSScriptRoot 'publish')" -ForegroundColor Cyan
277-
Write-Host "Local packages copied to: $LocalNugetPath" -ForegroundColor Cyan
278+
if (-not [string]::IsNullOrWhiteSpace($LocalNugetPath)) {
279+
Write-Host "Local packages copied to: $LocalNugetPath" -ForegroundColor Cyan
280+
}
278281
Write-Host "====================================================="
279282
} else {
280283
Write-Host "====================================================="

0 commit comments

Comments
 (0)