Created
December 24, 2024 21:49
-
-
Save johanvdw/ea201a3b4cf81a8e711f81946a0d38c6 to your computer and use it in GitHub Desktop.
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 | |
set -e | |
# originally based on https://stackoverflow.com/a/10847242/545346 | |
# CC-BY-SA 3.0 | |
if [ ! -z "${DRONE_NETRC_FILE}" ]; then | |
echo $DRONE_NETRC_FILE > $HOME/.netrc | |
chmod 600 $HOME/.netrc | |
fi | |
git fetch --tags | |
max_size=${PLUGIN_MAX_SIZE:-1048576} | |
old=origin/$DRONE_REPO_BRANCH | |
new='HEAD' | |
echo "Comparing HEAD to $old" | |
args=$(git rev-parse --sq $old $new) | |
eval "git diff-tree -r $args" | { | |
total=0 | |
while read A B C D M P | |
do | |
case $M in | |
M) bytes=$(( $(git cat-file -s $D) - $(git cat-file -s $C) )) ;; | |
A) bytes=$(git cat-file -s $D) ;; | |
D) bytes=-$(git cat-file -s $C) ;; | |
*) | |
echo >&2 warning: unhandled mode $M in \"$A $B $C $D $M $P\" | |
continue | |
;; | |
esac | |
total=$(( $total + $bytes )) | |
printf '%d\t%s\n' $bytes "$P" | |
done | |
echo total $total bytes added in this branch/pr | |
if [ "$total" -gt "$max_size" ]; then | |
echo "Size difference between $new and $old larger than $max_size bytes: Failing" | |
echo "Make sure you are not adding large (binary) files to the repo; Check with IT for more info." | |
exit $total | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment