From b6f318f642bd7fa0e5ba783fe71b6e83c06da6f3 Mon Sep 17 00:00:00 2001 From: "Peter Helcmanovsky (Ped)" Date: Mon, 22 Jul 2019 17:21:07 +0200 Subject: [PATCH 1/3] add CI_SERVICE_NAME env-var to avoid pyYAML installation just to config service name --- README.md | 1 + cpp_coveralls/__init__.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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', '') From acbbae60be63600d3909e5d2a7a9c8829469ea4d Mon Sep 17 00:00:00 2001 From: "Peter Helcmanovsky (Ped)" Date: Tue, 23 Jul 2019 12:36:15 +0200 Subject: [PATCH 2/3] add "service_number" set to git revision number, if "job_id" is empty 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,.. and staying at Build #1 for every commit, even when sources did change) This may be inherently wrong solution and complete hack, feel free to comment+help with the issue (also I don't know python, so the code change may be not optimal itself). --- cpp_coveralls/coverage.py | 17 ++++++++++++++--- cpp_coveralls/gitrepo.py | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) 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..d2a8b16 100644 --- a/cpp_coveralls/gitrepo.py +++ b/cpp_coveralls/gitrepo.py @@ -40,6 +40,7 @@ def gitrepo(cwd): 'committer_name': repo.gitlog('%cN'), 'committer_email': repo.gitlog('%ce'), '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', From 38d46dea4251996455ba4abda37c6e95900939aa Mon Sep 17 00:00:00 2001 From: "Peter Helcmanovsky (Ped)" Date: Tue, 23 Jul 2019 12:47:28 +0200 Subject: [PATCH 3/3] add "service_number", typo bugfix --- cpp_coveralls/gitrepo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp_coveralls/gitrepo.py b/cpp_coveralls/gitrepo.py index d2a8b16..7ec8438 100644 --- a/cpp_coveralls/gitrepo.py +++ b/cpp_coveralls/gitrepo.py @@ -39,7 +39,7 @@ 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',