diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5c844ec --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +#should deny +name: Verify +on: [pull_request] +jobs: + test: + runs-on: ubuntu-20.04 + steps: + - name: Prepare repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + sudo apt install -y unzip jq + + - name: Run verify script + run: | + cd scripts + bash verify.sh + if [ $? -eq 1 ]; then + exit 1 + fi diff --git a/scripts/verify.sh b/scripts/verify.sh new file mode 100755 index 0000000..a8e305e --- /dev/null +++ b/scripts/verify.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +function checkVersionAndId { + idArg=$1 + versionArg=$2 + + themeId="$(unzip -p "${idArg}.zip" theme.json | jq -r '.id')" + if [[ $idArg != "$themeId" ]]; then + echo "Theme id for $idArg does NOT match!" + exit 1 + else + echo "theme ids match" + fi + + themeVersion="$(unzip -p "${idArg}.zip" theme.json | jq -r '.version')" + if [[ "$versionArg" != "$themeVersion" ]]; then + echo "Versions for $idArg do NOT match!" + exit 1 + else + echo "versions match" + fi +} + +zip_dir="../data/themes" + +# Change to the specified zip_dir +cd "$zip_dir" || exit 1 + + +json_file="../themes.json" + +# Read the contents of the JSON file +json=$(cat "$json_file") + +# Extract the "sha256" and "id" values using jq +themes=$(echo "$json" | jq -r '.themes[] | "\(.sha256) \(.id) \(.version)"') + +# Loop through each theme and print the "sha256" and "id" values +while read -r sha256 id version; do + + file="${id}.zip" + if [[ -f "$file" ]]; then + # Calculate the SHA256 hash + sha256sum_output=$(sha256sum "$file") + sha256_hash=${sha256sum_output%% *} + + # Check if match + if [[ "$sha256" == "$sha256_hash" ]]; then + echo "Theme $file hash matches hash in themes.json" + else + echo "Theme $file hash doe NOT match hash in themes.json!" + exit 1 + fi + + # Check inside zip file + checkVersionAndId "$id" "$version" + + echo + + else + echo "Theme $file not found!" + exit 1 + fi + +done <<< "$themes" + +