Files
docker-cli/components/engine/hack/travis/dco.py
Tianon Gravi 8d4b73a932 Add Travis CI configuration to validate DCO and gofmt
After each push, Travis CI will trigger, and check two things:

- make sure that each commit in the push has the Docker certificate of origin
- make sure that all .go files changed by this sequence of commits are correctly formatted in the most recent commit

Note: there is one edge case; if you do a git force push, we cannot figure out the actual commits in the force push, and we will just run the checks as if upstream master were the base. Pull requests will always be tested correctly, though.

Docker-DCO-1.0-Signed-off-by: Andrew Page <admwiggin@gmail.com> (github: tianon)
Upstream-commit: 561d1db074edd4e7e7d8b02401abd3fc11b9d51c
Component: engine
2014-01-07 08:25:54 -07:00

42 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python
import re
import subprocess
import yaml
from env import commit_range
commit_format = '-%n hash: %h%n author: %aN <%aE>%n message: |%n%w(0,2,2)%B'
gitlog = subprocess.check_output([
'git', 'log', '--reverse',
'--format=format:'+commit_format,
'..'.join(commit_range), '--',
])
commits = yaml.load(gitlog)
if not commits:
exit(0) # what? how can we have no commits?
DCO = 'Docker-DCO-1.0-Signed-off-by:'
p = re.compile(r'^{0} ([^<]+) <([^<>@]+@[^<>]+)> \(github: (\S+)\)$'.format(re.escape(DCO)), re.MULTILINE|re.UNICODE)
failed_commits = 0
for commit in commits:
m = p.search(commit['message'])
if not m:
print 'Commit {1} does not have a properly formatted "{0}" marker.'.format(DCO, commit['hash'])
failed_commits += 1
continue # print ALL the commits that don't have a proper DCO
(name, email, github) = m.groups()
# TODO verify that "github" is the person who actually made this commit via the GitHub API
if failed_commits > 0:
exit(failed_commits)
print 'All commits have a valid "{0}" marker.'.format(DCO)
exit(0)