Skip to content

Commit

Permalink
Fix environment detection for Semaphore CI
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
browniebroke committed Oct 9, 2020
1 parent e31c265 commit 32c1644
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions coveralls/api.py
Expand Up @@ -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():
Expand Down
6 changes: 4 additions & 2 deletions tests/api/configuration_test.py
Expand Up @@ -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)
Expand Down

0 comments on commit 32c1644

Please sign in to comment.