Skip to content

Commit

Permalink
Add tools checksum gen
Browse files Browse the repository at this point in the history
  • Loading branch information
xchwarze committed May 20, 2024
1 parent 05b996f commit d800868
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
.\generate-checksums.ps1 -Directory "${{ env.SRC_PATH }}/toolkit" -OutputFile "${{ github.workspace }}/tools_checksums.txt"
.\generate-checksums.ps1 -Directory "${{ github.workspace }}" -FilePattern "*.exe" -OutputFile "${{ github.workspace }}/installer_checksums.txt"
.\generate-checksums.ps1 -Directory "${{ github.workspace }}" -FilePattern "*.exe" -NoRecurse -OutputFile "${{ github.workspace }}/installer_checksums.txt"
- name: Upload Setup as Artifact
uses: actions/upload-artifact@v4
Expand Down
23 changes: 19 additions & 4 deletions bin/installer/bin/generate-checksums.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
param (
[string]$Directory = ".",
[Parameter(Mandatory = $true)]
[string]$Directory,
[string]$OutputFile = "checksums.txt",
[string]$FilePattern = "*"
[string]$FilePattern = "*",
[switch]$NoRecurse
)

# Initialize an array to store the hash results
Expand All @@ -21,13 +23,26 @@ function Get-FileHashSHA256 {
return [BitConverter]::ToString($hash) -replace "-", ""
}

# Verify that the Directory parameter is provided
if (-not $Directory) {
Write-Error "The 'Directory' parameter is mandatory."
exit 1
}

# Get the full path of the directory
$fullDirectoryPath = (Get-Item -Path $Directory).FullName

# Determine if recursion is enabled
if ($NoRecurse) {
$searchOption = [System.IO.SearchOption]::TopDirectoryOnly
} else {
$searchOption = [System.IO.SearchOption]::AllDirectories
}

# Iterate over each file in the directory matching the pattern
Get-ChildItem -Path $Directory -Filter $FilePattern -File -Recurse | ForEach-Object {
Get-ChildItem -Path $Directory -Filter $FilePattern -File -Recurse:$searchOption | ForEach-Object {
$fileHash = Get-FileHashSHA256 -filePath $_.FullName
$relativePath = $_.FullName.Substring($fullDirectoryPath.Length).TrimStart('\')
$relativePath = $_.FullName.Substring($fullDirectoryPath.Length + 1).TrimStart('\')
$hashResults += "$fileHash .\$relativePath"
}

Expand Down

0 comments on commit d800868

Please sign in to comment.