Skip to content

Commit 9f93bd8

Browse files
bboeTheKevJames
andcommitted
feat(github): add service_number for github actions
Required for supporting parallel builds. Co-Authored-By: Kevin James <[email protected]>
1 parent 6064a81 commit 9f93bd8

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

coveralls/api.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ def __init__(self, token_required=True, service_name=None, **kwargs):
5151
name, job, pr = self.load_config_from_ci_environment()
5252
self.config['service_name'] = self.config.get('service_name', name)
5353
if job:
54-
self.config['service_job_id'] = job
54+
# N.B. Github Actions uses a different chunk of the Coveralls
55+
# config when running parallel builds, ie. `service_number` instead
56+
# of `service_job_id`.
57+
if name.startswith('github'):
58+
self.config['service_number'] = job
59+
else:
60+
self.config['service_job_id'] = job
5561
if pr:
5662
self.config['service_pull_request'] = pr
5763

@@ -85,10 +91,12 @@ def load_config_from_circle():
8591

8692
@staticmethod
8793
def load_config_from_github():
94+
service_number = os.environ.get('GITHUB_SHA')
8895
pr = None
8996
if os.environ.get('GITHUB_REF', '').startswith('refs/pull/'):
9097
pr = os.environ.get('GITHUB_REF', '//').split('/')[2]
91-
return 'github-actions', None, pr
98+
service_number += "-PR-{0}".format(pr)
99+
return 'github', service_number, pr
92100

93101
@staticmethod
94102
def load_config_from_jenkins():

docs/usage/tox.rst

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ All variables:
6666

6767
- ``GITHUB_ACTIONS``
6868
- ``GITHUB_REF``
69+
- ``GITHUB_SHA``
6970
- ``GITHUB_HEAD_REF``
7071

7172
Jenkins

tests/api/configuration_test.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,29 @@ def test_circleci_no_config(self):
110110
assert cover.config['service_job_id'] == '888'
111111
assert cover.config['service_pull_request'] == '9999'
112112

113-
@mock.patch.dict(os.environ, {'GITHUB_ACTIONS': 'true',
114-
'GITHUB_REF': 'refs/pull/1234/merge',
115-
'GITHUB_HEAD_REF': 'fixup-branch'},
116-
clear=True)
113+
@mock.patch.dict(
114+
os.environ,
115+
{'GITHUB_ACTIONS': 'true',
116+
'GITHUB_REF': 'refs/pull/1234/merge',
117+
'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f',
118+
'GITHUB_HEAD_REF': 'fixup-branch'},
119+
clear=True)
117120
def test_github_no_config(self):
118121
cover = Coveralls(repo_token='xxx')
119-
assert cover.config['service_name'] == 'github-actions'
122+
assert cover.config['service_name'] == 'github'
120123
assert cover.config['service_pull_request'] == '1234'
121124
assert 'service_job_id' not in cover.config
122125

123-
@mock.patch.dict(os.environ, {'GITHUB_ACTIONS': 'true',
124-
'GITHUB_REF': 'refs/heads/master',
125-
'GITHUB_HEAD_REF': ''},
126-
clear=True)
126+
@mock.patch.dict(
127+
os.environ,
128+
{'GITHUB_ACTIONS': 'true',
129+
'GITHUB_REF': 'refs/heads/master',
130+
'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f',
131+
'GITHUB_HEAD_REF': ''},
132+
clear=True)
127133
def test_github_no_config_no_pr(self):
128134
cover = Coveralls(repo_token='xxx')
129-
assert cover.config['service_name'] == 'github-actions'
135+
assert cover.config['service_name'] == 'github'
130136
assert 'service_pull_request' not in cover.config
131137
assert 'service_job_id' not in cover.config
132138

tests/git_test.py

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class GitInfoTestBranch(GitTest):
124124
@mock.patch.dict(os.environ, {
125125
'GITHUB_ACTIONS': 'true',
126126
'GITHUB_REF': 'refs/pull/1234/merge',
127+
'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f',
127128
'GITHUB_HEAD_REF': 'fixup-branch'
128129
}, clear=True)
129130
def test_gitinfo_github_pr(self):
@@ -133,6 +134,7 @@ def test_gitinfo_github_pr(self):
133134
@mock.patch.dict(os.environ, {
134135
'GITHUB_ACTIONS': 'true',
135136
'GITHUB_REF': 'refs/heads/master',
137+
'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f',
136138
'GITHUB_HEAD_REF': ''
137139
}, clear=True)
138140
def test_gitinfo_github_nopr(self):

0 commit comments

Comments
 (0)