Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit f677699

Browse files
Fix branch name detection for GitHub Actions CI (#111)
* Fix typo (it is 'refs/heads/' not 'refs/head') * Detect GITHUB_HEAD_REF='' as falsey
1 parent 0546624 commit f677699

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/codecov.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ def build_params(ci)
192192
when GITHUB
193193
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
194194
params[:service] = 'github-actions'
195-
params[:branch] = ENV['GITHUB_HEAD_REF'] || ENV['GITHUB_REF'].sub('refs/head/', '')
196-
# PR refs are in the format: refs/pull/7/merge for pull_request events
197-
params[:pr] = ENV['GITHUB_REF'].split('/')[2] unless ENV['GITHUB_HEAD_REF'].nil? || ENV['GITHUB_HEAD_REF'].empty?
195+
if (ENV['GITHUB_HEAD_REF'] || '').empty?
196+
params[:branch] = ENV['GITHUB_REF'].sub('refs/heads/', '')
197+
else
198+
params[:branch] = ENV['GITHUB_HEAD_REF']
199+
# PR refs are in the format: refs/pull/7/merge for pull_request events
200+
params[:pr] = ENV['GITHUB_REF'].split('/')[2]
201+
end
198202
params[:slug] = ENV['GITHUB_REPOSITORY']
199203
params[:build] = ENV['GITHUB_RUN_ID']
200204
params[:commit] = ENV['GITHUB_SHA']

test/test_codecov.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ def test_github_pull_request
484484
def test_github_push
485485
ENV['CI'] = 'true'
486486
ENV['GITHUB_ACTIONS'] = 'true'
487-
ENV['GITHUB_HEAD_REF'] = nil
488-
ENV['GITHUB_REF'] = 'refs/head/master'
487+
ENV['GITHUB_HEAD_REF'] = ''
488+
ENV['GITHUB_REF'] = 'refs/heads/master'
489489
ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
490490
ENV['GITHUB_RUN_ID'] = '1'
491491
ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'

0 commit comments

Comments
 (0)