Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environment detection for Semaphore CI #236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions coveralls/api.py
Expand Up @@ -118,9 +118,19 @@ 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_JOB_UUID') # Classic
or os.environ.get('SEMAPHORE_JOB_ID') # 2.0
)
number = (
os.environ.get('SEMAPHORE_EXECUTABLE_UUID') # Classic
or os.environ.get('SEMAPHORE_WORKFLOW_ID') # 2.0
)
pr = (
os.environ.get('SEMAPHORE_BRANCH_ID') # Classic
or os.environ.get('SEMAPHORE_GIT_PR_NUMBER') # 2.0
)
return 'semaphore-ci', job, number, pr

@staticmethod
def load_config_from_unknown():
Expand Down
26 changes: 23 additions & 3 deletions docs/usage/tox.rst
Expand Up @@ -102,15 +102,35 @@ All variables:

SemaphoreCI
-----------

Classic
~~~~~~~

::

passenv = SEMAPHORE SEMAPHORE_EXECUTABLE_UUID SEMAPHORE_JOB_UUID SEMAPHORE_BRANCH_ID BRANCH_NAME

All variables:

- ``SEMAPHORE``
- ``SEMAPHORE_EXECUTABLE_UUID``
- ``SEMAPHORE_JOB_UUID``
- ``SEMAPHORE_BRANCH_ID``
- ``BRANCH_NAME``

2.0
~~~

::

passenv = SEMAPHORE SEMAPHORE_BUILD_NUMBER BRANCH_NAME PULL_REQUEST_NUMBER
passenv = SEMAPHORE SEMAPHORE_WORKFLOW_ID SEMAPHORE_JOB_ID SEMAPHORE_GIT_PR_NUMBER BRANCH_NAME

All variables:

- ``SEMAPHORE``
- ``SEMAPHORE_BUILD_NUMBER``
- ``SEMAPHORE_WORKFLOW_ID``
- ``SEMAPHORE_JOB_ID``
- ``SEMAPHORE_GIT_PR_NUMBER``
- ``BRANCH_NAME``
- ``PULL_REQUEST_NUMBER``

.. _tox: https://tox.readthedocs.io/en/latest/
31 changes: 24 additions & 7 deletions tests/api/configuration_test.py
Expand Up @@ -170,15 +170,32 @@ def test_travis_no_config(self):
assert cover.config['service_job_id'] == '777'
assert 'repo_token' not in cover.config

@mock.patch.dict(os.environ,
{'SEMAPHORE': 'True',
'SEMAPHORE_BUILD_NUMBER': '888',
'PULL_REQUEST_NUMBER': '9999'},
clear=True)
def test_semaphore_no_config(self):
@mock.patch.dict(
os.environ,
{'SEMAPHORE': 'True',
'SEMAPHORE_EXECUTABLE_UUID': '36980c73',
'SEMAPHORE_JOB_UUID': 'a26d42cf',
'SEMAPHORE_BRANCH_ID': '9999'},
clear=True)
def test_semaphore_classic_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'] == 'a26d42cf'
assert cover.config['service_number'] == '36980c73'
assert cover.config['service_pull_request'] == '9999'

@mock.patch.dict(
os.environ,
{'SEMAPHORE': 'True',
'SEMAPHORE_WORKFLOW_ID': 'b86b3adf',
'SEMAPHORE_JOB_ID': '2b942b49',
'SEMAPHORE_GIT_PR_NUMBER': '9999'},
clear=True)
def test_semaphore_20_no_config(self):
cover = Coveralls(repo_token='xxx')
assert cover.config['service_name'] == 'semaphore-ci'
assert cover.config['service_job_id'] == '2b942b49'
assert cover.config['service_number'] == 'b86b3adf'
assert cover.config['service_pull_request'] == '9999'

@mock.patch.dict(os.environ, {'COVERALLS_SERVICE_NAME': 'xxx'}, clear=True)
Expand Down