diff --git a/README.md b/README.md index 689f1bd..da92cc1 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Inspired from [z4r/python-coveralls](https://github.com/z4r/python-coveralls), i - `COVERALLS_REPO_TOKEN` - `COVERALLS_ENDPOINT` - `COVERALLS_PARALLEL` +- `CI_SERVICE_NAME` ## Usage: diff --git a/cpp_coveralls/__init__.py b/cpp_coveralls/__init__.py index c3d0e4e..1b6da93 100644 --- a/cpp_coveralls/__init__.py +++ b/cpp_coveralls/__init__.py @@ -73,7 +73,13 @@ def run(): # use environment COVERALLS_REPO_TOKEN as a fallback args.repo_token = os.environ.get('COVERALLS_REPO_TOKEN') - args.service_name = yml.get('service_name', 'travis-ci') + args.service_name = yml.get('service_name', '') + if not args.service_name: + # use environment CI_SERVICE_NAME as a fallback + args.service_name = os.environ.get('CI_SERVICE_NAME') + if not args.service_name: + # use default 'travis-ci' as a fallback 2 + args.service_name = 'travis-ci' if not args.gcov_options: args.gcov_options = yml.get('gcov_options', '') diff --git a/cpp_coveralls/coverage.py b/cpp_coveralls/coverage.py index 4f2c6e3..b512717 100644 --- a/cpp_coveralls/coverage.py +++ b/cpp_coveralls/coverage.py @@ -374,14 +374,28 @@ def collect_non_report_files(args, discovered_files): def collect(args): """Collect coverage reports.""" excl_paths = exclude_paths(args) + abs_root = os.path.abspath(args.root) report = {} + # Use the root directory to get information on the Git repository + report['git'] = gitrepo.gitrepo(abs_root) + if args.repo_token: report['repo_token'] = args.repo_token report['service_name'] = args.service_name report['service_job_id'] = args.service_job_id + # If the service_name + service_job_id is not set to identify build, + # the default build numbers auto-incremented by coveralls.io seems to never advance + # (doing just incremental changes to original build #1), so this git revision number + # hack is used to get something more meaningful (at least at the project I'm trying + # to make this work, it's acting like this, numbering coverage data 1.1, 1.2, 1.3,..) + ## This may be inherently wrong solution and complete hack, feel free to comment+help + # to resolve this in more appropriate way. by Ped7g ( https://github.com/ped7g ) + if not args.service_job_id: + report['service_number'] = report['git']['head']['rev_count'] + if os.getenv('COVERALLS_PARALLEL', False): report['parallel'] = 'true' @@ -393,7 +407,6 @@ def collect(args): discovered_files = set() src_files = {} - abs_root = os.path.abspath(args.root) if args.lcov_file: info_lines = [line.rstrip('\n') for line in open(args.lcov_file, 'r')] line_iter = iter(info_lines) @@ -467,6 +480,4 @@ def collect(args): report['source_files'].extend( collect_non_report_files(args, discovered_files)) - # Use the root directory to get information on the Git repository - report['git'] = gitrepo.gitrepo(abs_root) return report diff --git a/cpp_coveralls/gitrepo.py b/cpp_coveralls/gitrepo.py index b7e09e2..7ec8438 100644 --- a/cpp_coveralls/gitrepo.py +++ b/cpp_coveralls/gitrepo.py @@ -39,7 +39,8 @@ def gitrepo(cwd): 'author_email': repo.gitlog('%ae'), 'committer_name': repo.gitlog('%cN'), 'committer_email': repo.gitlog('%ce'), - 'message': repo.gitlog('%s') + 'message': repo.gitlog('%s'), + 'rev_count': repo.git('rev-list', '--count', 'HEAD')[1].strip() }, 'branch': os.environ.get('TRAVIS_BRANCH', os.environ.get('APPVEYOR_REPO_BRANCH',