Skip to content

Instantly share code, notes, and snippets.

@mfdj
Last active April 8, 2016 18:02
Show Gist options
  • Save mfdj/4ac0dd83e98ba479c5c8ca141481d075 to your computer and use it in GitHub Desktop.
Save mfdj/4ac0dd83e98ba479c5c8ca141481d075 to your computer and use it in GitHub Desktop.
Pre deploy client build example
#!/usr/bin/env bash
if ! command -v gulp > /dev/null; then
echo && echo "error: gulp required"
exit 1
fi
gulp build
if ! command -v md5sum > /dev/null; then
echo && echo "error: md5sum required"
exit 1
fi
# hash frontend assets to single filename
# http://stackoverflow.com/questions/1657232/how-can-i-calculate-an-md5-checksum-of-a-directory
asset_paths='web/assets'
asset_hash=`find $asset_paths -type f -exec md5sum {} + | awk '{print $1}' | sort | md5sum | awk '{print $1}' | cut -c 1-12`
archive_name=client_assets.${asset_hash}.tar.gz
# check that the archive doesn't already exsist
if [[ ! -f $archive_name ]]; then
echo "Removing old: client_assets.*.tar.gz"
git rm client_assets.*.tar.gz --ignore-unmatch
echo "Making new archive:"
echo "tar -zcvf $archive_name $asset_paths"
tar -zcvf "$archive_name" "$asset_paths"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment