forked from docker-library/official-images
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-pr.sh
executable file
·102 lines (89 loc) · 2.49 KB
/
test-pr.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
99
100
101
102
#!/bin/bash
set -eo pipefail
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
usage() {
cat <<-EOUSAGE
usage: $0 [PR number] [repo[:tag]]
ie: $0 1024
$0 9001 debian php django
$0 0 hylang # special case that runs against local directory
This script builds and tests the specified pull request to official-images and
provides ouput in markdown for commenting on the pull request.
EOUSAGE
}
pull="$1"
shift || { usage >&2 && exit 1; }
if [ -z "$BASHBREW_SECOND_STAGE" ]; then
docker build --pull -t bashbrew "$dir" > /dev/null
if [ "$pull" = '0' ]; then
name="bashbrew-test-local-$RANDOM"
else
name="bashbrew-test-pr-$pull"
fi
exec docker run \
-it --rm \
--name "$name" \
-e BASHBREW_SECOND_STAGE=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /usr/src/pr \
bashbrew /usr/src/official-images/test-pr.sh "$pull" "$@"
fi
if [ -d .git ]; then
echo >&2 'error: something has gone horribly wrong; .git already exists'
echo >&2 ' why do you have BASHBREW_SECOND_STAGE set?'
exit 1
fi
if [ "$pull" = '0' ]; then
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
commit='FAKE'
else
# TODO we only have "git version 2.4.1" which doesn't support "clone -q" :(
git init -q .
git remote add origin https://github.com/docker-library/official-images.git
git fetch -q origin
git reset -q --hard origin/master
git config user.name 'nobody'
git config user.email '[email protected]'
git fetch -q origin "pull/$pull/head:pr-$pull"
git merge -q --no-edit "pr-$pull"
commit="$(git log -1 --format=format:%h "pr-$pull")"
fi
if [ "$#" -eq 0 ]; then
IFS=$'\n'
files=( $(git diff --name-only origin/master...HEAD -- library | xargs -n1 basename) )
unset IFS
# TODO narrow this down into groups of the exact tags for each image that changed >:)
else
files=( "$@" )
fi
if [ ${#files[@]} -eq 0 ]; then
echo >&2 'no files in library/ changed in PR #'"$pull"
exit 0
fi
join() {
sep="$1"
arg1="$2"
shift 2
echo -n "$arg1"
[ $# -gt 0 ] && printf "${sep}%s" "$@"
}
echo 'Build test of' '#'"$pull"';' "$commit" '(`'"$(join '`, `' "${files[@]}")"'`):'
failed=
for img in "${files[@]}"; do
echo
echo '```console'
echo '$ bashbrew build "'"$img"'"'
if ./bashbrew/bashbrew.sh build "$img"; then
echo '$ bashbrew list --uniq "$url" | xargs test/run.sh'
if ! ./bashbrew/bashbrew.sh list --uniq "$img" | xargs ./test/run.sh; then
failed=1
fi
else
failed=1
fi
echo '```'
done
if [ "$failed" ]; then
echo
echo 'There is at least one failure in the above build log.'
fi