validate-dco 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. set -e
  3. source "$(dirname "$BASH_SOURCE")/.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. elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then
  20. echo 'Congratulations! DCO small-patch-exception material!'
  21. else
  22. commits=( $(validate_log --format='format:%H%n') )
  23. badCommits=()
  24. for commit in "${commits[@]}"; do
  25. if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
  26. # no content (ie, Merge commit, etc)
  27. continue
  28. fi
  29. if ! git log -1 --format='format:%B' "$commit" | check_dco; then
  30. badCommits+=( "$commit" )
  31. fi
  32. done
  33. if [ ${#badCommits[@]} -eq 0 ]; then
  34. echo "Congratulations! All commits are properly signed with the DCO!"
  35. else
  36. {
  37. echo "These commits do not have a proper '$dcoPrefix' marker:"
  38. for commit in "${badCommits[@]}"; do
  39. echo " - $commit"
  40. done
  41. echo
  42. echo 'Please amend each commit to include a properly formatted DCO marker.'
  43. echo
  44. echo 'Visit the following URL for information about the Docker DCO:'
  45. echo ' https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work'
  46. echo
  47. } >&2
  48. false
  49. fi
  50. fi