Skip to content

Commit

Permalink
Added script for checking the file sizes of changed/added files to be…
Browse files Browse the repository at this point in the history
… checked during the completion of the merge request before merging into master.dev
  • Loading branch information
scopplestone committed Jan 11, 2022
1 parent 652aaa5 commit a8ff5b8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitlab/merge_request_templates/Bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Closes #number
## Merge Request Checklist

* [ ] Style Guide
* [ ] Maximum of 10 compile warnings via *./tools/test_max_warnings.sh*
* [ ] Maximum of 10 compile warnings via *./tools/test_max_warnings.sh*
* [ ] No large files via *./tools/test_max_file_size.sh*. What is the largest file?
1 change: 1 addition & 0 deletions .gitlab/merge_request_templates/Feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Closes #number

* [ ] Style Guide
* [ ] Maximum of 10 compile warnings via *./tools/test_max_warnings.sh*. How many warning were found?
* [ ] No large files via *./tools/test_max_file_size.sh*. What is the largest file?
* [ ] Descriptions for new/changed routines
* [ ] Short header description (do not just spell out the name of the subroutine, units for important variables if applicable)
* [ ] Workflow
Expand Down
48 changes: 48 additions & 0 deletions tools/test_max_file_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Script for checking the file size of every changed/added/removed file compared with master.dev branch
# Depending on the file size, different colours indicate if the added files are too large

if test -t 1; then # if terminal
NbrOfColors=$(which tput > /dev/null && tput colors) # supports color
if test -n "$NbrOfColors" && test $NbrOfColors -ge 8; then
NC="$(tput sgr0)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
fi
fi

# Get all changed files
CHANGED=$(git diff --name-only master.dev)

# Check if any changes are present
if [[ -n $CHANGED ]]; then
# Sort found files by size (-S) in reverse ordering (-r)
SORTED=$(ls -Shsr $CHANGED)
# Loop over all changes
for file in $SORTED; do
# Check if path is a file that exists
if [[ -f $file ]]; then
# -b, --bytes equivalent to '--apparent-size --block-size=1'
LINE=$(du -h $file)
FILESIZE=$(du -b $file | cut -d ' ' -f1) # this is a tab, not a white space
if [[ $FILESIZE -gt 1000000 ]]; then
printf "${RED}$LINE${NC}\n"
else
if [[ $FILESIZE -gt 100000 ]]; then
printf "${YELLOW}$LINE${NC}\n"
else
printf "${GREEN}$LINE${NC}\n"
fi
fi
fi
done
echo ""
FILESIZE=$(du -h $file | cut -d ' ' -f1) # this is a tab, not a white space
printf "The largest file is [$FILESIZE]\n"
else
echo "no changes to master.dev found. Exit."
fi


0 comments on commit a8ff5b8

Please sign in to comment.