2016-05-09 12:41:01 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2016-05-10 12:16:33 +00:00
|
|
|
import argparse
|
2016-05-30 17:59:45 +00:00
|
|
|
import glob
|
2016-05-09 12:41:01 +00:00
|
|
|
import os
|
2016-06-18 20:46:41 +00:00
|
|
|
import platform
|
2016-05-30 17:59:45 +00:00
|
|
|
import shutil
|
2016-05-09 12:41:01 +00:00
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
2016-05-09 12:49:38 +00:00
|
|
|
from subprocess import check_call, check_output
|
2016-05-09 12:41:01 +00:00
|
|
|
|
|
|
|
|
2016-06-18 20:46:41 +00:00
|
|
|
_WINDOWS = platform.system().lower() == 'windows'
|
2016-05-30 13:51:12 +00:00
|
|
|
_PACKAGE_NAME = os.environ.get(
|
2016-05-22 21:42:23 +00:00
|
|
|
'CLI_PACKAGE_NAME', 'github.com/urfave/cli'
|
2016-05-09 12:41:01 +00:00
|
|
|
)
|
2016-05-30 13:51:12 +00:00
|
|
|
_TARGETS = {}
|
2016-05-09 12:41:01 +00:00
|
|
|
|
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
def main(sysargs=sys.argv[:]):
|
2016-05-10 12:16:33 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
2016-05-30 13:53:47 +00:00
|
|
|
'target', nargs='?', choices=tuple(_TARGETS.keys()), default='test'
|
2016-05-10 12:16:33 +00:00
|
|
|
)
|
|
|
|
args = parser.parse_args(sysargs[1:])
|
2016-05-09 12:49:38 +00:00
|
|
|
|
2016-05-30 13:53:47 +00:00
|
|
|
_TARGETS[args.target]()
|
2016-05-09 12:58:20 +00:00
|
|
|
return 0
|
2016-05-09 12:49:38 +00:00
|
|
|
|
|
|
|
|
2016-05-30 13:51:12 +00:00
|
|
|
def _target(func):
|
|
|
|
_TARGETS[func.__name__.strip('_')] = func
|
|
|
|
return func
|
|
|
|
|
|
|
|
|
|
|
|
@_target
|
2016-05-09 12:58:20 +00:00
|
|
|
def _test():
|
|
|
|
if check_output('go version'.split()).split()[2] < 'go1.2':
|
2016-06-23 04:56:44 +00:00
|
|
|
_run('go test -v .')
|
2016-05-09 12:58:20 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
coverprofiles = []
|
|
|
|
for subpackage in ['', 'altsrc']:
|
|
|
|
coverprofile = 'cli.coverprofile'
|
|
|
|
if subpackage != '':
|
|
|
|
coverprofile = '{}.coverprofile'.format(subpackage)
|
|
|
|
|
|
|
|
coverprofiles.append(coverprofile)
|
|
|
|
|
|
|
|
_run('go test -v'.split() + [
|
|
|
|
'-coverprofile={}'.format(coverprofile),
|
2016-05-30 13:51:12 +00:00
|
|
|
('{}/{}'.format(_PACKAGE_NAME, subpackage)).rstrip('/')
|
2016-05-09 12:58:20 +00:00
|
|
|
])
|
|
|
|
|
2016-05-22 23:44:21 +00:00
|
|
|
combined_name = _combine_coverprofiles(coverprofiles)
|
2016-06-23 04:56:44 +00:00
|
|
|
_run('go tool cover -func={}'.format(combined_name))
|
2016-05-22 23:44:21 +00:00
|
|
|
os.remove(combined_name)
|
2016-05-09 12:41:01 +00:00
|
|
|
|
2016-05-09 12:58:20 +00:00
|
|
|
|
2016-05-30 13:51:12 +00:00
|
|
|
@_target
|
2016-07-16 13:12:42 +00:00
|
|
|
def _gfmrun():
|
|
|
|
_run(['gfmrun', '-c', str(_gfmrun_count()), '-s', 'README.md'])
|
2016-05-09 12:58:20 +00:00
|
|
|
|
|
|
|
|
2016-05-30 13:51:12 +00:00
|
|
|
@_target
|
2016-05-09 12:58:20 +00:00
|
|
|
def _vet():
|
2016-06-23 04:56:44 +00:00
|
|
|
_run('go vet ./...')
|
2016-05-09 12:41:01 +00:00
|
|
|
|
|
|
|
|
2016-05-30 17:59:45 +00:00
|
|
|
@_target
|
|
|
|
def _migrations():
|
|
|
|
migration_script = os.path.abspath(
|
|
|
|
os.environ.get('V1TOV2', './cli-v1-to-v2')
|
|
|
|
)
|
|
|
|
v1_readme_url = os.environ.get(
|
|
|
|
'V1README',
|
|
|
|
'https://raw.githubusercontent.com/urfave/cli/v1/README.md'
|
|
|
|
)
|
|
|
|
|
|
|
|
tmpdir = tempfile.mkdtemp()
|
|
|
|
try:
|
|
|
|
os.chdir(tmpdir)
|
|
|
|
_run('curl -sSL -o README.md {}'.format(v1_readme_url).split())
|
2016-07-16 16:24:16 +00:00
|
|
|
_run('gfmrun extract -o .'.split())
|
2016-05-30 17:59:45 +00:00
|
|
|
|
|
|
|
for gofile in glob.glob('*.go'):
|
|
|
|
for i in (0, 1):
|
|
|
|
_run(['python', migration_script, '-w', gofile])
|
|
|
|
_run('go build -o tmp.out {}'.format(gofile).split())
|
|
|
|
finally:
|
2016-05-30 19:15:49 +00:00
|
|
|
if os.environ.get('NOCLEAN', '') == '':
|
|
|
|
shutil.rmtree(tmpdir, ignore_errors=True)
|
2016-05-30 17:59:45 +00:00
|
|
|
|
|
|
|
|
2016-06-17 13:11:36 +00:00
|
|
|
@_target
|
2016-06-16 15:47:19 +00:00
|
|
|
def _toc():
|
2016-06-18 20:46:41 +00:00
|
|
|
exe = ['bash'] if _WINDOWS else []
|
|
|
|
_run(exe + [
|
|
|
|
os.path.join('node_modules', '.bin', 'markdown-toc'),
|
2016-06-18 20:37:11 +00:00
|
|
|
'-i', 'README.md'
|
|
|
|
])
|
2016-07-10 16:26:09 +00:00
|
|
|
_run('git diff --exit-code')
|
2016-06-23 04:56:44 +00:00
|
|
|
|
|
|
|
|
2016-07-14 21:50:16 +00:00
|
|
|
@_target
|
2016-06-23 04:56:44 +00:00
|
|
|
def _gen():
|
2016-06-23 05:08:19 +00:00
|
|
|
go_version = check_output('go version'.split()).split()[2]
|
|
|
|
if go_version < 'go1.4':
|
|
|
|
print('runtests: skip on {}'.format(go_version), file=sys.stderr)
|
|
|
|
return
|
|
|
|
|
2016-07-14 20:02:57 +00:00
|
|
|
_run('go generate ./...')
|
2016-07-10 16:26:09 +00:00
|
|
|
_run('git diff --exit-code')
|
2016-06-16 15:47:19 +00:00
|
|
|
|
|
|
|
|
2016-05-09 12:41:01 +00:00
|
|
|
def _run(command):
|
2016-06-23 04:56:44 +00:00
|
|
|
if hasattr(command, 'split'):
|
|
|
|
command = command.split()
|
2016-05-09 12:41:01 +00:00
|
|
|
print('runtests: {}'.format(' '.join(command)), file=sys.stderr)
|
2016-06-18 20:28:50 +00:00
|
|
|
sys.stderr.flush()
|
2016-05-09 12:41:01 +00:00
|
|
|
check_call(command)
|
|
|
|
|
|
|
|
|
2016-07-16 13:12:42 +00:00
|
|
|
def _gfmrun_count():
|
2016-05-09 12:41:01 +00:00
|
|
|
with open('README.md') as infile:
|
|
|
|
lines = infile.read().splitlines()
|
|
|
|
return len(filter(_is_go_runnable, lines))
|
|
|
|
|
|
|
|
|
|
|
|
def _is_go_runnable(line):
|
|
|
|
return line.startswith('package main')
|
|
|
|
|
|
|
|
|
|
|
|
def _combine_coverprofiles(coverprofiles):
|
2016-05-22 23:44:21 +00:00
|
|
|
combined = tempfile.NamedTemporaryFile(
|
|
|
|
suffix='.coverprofile', delete=False
|
|
|
|
)
|
2016-05-09 12:41:01 +00:00
|
|
|
combined.write('mode: set\n')
|
|
|
|
|
|
|
|
for coverprofile in coverprofiles:
|
|
|
|
with open(coverprofile, 'r') as infile:
|
|
|
|
for line in infile.readlines():
|
|
|
|
if not line.startswith('mode: '):
|
|
|
|
combined.write(line)
|
|
|
|
|
|
|
|
combined.flush()
|
2016-05-22 23:44:21 +00:00
|
|
|
name = combined.name
|
|
|
|
combined.close()
|
|
|
|
return name
|
2016-05-09 12:41:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|