Skip to content

Commit 6dd671d

Browse files
authored
Merge pull request #176
ci: improvements to sign output
2 parents c100ab1 + 4866cf0 commit 6dd671d

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

build/sign.ps1

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ function Initialize-DirectoryStructure {
9797
Packages = Join-Path $BaseDirectory "signed\packages"
9898
}
9999

100-
Write-Host "`nCreating directory structure..."
100+
Write-Debug "`nCreating directory structure..."
101101
# Only create the directories we'll manage
102102
$directories.Keys | Where-Object { $_ -ne 'WorkingDir' } | ForEach-Object {
103103
$dir = $directories[$_]
104104
if (-not (Test-Path $dir)) {
105105
New-Item -ItemType Directory -Path $dir -Force | Out-Null
106-
Write-Host "✓ Created: $dir"
106+
Write-Debug "✓ Created: $dir"
107107
}
108108
}
109109

@@ -120,25 +120,23 @@ function Test-GithubAttestation {
120120
[string]$RepoName
121121
)
122122

123-
Write-Host " 🔐 Verifying attestation for: $FilePath" -ForegroundColor Gray
123+
# Get the parent directory name and the file name
124+
$fileName = (Get-ChildItem $FilePath).Name
125+
126+
Write-Host " 🔐 Verifying attestation for: ..$parentDir\$fileName" -ForegroundColor Gray
124127

125128
try {
126-
# Check if gh CLI is available
127-
if (-not (Get-Command gh -ErrorAction SilentlyContinue)) {
128-
throw "GitHub CLI (gh) is not installed or not in PATH"
129-
}
130-
131129
$output = gh attestation verify $FilePath --repo $RepoName 2>&1
132130
if ($LASTEXITCODE -ne 0) {
133131
Write-Host $output -ForegroundColor Red
134132
throw $output # This will trigger the catch block
135133
}
136134

137-
Write-Host "Attestation verified" -ForegroundColor Green
135+
Write-Host "Verified" -ForegroundColor Green
138136
return $true
139137
}
140138
catch {
141-
Write-Host "Attestation verification failed: $_" -ForegroundColor Red
139+
Write-Host "Verification failed: $_" -ForegroundColor Red
142140
return $false
143141
}
144142
}
@@ -160,6 +158,8 @@ How to use:
160158
> . \.Yubico.NET.SDK\build\sign.ps1
161159
4. The script can be invoked by following the examples below.
162160
161+
Set $DebugPreference = "Continue" for verbose output
162+
163163
.PARAMETER Thumbprint
164164
The thumbprint of the signing certificate stored on the smart card.
165165
@@ -241,6 +241,11 @@ function Invoke-NuGetPackageSigning {
241241
}
242242
Write-Host "✓ NuGet found at: $NuGetPath"
243243

244+
if (-not (Get-Command gh -ErrorAction SilentlyContinue)) {
245+
throw "GitHub CLI installed or not found in PATH"
246+
}
247+
Write-Host "✓ GitHub CLI found at: $NuGetPath"
248+
244249
# Verify certificate is available and log details
245250
$cert = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $Thumbprint }
246251
if (-not $cert) {
@@ -304,7 +309,7 @@ function Invoke-NuGetPackageSigning {
304309
Write-Host "Extracting to: $extractPath"
305310
Expand-Archive -Path $package.FullName -DestinationPath $extractPath -Force
306311

307-
Write-Host "Cleaning package structure"
312+
Write-Debug "Cleaning package structure"
308313
Get-ChildItem -Path $extractPath -Recurse -Include "_rels", "package" | Remove-Item -Force -Recurse
309314
Get-ChildItem -Path $extractPath -Recurse -Filter '[Content_Types].xml' | Remove-Item -Force
310315

@@ -318,11 +323,16 @@ function Invoke-NuGetPackageSigning {
318323
Sign-SingleFile -FilePath $dll.FullName -Thumbprint $Thumbprint -SignToolPath $SignToolPath -TimestampServer $TimestampServer
319324
}
320325

321-
Write-Host "Repacking signed content..."
326+
Write-Host "Repacking assemblies..."
322327
Get-ChildItem -Path $extractPath -Recurse -Filter "*.nuspec" |
323328
ForEach-Object {
324329
Write-Host " Packing: $($_.Name)"
325-
& $NuGetPath pack $_.FullName -OutputDirectory $directories.Packages
330+
$output = & $NuGetPath pack $_.FullName -OutputDirectory $directories.Packages 2>&1
331+
332+
if ($LASTEXITCODE -ne 0) {
333+
$output | ForEach-Object { Write-Host $_ }
334+
throw "Signing failed for file: $FilePath"
335+
}
326336
}
327337
}
328338

@@ -345,7 +355,13 @@ function Invoke-NuGetPackageSigning {
345355
"-Timestamper", $TimestampServer,
346356
"-NonInteractive"
347357
)
348-
& $NuGetPath @nugetSignParams
358+
359+
$output = & $NuGetPath @nugetSignParams 2>&1
360+
361+
if ($LASTEXITCODE -ne 0) {
362+
$output | ForEach-Object { Write-Host $_ }
363+
throw "Signing failed for file: $FilePath"
364+
}
349365
}
350366

351367
# Print summary of signed packages
@@ -363,7 +379,9 @@ function Invoke-NuGetPackageSigning {
363379
}
364380

365381
Write-Host "`n✨ Package signing process completed successfully! ✨" -ForegroundColor Green
366-
return $directories.Packages
382+
Write-Host "➡️ Locate your signed packages here: $($directories.Packages)" -ForegroundColor Yellow
383+
384+
return
367385
}
368386
catch {
369387
Write-Host "`n❌ Error occurred:" -ForegroundColor Red

0 commit comments

Comments
 (0)