Skip to content

Commit

Permalink
try moving to actions for windows-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Feb 22, 2024
1 parent dcffe7b commit f41b698
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 16 deletions.
5 changes: 1 addition & 4 deletions .github/actions/gradle-and-sha/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ runs:
run: |
mv ${{ inputs.intermediate-filepath }} ${{ inputs.final-filepath }}
- name: "Generate SHA512. If ZIP, it will also extract to avoid timestamp-mingling."
- name: "Generate SHA512"
shell: bash
run: |
./.github/workflows/sha.sh ${{ inputs.final-filepath }} ${{ runner.os }} 512 > ${{ inputs.final-finalpath }}.sha512
if [ "${{ inputs.intermediate-filepath }}" == "*zip" ]; then
./.github/workflows/sha-of-zip.sh ${{ inputs.final-filepath }} ${{ runner.os }} 512 > ${{ inputs.final-finalpath }}.golden.sha512
fi
64 changes: 64 additions & 0 deletions .github/actions/sha-of-zip.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
:: sha-of-zip.bat
:: Windows port of sha-of-zip.sh. See that file for a description.
:: Usage: ./sha-of-zip.bat <ZIP_FILEPATH> <sha version: 1, 256, or 512>

@echo off

set ZIP_FILEPATH=%1
set SHA_A=%2

:: 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"

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%
Expand-Archive -Path %ZIP_FILEPATH% -Destination %EXTRACTIONDIR%
cd %EXTRACTIONDIR%

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

:: 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% SHA%SHA_A%

endlocal
10 changes: 0 additions & 10 deletions .github/workflows/sha-of-zip.sh → .github/actions/sha-of-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,22 @@ zipFilepath=$1
os=$2
a=$3

echo parentpath
parentPath=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )

# Make a temporary directory to extract zip, and a temporary file to hold SHAs
echo temp1
tempDirectory=$(mktemp -d)
echo temp2
tempAllChecksumsFile=$(mktemp)
echo temp3
touch $tempAllChecksumsFile

# Extract the zip
echo unzipy
unzip -q $zipFilepath -d $tempDirectory 2>/dev/null

# Get a checksum for each file in the zip
echo tempcd
cd $tempDirectory
echo foreach
for filename in $(find * -type f | sort); do
echo hcheck
checksum=$($parentPath/sha.sh $filename $os $a)
echo sum
echo $checksum >> $tempAllChecksumsFile
done

# Echo the checksum of the checksums
echo sumitall
echo $($parentPath/sha.sh $tempAllChecksumsFile $os $a)
27 changes: 27 additions & 0 deletions .github/actions/sha-of-zip/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Create SHA of a .zip file by extracting it"
description: "Cross-platform helper: checksum of checksums to be timestamp-independent"

inputs:
zipFilename:
description: "The output file name"
required: true
shaA:
description: "The sha strategy (1, 256, or 512)"
required: true

runs:
using: "composite"
steps:
- name: "Run pre-command"
shell: bash
run: ${{ inputs.command }}

- name: "Generate zip for Linux/Mac"
if: runner.os == 'Linux' || runner.os == 'MacOS'
shell: bash
run: ./.github/actions/sha-of-zip.sh ${{ inputs.zipFilename }} ${{ runner.os }} ${{ inputs.shaA }}

- name: "Generate zip for Windows"
if: runner.os == 'Windows'
shell: powershell
run: ./.github/actions/sha-of-zip.bat ${{ inputs.zipFilename }} ${{ inputs.shaA }}
2 changes: 1 addition & 1 deletion .github/actions/zip/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ runs:
shell: bash
run: ${{ inputs.command }}

- name: "Generate zip for Linux"
- name: "Generate zip for Linux/Mac"
if: runner.os == 'Linux' || runner.os == 'MacOS'
shell: bash
run: zip -r ${{inputs.zipFilename}} ${{inputs.input}}
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ jobs:
shell: bash
run: |
./.github/workflows/sha.sh ${{steps.cachefn.outputs.FILEPATH}} ${{ runner.os }} 512 > ${{steps.cachefn.outputs.FILEPATH}}.sha512
# ./.github/workflows/sha-of-zip.sh ${{steps.cachefn.outputs.FILEPATH}} ${{ runner.os }} 512 > ${{steps.cachefn.outputs.FILEPATH}}.golden.sha512
- name: "Generate Golden SHA512 for jlinkZip"
uses: ./.github/actions/sha-of-zip
with:
zipFilename: ${{ steps.zipfn.outputs.FILEPATH }}
shaA: 512

- name: "Generate Golden SHA512 for plugins cache"
uses: ./.github/actions/sha-of-zip
with:
zipFilename: ${{steps.cachefn.outputs.FILEPATH}}
shaA: 512

- name: "Prepare keychain"
if: matrix.os == 'macOS-latest'
Expand Down

0 comments on commit f41b698

Please sign in to comment.