forked from docker-library/official-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
naughty-commits.sh
executable file
·98 lines (83 loc) · 2.72 KB
/
naughty-commits.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
set -Eeuo pipefail
fileSizeThresholdMB='2'
: "${BASHBREW_CACHE:=$HOME/.cache/bashbrew}"
export BASHBREW_CACHE BASHBREW_ARCH=
if [ ! -d "$BASHBREW_CACHE/git" ]; then
# initialize the "bashbrew cache"
bashbrew --arch amd64 from --uniq --apply-constraints hello-world:linux > /dev/null
fi
_git() {
git -C "$BASHBREW_CACHE/git" "$@"
}
if [ "$#" -eq 0 ]; then
set -- '--all'
fi
imgs="$(bashbrew list --repos "$@" | sort -u)"
for img in $imgs; do
IFS=$'\n'
commits=( $(
bashbrew cat --format '
{{- range $e := .Entries -}}
{{- range $a := .Architectures -}}
{{- /* force `git fetch` */ -}}
{{- $froms := $.ArchDockerFroms $a $e -}}
{{- $e.ArchGitCommit $a -}}
{{- "\n" -}}
{{- end -}}
{{- end -}}
' "$img" | sort -u
) )
unset IFS
declare -A naughtyCommits=() naughtyTopCommits=() seenCommits=()
for topCommit in "${commits[@]}"; do
IFS=$'\n'
potentiallyNaughtyGlobs=( '**.tar**' )
potentiallyNaughtyCommits=( $(_git log --diff-filter=DMT --format='format:%H' "$topCommit" -- "${potentiallyNaughtyGlobs[@]}") )
unset IFS
# bash 4.3 sucks (https://stackoverflow.com/a/7577209/433558)
[ "${#potentiallyNaughtyCommits[@]}" -gt 0 ] || continue
for commit in "${potentiallyNaughtyCommits[@]}"; do
[ -z "${seenCommits[$commit]:-}" ] || break
seenCommits[$commit]=1
IFS=$'\n'
binaryFiles=( $(
_git diff-tree --no-commit-id -r --numstat --diff-filter=DMT "$commit" -- "${potentiallyNaughtyGlobs[@]}" \
| grep '^-' \
| cut -d$'\t' -f3- \
|| :
) )
unset IFS
# bash 4.3 sucks (https://stackoverflow.com/a/7577209/433558)
[ "${#binaryFiles[@]}" -gt 0 ] || continue
naughtyReasons=()
for file in "${binaryFiles[@]}"; do
fileSize="$(_git ls-tree -r --long "$commit" -- "$file" | awk '{ print $4 }')"
fileSizeMB="$(( fileSize / 1024 / 1024 ))"
if [ "$fileSizeMB" -gt "$fileSizeThresholdMB" ]; then
naughtyReasons+=( "modified binary file (larger than ${fileSizeThresholdMB}MB): $file (${fileSizeMB}MB)" )
fi
done
if [ "${#naughtyReasons[@]}" -gt 0 ]; then
IFS=$'\n'
naughtyCommits[$commit]="${naughtyReasons[*]}"
unset IFS
naughtyTopCommits[$commit]="$topCommit"
fi
done
done
if [ "${#naughtyCommits[@]}" -gt 0 ]; then
echo " - $img:"
for naughtyCommit in "${!naughtyCommits[@]}"; do
naughtyReasons="${naughtyCommits[$naughtyCommit]}"
naughtyTopCommit="${naughtyTopCommits[$naughtyCommit]}"
if [ "$naughtyTopCommit" != "$naughtyCommit" ]; then
#commitsBetween="$(_git rev-list --count "$naughtyCommit...$naughtyTopCommit")"
naughtyCommit+=" (in history of $naughtyTopCommit)"
fi
echo " - commit $naughtyCommit:"
sed -e 's/^/ - /' <<<"$naughtyReasons"
done
echo
fi
done