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

Commit

Permalink
Add support GitHub Actions (#78)
Browse files Browse the repository at this point in the history
* Add support GitHub Actions

Based on #52

Co-authored-by: Timo Schilling <timo@schilling.io>

* Use GitHub Actions

* Clear out GitHub Actions var

Co-authored-by: Timo Schilling <timo@schilling.io>
Co-authored-by: Thomas Hu <tomhu1096@gmail.com>
  • Loading branch information
3 people committed Aug 6, 2020
1 parent fd625ad commit 3fe7460
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
12 changes: 12 additions & 0 deletions lib/codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SimpleCov::Formatter::Codecov
CIRCLE = 'Circle CI',
CODESHIP = 'Codeship CI',
DRONEIO = 'Drone CI',
GITHUB = 'GitHub Actions',
GITLAB = 'GitLab CI',
HEROKU = 'Heroku CI',
JENKINS = 'Jenkins CI',
Expand Down Expand Up @@ -62,6 +63,8 @@ def detect_ci
CODESHIP
elsif ((ENV['CI'] == 'true') || (ENV['CI'] == 'drone')) && (ENV['DRONE'] == 'true')
DRONEIO
elsif (ENV['CI'] == 'true') && (ENV['GITHUB_ACTIONS'] == 'true')
GITHUB
elsif !ENV['GITLAB_CI'].nil?
GITLAB
elsif ENV['HEROKU_TEST_RUN_ID']
Expand Down Expand Up @@ -172,6 +175,15 @@ def build_params(ci)
params[:build_url] = ENV['DRONE_BUILD_LINK'] || ENV['DRONE_BUILD_URL'] || ENV['CI_BUILD_URL']
params[:pr] = ENV['DRONE_PULL_REQUEST']
params[:tag] = ENV['DRONE_TAG']
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/heads/', '')
# PR refs are in the format: refs/pull/7/merge
params[:pr] = ENV['GITHUB_REF'].split('/')[2] if ENV['GITHUB_HEAD_REF']
params[:slug] = ENV['GITHUB_REPOSITORY']
params[:build] = ENV['GITHUB_RUN_ID']
params[:commit] = ENV['GITHUB_SHA']
when GITLAB
# http://doc.gitlab.com/ci/examples/README.html#environmental-variables
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb#L96
Expand Down
38 changes: 35 additions & 3 deletions test/test_codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ class TestCodecov < Minitest::Test
CI = SimpleCov::Formatter::Codecov.new.detect_ci

REALENV =
if CI == SimpleCov::Formatter::Codecov::TRAVIS
if CI == SimpleCov::Formatter::Codecov::GITHUB
{
'GITHUB_ACTIONS' => ENV['GITHUB_ACTIONS'],
'GITHUB_HEAD_REF' => ENV['GITHUB_HEAD_REF'],
'GITHUB_REF' => ENV['GITHUB_REF'],
'GITHUB_REPOSITORY' => ENV['GITHUB_REPOSITORY'],
'GITHUB_RUN_ID' => ENV['GITHUB_RUN_ID'],
'GITHUB_SHA' => ENV['GITHUB_SHA']
}
elsif CI == SimpleCov::Formatter::Codecov::TRAVIS
{
'TRAVIS' => ENV['TRAVIS'],
'TRAVIS_BRANCH' => ENV['TRAVIS_BRANCH'],
Expand All @@ -15,10 +24,10 @@ class TestCodecov < Minitest::Test
'TRAVIS_JOB_NUMBER' => ENV['TRAVIS_JOB_NUMBER'],
'TRAVIS_PULL_REQUEST' => ENV['TRAVIS_PULL_REQUEST'],
'TRAVIS_JOB_ID' => ENV['TRAVIS_JOB_ID']
}.freeze
}
else
{}
end
end.freeze

def url
ENV['CODECOV_URL'] || 'https://codecov.io'
Expand Down Expand Up @@ -85,6 +94,7 @@ def assert_successful_upload(data)

def setup
ENV['CI'] = nil
ENV['GITHUB_ACTIONS'] = nil
ENV['TRAVIS'] = nil
end

Expand Down Expand Up @@ -159,6 +169,12 @@ def teardown
ENV['ghprbSourceBranch'] = nil
ENV['GIT_BRANCH'] = nil
ENV['GIT_COMMIT'] = nil
ENV['GITHUB_ACTIONS'] = nil
ENV['GITHUB_REF'] = nil
ENV['GITHUB_HEAD_REF'] = nil
ENV['GITHUB_REPOSITORY'] = nil
ENV['GITHUB_RUN_ID'] = nil
ENV['GITHUB_SHA'] = nil
ENV['GITLAB_CI'] = nil
ENV['HEROKU_TEST_RUN_ID'] = nil
ENV['HEROKU_TEST_RUN_BRANCH'] = nil
Expand Down Expand Up @@ -411,6 +427,22 @@ def test_wercker
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
end

def test_github
ENV['CI'] = 'true'
ENV['GITHUB_ACTIONS'] = 'true'
ENV['GITHUB_REF'] = 'refs/head/master'
ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
ENV['GITHUB_RUN_ID'] = '1'
ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
result = upload
assert_equal('github-actions', result['params'][:service])
assert_equal('c739768fcac68144a3a6d82305b9c4106934d31a', result['params'][:commit])
assert_equal('codecov/ci-repo', result['params'][:slug])
assert_equal('1', result['params'][:build])
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
end

def test_gitlab
ENV['GITLAB_CI'] = 'true'
ENV['CI_BUILD_REF_NAME'] = 'master'
Expand Down

0 comments on commit 3fe7460

Please sign in to comment.