diff --git a/coveralls/git.py b/coveralls/git.py index 9727e5a0..b0efa9de 100644 --- a/coveralls/git.py +++ b/coveralls/git.py @@ -32,7 +32,10 @@ def git_branch(): branch = None if os.environ.get('GITHUB_ACTIONS'): github_ref = os.environ.get('GITHUB_REF') - if github_ref.startswith('refs/heads/'): + if ( + github_ref.startswith('refs/heads/') + or github_ref.startswith('refs/tags/') + ): # E.g. in push events. branch = github_ref.split('/', 2)[-1] else: diff --git a/tests/git_test.py b/tests/git_test.py index 562a87d5..ee629af7 100644 --- a/tests/git_test.py +++ b/tests/git_test.py @@ -125,6 +125,16 @@ def test_gitinfo_github_pr(self): 'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f', 'GITHUB_HEAD_REF': '' }, clear=True) - def test_gitinfo_github_nopr(self): + def test_gitinfo_github_branch(self): git_info = coveralls.git.git_info() assert git_info['git']['branch'] == 'master' + + @mock.patch.dict(os.environ, { + 'GITHUB_ACTIONS': 'true', + 'GITHUB_REF': 'refs/tags/v1.0', + 'GITHUB_SHA': 'bb0e00166b28f49db04d6a8b8cb4bddb5afa529f', + 'GITHUB_HEAD_REF': '' + }, clear=True) + def test_gitinfo_github_tag(self): + git_info = coveralls.git.git_info() + assert git_info['git']['branch'] == 'v1.0'