Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: improvements to sign output #176

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions build/sign.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ function Initialize-DirectoryStructure {
Packages = Join-Path $BaseDirectory "signed\packages"
}

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

Expand All @@ -120,25 +120,23 @@ function Test-GithubAttestation {
[string]$RepoName
)

Write-Host " 🔐 Verifying attestation for: $FilePath" -ForegroundColor Gray
# Get the parent directory name and the file name
$fileName = (Get-ChildItem $FilePath).Name

Write-Host " 🔐 Verifying attestation for: ..$parentDir\$fileName" -ForegroundColor Gray

try {
# Check if gh CLI is available
if (-not (Get-Command gh -ErrorAction SilentlyContinue)) {
throw "GitHub CLI (gh) is not installed or not in PATH"
}

$output = gh attestation verify $FilePath --repo $RepoName 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host $output -ForegroundColor Red
throw $output # This will trigger the catch block
}

Write-Host " ✅ Attestation verified" -ForegroundColor Green
Write-Host " ✅ Verified" -ForegroundColor Green
return $true
}
catch {
Write-Host " ❌ Attestation verification failed: $_" -ForegroundColor Red
Write-Host " ❌ Verification failed: $_" -ForegroundColor Red
return $false
}
}
Expand All @@ -160,6 +158,8 @@ How to use:
> . \.Yubico.NET.SDK\build\sign.ps1
4. The script can be invoked by following the examples below.

Set $DebugPreference = "Continue" for verbose output

.PARAMETER Thumbprint
The thumbprint of the signing certificate stored on the smart card.

Expand Down Expand Up @@ -241,6 +241,11 @@ function Invoke-NuGetPackageSigning {
}
Write-Host "✓ NuGet found at: $NuGetPath"

if (-not (Get-Command gh -ErrorAction SilentlyContinue)) {
throw "GitHub CLI installed or not found in PATH"
}
Write-Host "✓ GitHub CLI found at: $NuGetPath"

# Verify certificate is available and log details
$cert = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $Thumbprint }
if (-not $cert) {
Expand Down Expand Up @@ -304,7 +309,7 @@ function Invoke-NuGetPackageSigning {
Write-Host "Extracting to: $extractPath"
Expand-Archive -Path $package.FullName -DestinationPath $extractPath -Force

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

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

Write-Host "Repacking signed content..."
Write-Host "Repacking assemblies..."
Get-ChildItem -Path $extractPath -Recurse -Filter "*.nuspec" |
ForEach-Object {
Write-Host " Packing: $($_.Name)"
& $NuGetPath pack $_.FullName -OutputDirectory $directories.Packages
$output = & $NuGetPath pack $_.FullName -OutputDirectory $directories.Packages 2>&1

if ($LASTEXITCODE -ne 0) {
$output | ForEach-Object { Write-Host $_ }
throw "Signing failed for file: $FilePath"
}
}
}

Expand All @@ -345,7 +355,13 @@ function Invoke-NuGetPackageSigning {
"-Timestamper", $TimestampServer,
"-NonInteractive"
)
& $NuGetPath @nugetSignParams

$output = & $NuGetPath @nugetSignParams 2>&1

if ($LASTEXITCODE -ne 0) {
$output | ForEach-Object { Write-Host $_ }
throw "Signing failed for file: $FilePath"
}
}

# Print summary of signed packages
Expand All @@ -363,7 +379,9 @@ function Invoke-NuGetPackageSigning {
}

Write-Host "`n✨ Package signing process completed successfully! ✨" -ForegroundColor Green
return $directories.Packages
Write-Host "➡️ Locate your signed packages here: $($directories.Packages)" -ForegroundColor Yellow

return
}
catch {
Write-Host "`n❌ Error occurred:" -ForegroundColor Red
Expand Down