From 2610885ab254a0d58277275fc58c415ecca47708 Mon Sep 17 00:00:00 2001 From: Frank-Colson <91486640+Frank-Colson@users.noreply.github.com> Date: Thu, 11 Nov 2021 12:53:35 -0800 Subject: [PATCH] fix: correctly support parallel execution on CircleCI (#336) Co-authored-by: Elijah Shaw-Rutschman --- coveralls/api.py | 8 +++++--- docs/usage/tox.rst | 2 ++ tests/api/configuration_test.py | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/coveralls/api.py b/coveralls/api.py index 56616880..d1024300 100644 --- a/coveralls/api.py +++ b/coveralls/api.py @@ -97,9 +97,11 @@ def load_config_from_buildkite(): @staticmethod def load_config_from_circle(): - pr = os.environ.get('CI_PULL_REQUEST', '').split('/')[-1] or None - number = os.environ.get('CIRCLE_WORKFLOW_ID') - return 'circle-ci', os.environ.get('CIRCLE_BUILD_NUM'), number, pr + number = os.environ.get( + 'CIRCLE_WORKFLOW_ID') or os.environ.get('CIRCLE_BUILD_NUM') + pr = (os.environ.get('CI_PULL_REQUEST') or "").split("/")[-1] or None + job = os.environ.get('CIRCLE_NODE_INDEX') or None + return 'circleci', job, number, pr def load_config_from_github(self): # Github tokens and standard Coveralls tokens are almost but not quite diff --git a/docs/usage/tox.rst b/docs/usage/tox.rst index 29b7eef0..3605bc26 100644 --- a/docs/usage/tox.rst +++ b/docs/usage/tox.rst @@ -52,8 +52,10 @@ CircleCI All variables: - ``CIRCLECI`` +- ``CIRCLE_WORKFLOW_ID`` - ``CIRCLE_BUILD_NUM`` - ``CIRCLE_BRANCH`` +- ``CIRCLE_NODE_INDEX`` - ``CI_PULL_REQUEST`` Github Actions diff --git a/tests/api/configuration_test.py b/tests/api/configuration_test.py index 4dc69e63..c9bd36f9 100644 --- a/tests/api/configuration_test.py +++ b/tests/api/configuration_test.py @@ -113,12 +113,24 @@ def test_buildkite_no_config_no_pr(self): 'CIRCLE_BUILD_NUM': '888', 'CI_PULL_REQUEST': 'https://github.com/org/repo/pull/9999'}, clear=True) - def test_circleci_no_config(self): + def test_circleci_singular_no_config(self): cover = Coveralls(repo_token='xxx') - assert cover.config['service_name'] == 'circle-ci' - assert cover.config['service_job_id'] == '888' + assert cover.config['service_name'] == 'circleci' + assert cover.config['service_number'] == '888' assert cover.config['service_pull_request'] == '9999' + @mock.patch.dict( + os.environ, + {'CIRCLECI': 'True', + 'CIRCLE_WORKFLOW_ID': '0ea2c0f7-4e56-4a94-bf77-bfae6bdbf80a', + 'CIRCLE_NODE_INDEX': '15'}, + clear=True) + def test_circleci_parallel_no_config(self): + cover = Coveralls(repo_token='xxx') + assert cover.config['service_name'] == 'circleci' + assert cover.config['service_number'] == '0ea2c0f7-4e56-4a94-bf77-bfae6bdbf80a' + assert cover.config['service_job_id'] == '15' + @mock.patch.dict( os.environ, {'GITHUB_ACTIONS': 'true',