opencode/script/sign-windows.ps1
Filip Hejmowski a26b0a73e4 fix(ci): keep dev previews and published libraries working with pack-npm
- when pack-npm fails on a non-release run, publish builds the libraries
  in place as before, so the CLI dev preview still ships after client
- library scripts skip versions already on npm in pack mode too, and
  NpmLibraries.verify accepts a missing tarball only for a published
  version, so a re-dispatched release does not rerun every check
- trim comments that restated code and correct inaccurate ones
2026-10-19 15:15:48 +02:00

89 lines
2.8 KiB
PowerShell

param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $Path
)
$ErrorActionPreference = "Stop"
if (-not $Path -or $Path.Count -eq 0) {
throw "At least one path is required"
}
if ($env:GITHUB_ACTIONS -ne "true") {
Write-Host "Skipping Windows signing because this is not running on GitHub Actions"
exit 0
}
$vars = @{
endpoint = $env:AZURE_TRUSTED_SIGNING_ENDPOINT
account = $env:AZURE_TRUSTED_SIGNING_ACCOUNT_NAME
profile = $env:AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE
}
if ($vars.Values | Where-Object { -not $_ }) {
Write-Host "Skipping Windows signing because Azure Artifact Signing is not configured"
exit 0
}
$moduleVersion = "0.5.8"
$module = Get-Module -ListAvailable -Name TrustedSigning | Where-Object { $_.Version -eq [version] $moduleVersion }
if (-not $module) {
try {
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser | Out-Null
}
catch {
Write-Host "NuGet package provider install skipped: $($_.Exception.Message)"
}
# PowerShellGet registers PSGallery only when the gallery answers, so a short outage fails Install-Module with
# "Unable to find repository 'PSGallery'".
foreach ($attempt in 1..3) {
try {
if (-not (Get-PSRepository | Where-Object { $_.Name -eq "PSGallery" })) {
Register-PSRepository -Default
}
Install-Module -Name TrustedSigning -RequiredVersion $moduleVersion -Force -Repository PSGallery -Scope CurrentUser
break
}
catch {
if ($attempt -eq 3) {
throw
}
Write-Host "::warning::TrustedSigning module install attempt $attempt failed: $($_.Exception.Message)"
Start-Sleep -Seconds (30 * $attempt)
}
}
}
Import-Module TrustedSigning -RequiredVersion $moduleVersion -Force
$files = @($Path | ForEach-Object { Resolve-Path $_ -ErrorAction SilentlyContinue } | Select-Object -ExpandProperty Path -Unique)
if (-not $files -or $files.Count -eq 0) {
throw "No files matched the requested paths"
}
$params = @{
Endpoint = $vars.endpoint
CodeSigningAccountName = $vars.account
CertificateProfileName = $vars.profile
Files = ($files -join ",")
FileDigest = "SHA256"
TimestampDigest = "SHA256"
TimestampRfc3161 = "http://timestamp.acs.microsoft.com"
ExcludeEnvironmentCredential = $true
ExcludeWorkloadIdentityCredential = $true
ExcludeManagedIdentityCredential = $true
ExcludeSharedTokenCacheCredential = $true
ExcludeVisualStudioCredential = $true
ExcludeVisualStudioCodeCredential = $true
ExcludeAzureCliCredential = $false
ExcludeAzurePowerShellCredential = $true
ExcludeAzureDeveloperCliCredential = $true
ExcludeInteractiveBrowserCredential = $true
}
Invoke-TrustedSigning @params