forked from docker-library/official-images
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request docker-library#1129 from infosiftr/test-pr-script
Add script for building and testing PRs
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
set -eo pipefail | ||
|
||
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" | ||
|
||
usage() { | ||
cat <<-EOUSAGE | ||
usage: $0 [PR number] [repo[:tag]] | ||
ie: $0 1024 | ||
$0 9001 debian php django | ||
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; } | ||
|
||
url="https://github.com/docker-library/official-images/pull/$pull.patch" | ||
pat="$(curl -fsSL --compressed "$url")" | ||
commit="$(echo "$pat" | grep -E '^From [0-9a-f]+ ' | tail -n1 | cut -d' ' -f2)" | ||
|
||
if [ "$#" -eq 0 ]; then | ||
IFS=$'\n' | ||
files=( $(echo "$pat" | awk -F '/' '$1 == "+++ b" && $2 == "library" { print $3 }' | sort -u) ) | ||
unset IFS | ||
else | ||
files=( "$@" ) | ||
fi | ||
|
||
if [ ${#files[@]} -eq 0 ]; then | ||
echo >&2 'no files in library/ changed in PR #'"$pull" | ||
exit 0 | ||
fi | ||
|
||
urls=() | ||
for f in "${files[@]}"; do | ||
urls+=( "https://raw.githubusercontent.com/docker-library/official-images/$commit/library/$f" ) | ||
done | ||
|
||
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 url in "${urls[@]}"; do | ||
echo | ||
echo '```console' | ||
echo '$ url="'"$url"'"' | ||
echo '$ bashbrew build "$url"' | ||
if ./bashbrew/bashbrew.sh build "$url"; then | ||
echo '$ bashbrew list --uniq "$url" | xargs test/run.sh' | ||
if ! ./bashbrew/bashbrew.sh list --uniq "$url" | 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 |