github.com/duglin/docker@v1.13.1/hack/validate/dco (about)

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