-
Notifications
You must be signed in to change notification settings - Fork 6
(GH-30) Add ability to compare meta information of found binaries #35
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#Requires -Modules chocolatey-diff | ||
|
||
Describe "Get-PackageBinaryData tests" { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function Get-PackageBinaryData { | ||
<# | ||
.SYNOPSIS | ||
The meta information about binaries included in package | ||
.DESCRIPTION | ||
The meta information about binaries included in the package, including | ||
the relative path, the checksum of the file, the embedded file and product | ||
version as well as the embedded company name. | ||
.OUTPUTS | ||
An array of hashtables with the basic information about each binary file. | ||
.EXAMPLE | ||
PS > Get-PackageBinaryData -packageDirectory path\to\package\dir | ||
#> | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string]$packageDirectory, | ||
[ValidateSet('sha1', 'sha256', 'sha512')] | ||
[string]$hashAlgorithm = 'sha256' | ||
) | ||
|
||
Push-Location $packageDirectory | Out-Null | ||
|
||
try { | ||
Write-Verbose "Finding binary files in '$packageDirectory..." | ||
$binaryFiles = Get-ChildItem -Path $packageDirectory -Recurse -File | ? { Test-IsBinary -Path $_.FullName } | ||
|
||
foreach ($file in $binaryFiles) { | ||
Write-Verbose "Aquiring binary data from $($file.Name)..." | ||
|
||
$item = Get-Item $file.FullName | ||
$result = @{ | ||
path = Resolve-Path $file.FullName -Relative | ||
checksum = Get-FileHash $file.FullName -Algorithm $hashAlgorithm | % Hash | ||
fileVersion = $item.VersionInfo.FileVersion | ||
productVersion = $item.VersionInfo.ProductVersion | ||
CompanyName = $item.VersionInfo.CompanyName | ||
} | ||
$result | ||
} | ||
} finally { | ||
|
||
Pop-Location | Out-Null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,29 +48,29 @@ | |
Get-ChocolateyPackageDiff -packageName chocolatey -oldPackageVersion 0.10.14 -newPackageVersion 0.10.15 | ||
|
||
#> | ||
[cmdletbinding(DefaultParameterSetName='Default')] | ||
[cmdletbinding(DefaultParameterSetName = 'Default')] | ||
param( | ||
[parameter(Mandatory = $true, Position = 0, ParameterSetName='Default')] | ||
[parameter(Mandatory = $true, Position = 0, ParameterSetName='DiffTool')] | ||
[string] $packageName, | ||
[parameter(Mandatory = $false, Position = 1, ParameterSetName='Default')] | ||
[parameter(Mandatory = $false, Position = 1, ParameterSetName='DiffTool')] | ||
[string] $oldPackageVersion, | ||
[parameter(Mandatory = $false, Position = 2, ParameterSetName='Default')] | ||
[parameter(Mandatory = $false, Position = 2, ParameterSetName='DiffTool')] | ||
[string] $newPackageVersion, | ||
[parameter(Mandatory = $false, ParameterSetName='Default')] | ||
[parameter(Mandatory = $false, ParameterSetName='DiffTool')] | ||
[string] $downloadLocation = $(Get-TempPath), | ||
[parameter(Mandatory = $false, ParameterSetName='Default')] | ||
[parameter(Mandatory = $false, ParameterSetName='DiffTool')] | ||
[switch] $keepFiles = $false, | ||
[parameter(Mandatory = $false, ParameterSetName='Default')] | ||
[switch] $ignoreExpectedChanges = $false, | ||
[parameter(Mandatory = $false, ParameterSetName='DiffTool')] | ||
[switch] $compareFolder = $false, | ||
[parameter(Mandatory = $false, ParameterSetName='DiffTool')] | ||
[switch] $useDiffTool = $false | ||
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'Default')] | ||
[parameter(Mandatory = $true, Position = 0, ParameterSetName = 'DiffTool')] | ||
[string] $packageName, | ||
[parameter(Mandatory = $false, Position = 1, ParameterSetName = 'Default')] | ||
[parameter(Mandatory = $false, Position = 1, ParameterSetName = 'DiffTool')] | ||
[string] $oldPackageVersion, | ||
[parameter(Mandatory = $false, Position = 2, ParameterSetName = 'Default')] | ||
[parameter(Mandatory = $false, Position = 2, ParameterSetName = 'DiffTool')] | ||
[string] $newPackageVersion, | ||
[parameter(Mandatory = $false, ParameterSetName = 'Default')] | ||
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')] | ||
[string] $downloadLocation = $(Get-TempPath), | ||
[parameter(Mandatory = $false, ParameterSetName = 'Default')] | ||
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')] | ||
[switch] $keepFiles = $false, | ||
[parameter(Mandatory = $false, ParameterSetName = 'Default')] | ||
[switch] $ignoreExpectedChanges = $false, | ||
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')] | ||
[switch] $compareFolder = $false, | ||
[parameter(Mandatory = $false, ParameterSetName = 'DiffTool')] | ||
[switch] $useDiffTool = $false | ||
) | ||
$currentProgressPreference = $ProgressPreference | ||
$ProgressPreference = 'SilentlyContinue' | ||
|
@@ -107,6 +107,19 @@ | |
Expand-Archive -Path $oldFileName -DestinationPath $oldExtractPath -Force | ||
Expand-Archive -Path $newFileName -DestinationPath $newExtractPath -Force | ||
|
||
foreach ($path in @($oldExtractPath; $newExtractPath)) { | ||
# Temporary workaround until mocking and unit tests | ||
# are figured out. | ||
if (!(Test-Path $path)) { continue; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this there? What is the use of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember right now, I have had this code in a stash for quite some time. The comment was also more a reminder to myself to figure out why the unit test was failing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Pester tests mock the folder and should not actually go out on the internet to download an actual package. I guess it's due to that. You'll do need to make actual Pester tests. |
||
|
||
$metaDestination = Join-Path $path "binary-data.txt" | ||
if (Test-Path $metaDestination) { | ||
Remove-Item $metaDestination | ||
} | ||
|
||
Get-PackageBinaryData -packageDirectory $path | Out-File -Encoding utf8 -FilePath $metaDestination | ||
} | ||
|
||
if ($compareFolder) { | ||
# We need to remove files that should not be compared | ||
$fullIgnoreList = $ignoreList | ForEach-Object { Join-Path $oldExtractPath $_ } | ||
|
Uh oh!
There was an error while loading. Please reload this page.