[CI] Improve version and sign check script (#24205)

* Remove multiple enumeration and condense conditional statements

* Update versionAndSignCheck.ps1

Add copyright year check

* Update versionAndSignCheck.ps1

Escape parentheses

* Updated logic to use regex matching
This commit is contained in:
Jeremy Sinclair
2023-03-11 09:47:54 -05:00
committed by GitHub
parent cc708e7ac5
commit c92931fe5a

View File

@@ -8,81 +8,72 @@ Param(
$DirPath = $targetDir; #this file is in pipeline, we need root. $DirPath = $targetDir; #this file is in pipeline, we need root.
$items = Get-ChildItem -Path $DirPath -File -Include *.exe, *.dll, *.ttf, PTCustomActions -Recurse -Force -ErrorAction SilentlyContinue $items = Get-ChildItem -Path $DirPath -File -Include *.exe, *.dll, *.ttf, PTCustomActions -Recurse -Force -ErrorAction SilentlyContinue
$versionExceptions = @(
"Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll",
"Microsoft.Windows.ApplicationModel.Resources.Projection.dll",
"Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll",
"Microsoft.Windows.AppLifecycle.Projection.dll",
"Microsoft.Windows.System.Power.Projection.dll",
"Microsoft.WindowsAppRuntime.Bootstrap.Net.dll",
"Microsoft.Xaml.Interactions.dll",
"Microsoft.Xaml.Interactivity.dll",
"hyjiacan.py4n.dll",
"Microsoft.WindowsAppRuntime.Release.Net.dll") -join '|';
$nullVersionExceptions = @(
"codicon.ttf",
"e_sqlite3.dll",
"vcamp140_app.dll",
"marshal.dll",
"Microsoft.UI.Composition.OSSupport.dll",
"Microsoft.UI.Xaml.Internal.dll",
"Microsoft.Windows.ApplicationModel.Resources.dll",
"Microsoft.WindowsAppRuntime.dll",
"Microsoft.WindowsAppRuntime.Bootstrap.dll",
"MRM.dll",
"PushNotificationsLongRunningTask.ProxyStub.dll",
"WindowsAppSdk.AppxDeploymentExtensions.Desktop.dll",
"System.Diagnostics.EventLog.Messages.dll") -join '|';
$totalFailure = 0; $totalFailure = 0;
Write-Host $DirPath; Write-Host $DirPath;
if(-not (Test-Path $DirPath)) if (-not (Test-Path $DirPath)) {
{
Write-Host "Folder does not exist!" Write-Host "Folder does not exist!"
} }
Write-Host "Total items: " $items.Count Write-Host "Total items: " $items.Count
if($items.Count -eq 0) if ($items.Count -eq 0) {
{
# no items means something bad happened. We should fail ASAP # no items means something bad happened. We should fail ASAP
exit 1; exit 1;
} }
$items | ForEach-Object { $items | ForEach-Object {
if($_.VersionInfo.FileVersion -eq "1.0.0.0" ) if ($_.VersionInfo.FileVersion -eq "1.0.0.0" -and $_.Name -notmatch $versionExceptions) {
{
# These items are exceptions that actually have the 1.0.0.0 version. # These items are exceptions that actually have the 1.0.0.0 version.
if ((-not $_.Name.EndsWith("Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Windows.ApplicationModel.Resources.Projection.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Windows.AppLifecycle.Projection.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Windows.System.Power.Projection.dll")) -and
(-not $_.Name.EndsWith("Microsoft.WindowsAppRuntime.Bootstrap.Net.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Xaml.Interactions.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Xaml.Interactivity.dll")) -and
(-not $_.Name.EndsWith("hyjiacan.py4n.dll")) -and
(-not $_.Name.EndsWith("Microsoft.WindowsAppRuntime.Release.Net.dll"))
)
{
Write-Host "Version set to 1.0.0.0: " + $_.FullName Write-Host "Version set to 1.0.0.0: " + $_.FullName
$totalFailure++; $totalFailure++;
} }
} elseif ($_.VersionInfo.FileVersion -eq $null -and $_.Name -notmatch $nullVersionExceptions) {
}
$items | ForEach-Object {
if($_.VersionInfo.FileVersion -eq $null )
{
# These items are exceptions that actually a version not set. # These items are exceptions that actually a version not set.
if ((-not $_.Name.EndsWith("codicon.ttf")) -and
(-not $_.Name.EndsWith("e_sqlite3.dll")) -and
(-not $_.Name.EndsWith("vcamp140_app.dll")) -and
(-not $_.Name.EndsWith("marshal.dll")) -and
(-not $_.Name.EndsWith("Microsoft.UI.Composition.OSSupport.dll")) -and
(-not $_.Name.EndsWith("Microsoft.UI.Xaml.Internal.dll")) -and
(-not $_.Name.EndsWith("Microsoft.Windows.ApplicationModel.Resources.dll")) -and
(-not $_.Name.EndsWith("Microsoft.WindowsAppRuntime.dll")) -and
(-not $_.Name.EndsWith("Microsoft.WindowsAppRuntime.Bootstrap.dll")) -and
(-not $_.Name.EndsWith("MRM.dll")) -and
(-not $_.Name.EndsWith("PushNotificationsLongRunningTask.ProxyStub.dll")) -and
(-not $_.Name.EndsWith("WindowsAppSdk.AppxDeploymentExtensions.Desktop.dll")) -and
(-not $_.Name.EndsWith("System.Diagnostics.EventLog.Messages.dll"))
)
{
Write-Host "Version not set: " + $_.FullName Write-Host "Version not set: " + $_.FullName
$totalFailure++; $totalFailure++;
} }
elseif ($_.VersionInfo.ProductName -contains "PowerToys" -and $_.VersionInfo.LegalCopyright -notmatch "Copyright \(C\) $((Get-Date).Year)") {
# PowerToys assemblies that aren't updated to the current year in the copyright
Write-Host "Copyright year out of date: " + $_.FullName
$totalFailure++;
} }
} else {
$items | ForEach-Object {
$auth = Get-AuthenticodeSignature $_.FullName $auth = Get-AuthenticodeSignature $_.FullName
if($auth.SignerCertificate -eq $null) if ($auth.SignerCertificate -eq $null) {
{
Write-Host "Not Signed: " + $_.FullName Write-Host "Not Signed: " + $_.FullName
$totalFailure++; $totalFailure++;
} }
} }
}
if($totalFailure -gt 0) if ($totalFailure -gt 0) {
{
exit 1 exit 1
} }