dco 1.7 KB

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