travis.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. set -e
  3. cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. repos=( --all )
  5. extraCommands=
  6. upstreamRepo='docker-library/official-images'
  7. upstreamBranch='master'
  8. if [ "$TRAVIS_PULL_REQUEST" -a "$TRAVIS_PULL_REQUEST" != 'false' ]; then
  9. upstreamRepo="$TRAVIS_REPO_SLUG"
  10. upstreamBranch="$TRAVIS_BRANCH"
  11. fi
  12. HEAD="$(git rev-parse --verify HEAD)"
  13. git fetch -q "https://github.com/$upstreamRepo.git" "refs/heads/$upstreamBranch"
  14. UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
  15. if [ "$TRAVIS_BRANCH" = 'master' -a "$TRAVIS_PULL_REQUEST" = 'false' ]; then
  16. # if we're testing master itself, RUN ALL THE THINGS
  17. echo >&2 'Testing master -- BUILD ALL THE THINGS!'
  18. elif [ "$(git diff --numstat "$UPSTREAM...$HEAD" -- ../library | wc -l)" -ne 0 ]; then
  19. # changes in library/ -- run our extended tests regardless of bashbrew changes
  20. repos=( $(git diff --numstat "$UPSTREAM...$HEAD" -- ../library | awk -F '/' '{ print $2 }') )
  21. extraCommands=1
  22. elif [ "$(git diff --numstat "$UPSTREAM...$HEAD" -- . | wc -l)" -ne 0 ]; then
  23. # changes in bashbrew/ -- keep "--all" so we test the bashbrew script changes appropriately
  24. echo >&2 'Changes in bashbrew/ detected!'
  25. #extraCommands=1 # TODO this takes a lot of load and often fails (force pushes to maintainer branches, etc)
  26. else
  27. # no changes to library/ or bashbrew/ -- skip tests
  28. repos=()
  29. fi
  30. if [ "${#repos[@]}" -eq 0 ]; then
  31. echo >&2 'Skipping test builds: no changes to library/ or bashbrew/ in PR'
  32. exit
  33. fi
  34. export BASHBREW_LIBRARY="$(dirname "$PWD")/library"
  35. if badTags="$(bashbrew list "${repos[@]}" | grep -E ':.+latest.*|:.*latest.+')" && [ -n "$badTags" ]; then
  36. echo >&2
  37. echo >&2 "Incorrectly formatted 'latest' tags detected:"
  38. echo >&2 ' ' $badTags
  39. echo >&2
  40. echo >&2 'Read https://github.com/docker-library/official-images#tags-and-aliases for more details.'
  41. echo >&2
  42. exit 1
  43. fi
  44. if [ -n "$extraCommands" ]; then
  45. naughtyFrom="$(../naughty-from.sh "${repos[@]}")"
  46. if [ -n "$naughtyFrom" ]; then
  47. echo >&2
  48. echo >&2 "Invalid 'FROM' + 'Architectures' combinations detected:"
  49. echo >&2
  50. echo >&2 "$naughtyFrom"
  51. echo >&2
  52. echo >&2 'Read https://github.com/docker-library/official-images#multiple-architectures for more details.'
  53. echo >&2
  54. exit 1
  55. fi
  56. naughtyConstraints="$(../naughty-constraints.sh "${repos[@]}")"
  57. if [ -n "$naughtyConstraints" ]; then
  58. echo >&2
  59. echo >&2 "Invalid 'FROM' + 'Constraints' combinations detected:"
  60. echo >&2
  61. echo >&2 "$naughtyConstraints"
  62. echo >&2
  63. exit 1
  64. fi
  65. naughtyCommits="$(../naughty-commits.sh "${repos[@]}")"
  66. if [ -n "$naughtyCommits" ]; then
  67. echo >&2
  68. echo >&2 "Unpleasant commits detected:"
  69. echo >&2
  70. echo >&2 "$naughtyCommits"
  71. echo >&2
  72. exit 1
  73. fi
  74. fi
  75. _bashbrew() {
  76. echo $'\n\n$ bashbrew' "$@" "${repos[@]}"
  77. bashbrew "$@" "${repos[@]}"
  78. }
  79. _bashbrew list
  80. _bashbrew list --uniq
  81. _bashbrew cat
  82. if [ -n "$extraCommands" ]; then
  83. _bashbrew list --build-order
  84. _bashbrew from
  85. fi
  86. echo; echo