Skip to content

Commit

Permalink
WIP: idempotent hash
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Oct 24, 2023
1 parent fac99e2 commit 3bf068b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/idempotent-hash.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
:: idempotent-hash.bat
@echo off

:: NOTE: This script must be placed one level up from the rcv directory

echo Initiating batch hash procedure…
echo %date% %time%

setlocal EnableExtensions EnableDelayedExpansion

set "HASHFILE=all_hashes.txt"
set "TEMPHASHFILE=all_hashes_temp.txt"
set "EXTRACTIONDIR=.\rcv\modules_extracted"
set "MODULESFILE=.\rcv\lib\modules"

if exist %HASHFILE% (
echo Deleting existing hash file, %HASHFILE% ...
del %HASHFILE%
)

if exist %EXTRACTIONDIR% (
echo Deleting existing extracted modules directory, %EXTRACTIONDIR% ...
rmdir /s /q %EXTRACTIONDIR%
)

echo Extracting contents of modules file...
mkdir %EXTRACTIONDIR%
cd %EXTRACTIONDIR%
jimage extract ..\..\%MODULESFILE%

echo Temporarily relocating modules file...
cd ..\..
copy %MODULESFILE% .
del %MODULESFILE%

:: Calculate the hash for every file here and in all subdirectories, appending to the file (format "(filename) = (hash)")
echo Calculating hashes...
for /r .\rcv %%f in (*) do (
<NUL set /p ="%%f = " >> %HASHFILE%
C:\Windows\System32\certutil.exe -hashfile "%%f" SHA512 | findstr /v ":" >> %HASHFILE%
)

echo Restoring modules file...
move .\modules %MODULESFILE%

:: Replace the absolute paths to each file with relative paths (e.g. C:\temp\rcv => .\rcv)

echo Replacing absolute paths with relative paths in hash file...
set "SEARCHTEXT=%cd%"
set "REPLACETEXT=."
for /f "delims=" %%A in ('type "%HASHFILE%"') do (
set "string=%%A"
set "modified=!string:%SEARCHTEXT%=%REPLACETEXT%!"
echo !modified!>>"%TEMPHASHFILE%"
)
del "%HASHFILE%"
rename "%TEMPHASHFILE%" "%HASHFILE%"

echo Sorting the hash file...
sort "%HASHFILE%" > "%TEMPHASHFILE%"
del "%HASHFILE%"
rename "%TEMPHASHFILE%" "%HASHFILE%"

echo Calculating the hash of the entire sorted hash file...
C:\Windows\System32\certutil.exe -hashfile %HASHFILE% SHA512

endlocal
13 changes: 9 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: "Generate Releases"

on:
release:
types: [ published ]
types: [ release ]
## To test this workflow without creating a release, uncomment the following and add a branch name (making sure "push"
## is at the same indent level as "release":
# push:
# branches:
# - 'branch-name'
push:
branches:
- 'feature/issue-759_idempotent-sha'

jobs:
release:
Expand Down Expand Up @@ -123,6 +123,11 @@ jobs:
echo "Attach staple"
xcrun stapler staple ${{ steps.exefn.outputs.FILEPATH }}
#- name: "Create idempotent hash on Windows"
# if: matrix.os == 'Windows'
# run: |
# ./idempotent_hash.bat
- uses: actions/upload-artifact@v3
with:
name: Package
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
with:
java-version: '20.0.1'
distribution: 'temurin'
- name: "Test with Gradle"
run: ./gradlew check
# - name: "Test with Gradle"
# run: ./gradlew check

0 comments on commit 3bf068b

Please sign in to comment.