Skip to content

rspec_profiling: Discover the correct branch name in GitLab CI

What does this MR do?

Monkey-patch rspec_profiling to return the correct branch name in GitLab CI environments

Are there points in the code the reviewer needs to double check?

Just make sure the spec runs appear in redash with the right branch name?

Why was this MR needed?

rspec_profiling 0.0.5 attempts to detect the checked-out branch. This fails in GitLab CI because we check out a commit, not a branch, so we're in detached HEAD state.

Fortunately, we can use $CI_BUILD_REF_NAME which has the branch (or tag) name in it.

Screenshots (if relevant)

gitlab-mbp:gitlab lupine$ RAILS_ENV=test CI_BUILD_REF_NAME='foo' CI=1 ruby -r'./config/environment' -e 'puts RspecProfiling::VCS::Git.new.branch'
foo
gitlab-mbp:gitlab lupine$ RAILS_ENV=test CI=1 ruby -r'./config/environment' -e 'puts RspecProfiling::VCS::Git.new.branch'
rspec-profiling-branch-name-in-ci
gitlab-mbp:gitlab lupine$ RAILS_ENV=test CI_BUILD_REF_NAME='foo' ruby -r'./config/environment' -e 'puts RspecProfiling::VCS::Git.new.branch'
rspec-profiling-branch-name-in-ci

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/27517 !9094 (merged)

/cc @stanhu

Merge request reports