Skip to content

Commit

Permalink
fix line endings for reproducible SHAs
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Feb 23, 2024
1 parent 24313bd commit b028a56
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
31 changes: 0 additions & 31 deletions .github/actions/Sha-Of-Directory.ps1

This file was deleted.

27 changes: 12 additions & 15 deletions .github/actions/sha-of-zip.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ setlocal EnableExtensions EnableDelayedExpansion

:: All paths relative to pwd -- where this script is called from
set "EXTRACTIONDIR=.\rcv\zip_extracted"
set "MODULESFILE=.\rcv\zip_extracted\rcv\lib\modules"
set "MODULESDIR=.\rcv\zip_extracted\rcv\lib\modules_extracted"
set "HASHFILE_UNSORTED=all_hashes_unsorted.txt"
set "HASHFILE_PATH_STRIPPED=all_hashes_path_stripped.txt"
set "HASHFILE_SORTED=all_hashes_sorted.txt"
Expand All @@ -21,24 +19,19 @@ if exist %HASHFILE_UNSORTED% (
del %HASHFILE_UNSORTED%
)

if exist %EXTRACTIONDIR% (
rmdir /s /q %EXTRACTIONDIR%
if exist %HASHFILE_PATH_STRIPPED% (
del %HASHFILE_PATH_STRIPPED%
)

if exist %MODULESDIR% (
rmdir /s /q %EXTRACTIONDIR%
if exist %HASHFILE_SORTED% (
del %HASHFILE_SORTED%
)

powershell -command Expand-Archive -Path %ZIP_FILEPATH% -Destination %EXTRACTIONDIR%

:: Extract modules, get the SHA-512 of it, and add it to the top of the hashfile
jimage extract --dir %MODULESDIR% %MODULESFILE%

powershell .github\actions\Sha-Of-Directory.ps1 %MODULESDIR% 512 > %HASHFILE_UNSORTED%
if exist %EXTRACTIONDIR% (
rmdir /s /q %EXTRACTIONDIR%
)

:: Delete both modules and the extracted dir
del %MODULESFILE%
rmdir /s /q %MODULESDIR%
powershell -command Expand-Archive -Path %ZIP_FILEPATH% -Destination %EXTRACTIONDIR%

:: Calculate the hash for every file here and in all subdirectories, appending to the file (format "(filename) = (hash)")
(
Expand All @@ -59,6 +52,10 @@ for /f "delims=" %%A in ('type "%HASHFILE_UNSORTED%"') do (

sort "%HASHFILE_PATH_STRIPPED%" > "%HASHFILE_SORTED%"

:: dos2unix on the file to ensure consistent SHAs
powershell -Command "& {[IO.File]::WriteAllText(\"%HASHFILE_SORTED%\", $([IO.File]::ReadAllText(\"%HASHFILE_SORTED%\") -replace \"`r`n", "`n\"))}"

:: echo the final hash
C:\Windows\System32\certutil.exe -hashfile %HASHFILE_SORTED% SHA%SHA_A% | findstr /v ":"

:: For debugging, enable printing the file-by-file hash
Expand Down
7 changes: 1 addition & 6 deletions .github/actions/sha-of-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ os=$2
sha_a=$3

parentPath=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
modulesPath="./rcv/lib/modules"

# Make a temporary directory to extract zip, and a temporary file to hold SHAs
tempDirectory=$(mktemp -d)
Expand All @@ -21,12 +20,8 @@ touch $tempAllChecksumsFile
# Extract the zip
unzip -q $zipFilepath -d $tempDirectory 2>/dev/null

# Go into the extracted directory and delete the modules file
# That file is consistent on a single machine, but differs across machines
cd $tempDirectory
rm $modulesPath

# Get a checksum for each file in the zip
cd $tempDirectory
for filename in $(find * -type f | sort); do
checksum=$($parentPath/../workflows/sha.sh $filename $os $sha_a)
echo $checksum >> $tempAllChecksumsFile
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,13 @@ jobs:
name: Package
if-no-files-found: error
path: |
${{ github.workspace }}/all_hashes_sorted.txt
${{ github.workspace }}/${{ steps.zipfn.outputs.FILEPATH }}
${{ github.workspace }}/${{ steps.zipfn.outputs.FILEPATH }}.sha512
${{ github.workspace }}/${{ steps.zipfn.outputs.FILEPATH }}.golden.sha512
${{ github.workspace }}/${{ steps.exefn.outputs.FILEPATH }}
${{ github.workspace }}/${{ steps.exefn.outputs.FILEPATH }}.sha512
${{ github.workspace }}/${{ steps.cachefn.outputs.FILEPATH }}
${{ github.workspace }}/${{ steps.cachefn.outputs.FILEPATH }}.sha512
${{ github.workspace }}/${{ steps.cachefn.outputs.FILEPATH }}.golden.sha512
${{ github.workspace }}/${{ steps.checksumsfn.outputs.FILEPATH }}
${{ github.workspace }}/${{ steps.checksumsfn.outputs.FILEPATH }}.sha512
retention-days: 1
Expand Down

0 comments on commit b028a56

Please sign in to comment.