From 32c16440d6266efdde53cc84ce7c39f82c59faed Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Fri, 9 Oct 2020 16:57:03 +0100 Subject: [PATCH] Fix environment detection for Semaphore CI We use semaphore CI with several parallel job and it looks like the environment isn't detected properly currently: - I couldn't find an environment variable giving the pull request number, (supposed to come from `PULL_REQUEST_NUMBER`), however I noted `SEMAPHORE_BRANCH_ID` which is the same ID between builds pushed to the same branch. Example value: 3385909. - The `SEMAPHORE_BUILD_NUMBER` is the same across all workers for a given push, and changes at each push. It sounds like it should be used as `number`, not as `job`. This starts at 1 on each branch, and increase on each push. - The job ID can be obtained via `SEMAPHORE_CURRENT_JOB`, and for a given build, each worker will have their own (e.g. 1, 2, 3, etc...). Looking at the config from the other CIs, I think it should be returned as `job`. --- coveralls/api.py | 7 ++++--- tests/api/configuration_test.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/coveralls/api.py b/coveralls/api.py index 73d51166..a05de8cd 100644 --- a/coveralls/api.py +++ b/coveralls/api.py @@ -118,9 +118,10 @@ def load_config_from_travis(): @staticmethod def load_config_from_semaphore(): - job = os.environ.get('SEMAPHORE_BUILD_NUMBER') - pr = os.environ.get('PULL_REQUEST_NUMBER') - return 'semaphore-ci', job, None, pr + job = os.environ.get('SEMAPHORE_CURRENT_JOB') + number = os.environ.get('SEMAPHORE_BUILD_NUMBER') + pr = os.environ.get('SEMAPHORE_BRANCH_ID') + return 'semaphore-ci', job, number, pr @staticmethod def load_config_from_unknown(): diff --git a/tests/api/configuration_test.py b/tests/api/configuration_test.py index 985bc925..71bb295e 100644 --- a/tests/api/configuration_test.py +++ b/tests/api/configuration_test.py @@ -173,12 +173,14 @@ def test_travis_no_config(self): @mock.patch.dict(os.environ, {'SEMAPHORE': 'True', 'SEMAPHORE_BUILD_NUMBER': '888', - 'PULL_REQUEST_NUMBER': '9999'}, + 'SEMAPHORE_CURRENT_JOB': '1', + 'SEMAPHORE_BRANCH_ID': '9999'}, clear=True) def test_semaphore_no_config(self): cover = Coveralls(repo_token='xxx') assert cover.config['service_name'] == 'semaphore-ci' - assert cover.config['service_job_id'] == '888' + assert cover.config['service_job_id'] == '1' + assert cover.config['service_number'] == '888' assert cover.config['service_pull_request'] == '9999' @mock.patch.dict(os.environ, {'COVERALLS_SERVICE_NAME': 'xxx'}, clear=True)