validate-dco 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. source "${MAKEDIR}/.validate"
  3. adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
  4. dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
  5. #notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')"
  6. : ${adds:=0}
  7. : ${dels:=0}
  8. # "Username may only contain alphanumeric characters or dashes and cannot begin with a dash"
  9. githubUsernameRegex='[a-zA-Z0-9][a-zA-Z0-9-]+'
  10. # https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
  11. dcoPrefix='Signed-off-by:'
  12. dcoRegex="^(Docker-DCO-1.1-)?$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: ($githubUsernameRegex)\\))?$"
  13. check_dco() {
  14. grep -qE "$dcoRegex"
  15. }
  16. if [ $adds -eq 0 -a $dels -eq 0 ]; then
  17. echo '0 adds, 0 deletions; nothing to validate! :)'
  18. else
  19. commits=( $(validate_log --format='format:%H%n') )
  20. badCommits=()
  21. for commit in "${commits[@]}"; do
  22. if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
  23. # no content (ie, Merge commit, etc)
  24. continue
  25. fi
  26. if ! git log -1 --format='format:%B' "$commit" | check_dco; then
  27. badCommits+=( "$commit" )
  28. fi
  29. done
  30. if [ ${#badCommits[@]} -eq 0 ]; then
  31. echo "Congratulations! All commits are properly signed with the DCO!"
  32. else
  33. {
  34. echo "These commits do not have a proper '$dcoPrefix' marker:"
  35. for commit in "${badCommits[@]}"; do
  36. echo " - $commit"
  37. done
  38. echo
  39. echo 'Please amend each commit to include a properly formatted DCO marker.'
  40. echo
  41. echo 'Visit the following URL for information about the Docker DCO:'
  42. echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work'
  43. echo
  44. } >&2
  45. false
  46. fi
  47. fi