Last active
December 28, 2020 12:25
-
-
Save sjml/e0d99474b9869490cd5ccf464cd656c5 to your computer and use it in GitHub Desktop.
Compare hugo output across versions
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
#!/usr/bin/env bash | |
# Compares the output directory for two versions of Hugo (https://gohugo.io), so you | |
# can know how updating to a new version will affect your content generation. | |
# exit on error | |
set -e | |
# the current Hugo project that I care about testing | |
REPO="$HUGO_REPO" | |
# only works for 64-bit Mac, but you can see how easy it would be to swap | |
MAC_SUFFIX="_macOS-64bit.tar.gz" | |
REL_PATTERN="https://github.com/gohugoio/hugo/releases/download/v%s/hugo_extended_%s%s" | |
if [[ $# -lt 2 ]]; then | |
echo "Determining versions to check..." | |
CURRENT_VERSION=$(hugo version | sed -n -E "s/^Hugo Static Site Generator v([^\/]*).*$/\1/p") | |
BREW_VERSION=$(brew info hugo | grep "hugo: stable" | sed -n -E "s/hugo: stable ([^[:space:]]*).*$/\1/p") | |
BUILD_A=$CURRENT_VERSION | |
BUILD_B=$BREW_VERSION | |
else | |
BUILD_A=$1 | |
BUILD_B=$2 | |
fi | |
if [ $BUILD_A = $BUILD_B ]; then | |
echo "Comparing $BUILD_A to itself? Nah." | |
exit 1 | |
fi | |
# download A | |
mkdir -p $(printf "hugo_%s" $BUILD_A) | |
URL_A=$(printf $REL_PATTERN $BUILD_A $BUILD_A $MAC_SUFFIX) | |
DL_TARGET_A=$(printf "hugo_%s/%s%s" $BUILD_A $BUILD_A $MAC_SUFFIX) | |
echo "Downloading $BUILD_A..." | |
wget -q $URL_A -O $DL_TARGET_A | |
# download B | |
mkdir -p $(printf "hugo_%s" $BUILD_B) | |
URL_B=$(printf $REL_PATTERN $BUILD_B $BUILD_B $MAC_SUFFIX) | |
DL_TARGET_B=$(printf "hugo_%s/%s%s" $BUILD_B $BUILD_B $MAC_SUFFIX) | |
echo "Downloading $BUILD_B..." | |
wget -q $URL_B -O $DL_TARGET_B | |
# clean pull of the repo | |
echo "Cloning repository..." | |
if [ -d "content_repo" ]; then | |
rm -rf "content_repo" | |
fi | |
git clone $REPO content_repo --quiet | |
# expand the downloads | |
tar -xzf $DL_TARGET_A -C hugo_$BUILD_A | |
tar -xzf $DL_TARGET_B -C hugo_$BUILD_B | |
# build public site with each | |
echo "Building sites..." | |
hugo_$BUILD_A/hugo --quiet -s content_repo -d ../public_$BUILD_A | |
hugo_$BUILD_B/hugo --quiet -s content_repo -d ../public_$BUILD_B | |
echo "Running comparison..." | |
set +e | |
echo "------- DIFFERENCES" | |
git diff ./public_$BUILD_A ./public_$BUILD_B | |
echo "------- /DIFFERENCES" | |
set -e | |
echo "Cleaning up..." | |
rm -rf content_repo | |
rm -rf hugo_$BUILD_A | |
rm -rf hugo_$BUILD_B | |
rm -rf public_$BUILD_A | |
rm -rf public_$BUILD_B | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment