1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/hack/travis/gofmt.py
Tianon Gravi 561d1db074 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)
2014-01-07 08:25:54 -07:00

28 lines
616 B
Python
Executable file

#!/usr/bin/env python
import subprocess
from env import commit_range
files = subprocess.check_output([
'git', 'diff', '--diff-filter=ACMR',
'--name-only', '...'.join(commit_range), '--',
])
exit_status = 0
for filename in files.split('\n'):
if filename.endswith('.go'):
try:
out = subprocess.check_output(['gofmt', '-s', '-l', filename])
if out != '':
print out,
exit_status = 1
except subprocess.CalledProcessError:
exit_status = 1
if exit_status != 0:
print 'Reformat the files listed above with "gofmt -s -w" and try again.'
exit(exit_status)
print 'All files pass gofmt.'
exit(0)