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

Fix branch name detection for GitHub Actions CI #111

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ def build_params(ci)
when GITHUB
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
params[:service] = 'github-actions'
params[:branch] = ENV['GITHUB_HEAD_REF'] || ENV['GITHUB_REF'].sub('refs/head/', '')
# PR refs are in the format: refs/pull/7/merge for pull_request events
params[:pr] = ENV['GITHUB_REF'].split('/')[2] unless ENV['GITHUB_HEAD_REF'].nil? || ENV['GITHUB_HEAD_REF'].empty?
if (ENV['GITHUB_HEAD_REF'] || '').empty?
params[:branch] = ENV['GITHUB_REF'].sub('refs/heads/', '')
else
params[:branch] = ENV['GITHUB_HEAD_REF']
# PR refs are in the format: refs/pull/7/merge for pull_request events
params[:pr] = ENV['GITHUB_REF'].split('/')[2]
end
params[:slug] = ENV['GITHUB_REPOSITORY']
params[:build] = ENV['GITHUB_RUN_ID']
params[:commit] = ENV['GITHUB_SHA']
Expand Down
4 changes: 2 additions & 2 deletions test/test_codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ def test_github_pull_request
def test_github_push
ENV['CI'] = 'true'
ENV['GITHUB_ACTIONS'] = 'true'
ENV['GITHUB_HEAD_REF'] = nil
ENV['GITHUB_REF'] = 'refs/head/master'
ENV['GITHUB_HEAD_REF'] = ''
ENV['GITHUB_REF'] = 'refs/heads/master'
ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
ENV['GITHUB_RUN_ID'] = '1'
ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
Expand Down