From d8008682873995a4877e78ec247ea37afd75d50a Mon Sep 17 00:00:00 2001 From: DSR! Date: Mon, 20 May 2024 00:50:07 -0300 Subject: [PATCH] Add tools checksum gen --- .github/workflows/builder.yml | 2 +- bin/installer/bin/generate-checksums.ps1 | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml index e4275ed..9e4563f 100644 --- a/.github/workflows/builder.yml +++ b/.github/workflows/builder.yml @@ -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 diff --git a/bin/installer/bin/generate-checksums.ps1 b/bin/installer/bin/generate-checksums.ps1 index 8f37786..2926af5 100644 --- a/bin/installer/bin/generate-checksums.ps1 +++ b/bin/installer/bin/generate-checksums.ps1 @@ -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 @@ -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" }