Created
April 9, 2019 20:18
-
-
Save westonruter/542bb89ca3a1f347731bad248a275298 to your computer and use it in GitHub Desktop.
Warning: this will reset all widgets on the site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check the savings of the AMP plugin's CSS tree shaker across the core themes between two git commits. | |
# WARNING: This will reset your widgets! | |
set -e | |
before_head=$1 | |
after_head=$2 | |
if [[ -z "$before_head" ]] || [[ -z "$after_head" ]]; then | |
echo "First argument needs to be the before HEAD, and second argument must be the after HEAD." | |
exit 1 | |
fi | |
echo "Warning: This will reset all your widgets! You have 3 seconds to cancel." | |
sleep 3 | |
url=$3 | |
if [[ -z "$url" ]]; then | |
echo "Using home URL for test." | |
url="$(wp option get home)/?amp" | |
fi | |
function curl_grep_included_size { | |
curl -s "$url" > /tmp/response | |
if grep -s 'Total excluded size' /tmp/response >/dev/null; then | |
echo '-1' | |
else | |
cat /tmp/response | grep 'Total included size' | sed 's/.*: //' | sed 's/ bytes.*//' | sed 's/,//' | |
fi | |
} | |
echo "theme | before | after | diff | savings" > results.txt; | |
echo "------|--------|-------|------|--------" >> results.txt; | |
wp transient delete --all | |
for theme in $(wp theme list --field=name | egrep 'twenty' | grep -v '-'); do | |
wp theme activate "$theme" | |
wp widget reset --all # For consistency. | |
git checkout "$before_head" | |
before_bytes=$(curl_grep_included_size) | |
git checkout "$after_head" | |
after_bytes=$(curl_grep_included_size) | |
reduction_bytes=$(expr "$after_bytes" - "$before_bytes") | |
reduction_percentage=$(php -r "printf( '%.2f%%', -( 1 - \$argv[1] / \$argv[2] ) * 100 );" "$after_bytes" "$before_bytes" ) | |
echo -e "$theme | $before_bytes | $after_bytes | $reduction_bytes | $reduction_percentage" >> results.txt | |
done | |
cat results.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment