validate-dco 1.8 KB

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