Skip to content

Commit

Permalink
Add script for testing bundle hash consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
andychow326 committed Sep 5, 2024
1 parent e7f99e6 commit 6547c37
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
54 changes: 54 additions & 0 deletions authui/check-bundle-consistency.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 6547c37

Please sign in to comment.