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