From 6547c377bec01f49c51014201632388449a4d8a1 Mon Sep 17 00:00:00 2001 From: Andy Chow Date: Wed, 4 Sep 2024 19:52:57 +0800 Subject: [PATCH] Add script for testing bundle hash consistency --- .github/workflows/ci.yaml | 3 ++ authui/check-bundle-consistency.sh | 54 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 authui/check-bundle-consistency.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 02b97690be..becf575e1e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -52,6 +52,9 @@ jobs: - run: npm run build working-directory: ./authui if: ${{ !cancelled() }} + - run: ./check-bundle-consistency.sh + working-directory: ./authui + if: ${{ !cancelled() }} portal-test: if: ${{ github.repository != 'oursky/authgear-server' }} diff --git a/authui/check-bundle-consistency.sh b/authui/check-bundle-consistency.sh new file mode 100755 index 0000000000..52c16a3874 --- /dev/null +++ b/authui/check-bundle-consistency.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# This script is used to test whether the built bundles are having the same hash over several builds + +N=5 +MANIFEST_LOCATION=../resources/authgear/generated/manifest.json +TEMP_DIR=$(mktemp -d) + +if [ $N -lt 2 ]; then + echo "[ERROR] The build number must be greater than 1" + exit 1 +fi + +build_bundles() +{ + for i in $(seq 1 $N) + do + echo "[INFO] Build no.$i" + + # Clear vite cache before building bundles + rm -rf node_modules/.vite > /dev/null 2>&1 + npm run build > /dev/null 2>&1 + + python3 -m json.tool --sort-keys --no-ensure-ascii --indent 2 <$MANIFEST_LOCATION >$TEMP_DIR/$i.json + done +} + +compare_bundles() +{ + echo "[INFO] Comparing $i builds..." + + for j in $(seq 2 $N) + do + diff $TEMP_DIR/1.json $TEMP_DIR/$j.json + # Used to check the error code + V=$? + if [ $V -eq 1 ];then + echo "[ERROR] Build hashes are not identical" + exit $V + fi + done + + echo "[INFO] Everything works fine, Bye!" +} + +main() +{ + build_bundles + compare_bundles +} + +echo "[INFO] Start of script" +main +echo "[INFO] End of script"