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

Commit 3fe7460

Browse files
ysakasintimoschillingthomasrockhu
authored
Add support GitHub Actions (#78)
* 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>
1 parent fd625ad commit 3fe7460

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

lib/codecov.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class SimpleCov::Formatter::Codecov
2020
CIRCLE = 'Circle CI',
2121
CODESHIP = 'Codeship CI',
2222
DRONEIO = 'Drone CI',
23+
GITHUB = 'GitHub Actions',
2324
GITLAB = 'GitLab CI',
2425
HEROKU = 'Heroku CI',
2526
JENKINS = 'Jenkins CI',
@@ -62,6 +63,8 @@ def detect_ci
6263
CODESHIP
6364
elsif ((ENV['CI'] == 'true') || (ENV['CI'] == 'drone')) && (ENV['DRONE'] == 'true')
6465
DRONEIO
66+
elsif (ENV['CI'] == 'true') && (ENV['GITHUB_ACTIONS'] == 'true')
67+
GITHUB
6568
elsif !ENV['GITLAB_CI'].nil?
6669
GITLAB
6770
elsif ENV['HEROKU_TEST_RUN_ID']
@@ -172,6 +175,15 @@ def build_params(ci)
172175
params[:build_url] = ENV['DRONE_BUILD_LINK'] || ENV['DRONE_BUILD_URL'] || ENV['CI_BUILD_URL']
173176
params[:pr] = ENV['DRONE_PULL_REQUEST']
174177
params[:tag] = ENV['DRONE_TAG']
178+
when GITHUB
179+
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
180+
params[:service] = 'github-actions'
181+
params[:branch] = ENV['GITHUB_HEAD_REF'] || ENV['GITHUB_REF'].sub('refs/heads/', '')
182+
# PR refs are in the format: refs/pull/7/merge
183+
params[:pr] = ENV['GITHUB_REF'].split('/')[2] if ENV['GITHUB_HEAD_REF']
184+
params[:slug] = ENV['GITHUB_REPOSITORY']
185+
params[:build] = ENV['GITHUB_RUN_ID']
186+
params[:commit] = ENV['GITHUB_SHA']
175187
when GITLAB
176188
# http://doc.gitlab.com/ci/examples/README.html#environmental-variables
177189
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb#L96

test/test_codecov.rb

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ class TestCodecov < Minitest::Test
66
CI = SimpleCov::Formatter::Codecov.new.detect_ci
77

88
REALENV =
9-
if CI == SimpleCov::Formatter::Codecov::TRAVIS
9+
if CI == SimpleCov::Formatter::Codecov::GITHUB
10+
{
11+
'GITHUB_ACTIONS' => ENV['GITHUB_ACTIONS'],
12+
'GITHUB_HEAD_REF' => ENV['GITHUB_HEAD_REF'],
13+
'GITHUB_REF' => ENV['GITHUB_REF'],
14+
'GITHUB_REPOSITORY' => ENV['GITHUB_REPOSITORY'],
15+
'GITHUB_RUN_ID' => ENV['GITHUB_RUN_ID'],
16+
'GITHUB_SHA' => ENV['GITHUB_SHA']
17+
}
18+
elsif CI == SimpleCov::Formatter::Codecov::TRAVIS
1019
{
1120
'TRAVIS' => ENV['TRAVIS'],
1221
'TRAVIS_BRANCH' => ENV['TRAVIS_BRANCH'],
@@ -15,10 +24,10 @@ class TestCodecov < Minitest::Test
1524
'TRAVIS_JOB_NUMBER' => ENV['TRAVIS_JOB_NUMBER'],
1625
'TRAVIS_PULL_REQUEST' => ENV['TRAVIS_PULL_REQUEST'],
1726
'TRAVIS_JOB_ID' => ENV['TRAVIS_JOB_ID']
18-
}.freeze
27+
}
1928
else
2029
{}
21-
end
30+
end.freeze
2231

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

8695
def setup
8796
ENV['CI'] = nil
97+
ENV['GITHUB_ACTIONS'] = nil
8898
ENV['TRAVIS'] = nil
8999
end
90100

@@ -159,6 +169,12 @@ def teardown
159169
ENV['ghprbSourceBranch'] = nil
160170
ENV['GIT_BRANCH'] = nil
161171
ENV['GIT_COMMIT'] = nil
172+
ENV['GITHUB_ACTIONS'] = nil
173+
ENV['GITHUB_REF'] = nil
174+
ENV['GITHUB_HEAD_REF'] = nil
175+
ENV['GITHUB_REPOSITORY'] = nil
176+
ENV['GITHUB_RUN_ID'] = nil
177+
ENV['GITHUB_SHA'] = nil
162178
ENV['GITLAB_CI'] = nil
163179
ENV['HEROKU_TEST_RUN_ID'] = nil
164180
ENV['HEROKU_TEST_RUN_BRANCH'] = nil
@@ -411,6 +427,22 @@ def test_wercker
411427
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
412428
end
413429

430+
def test_github
431+
ENV['CI'] = 'true'
432+
ENV['GITHUB_ACTIONS'] = 'true'
433+
ENV['GITHUB_REF'] = 'refs/head/master'
434+
ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
435+
ENV['GITHUB_RUN_ID'] = '1'
436+
ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
437+
ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
438+
result = upload
439+
assert_equal('github-actions', result['params'][:service])
440+
assert_equal('c739768fcac68144a3a6d82305b9c4106934d31a', result['params'][:commit])
441+
assert_equal('codecov/ci-repo', result['params'][:slug])
442+
assert_equal('1', result['params'][:build])
443+
assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
444+
end
445+
414446
def test_gitlab
415447
ENV['GITLAB_CI'] = 'true'
416448
ENV['CI_BUILD_REF_NAME'] = 'master'

0 commit comments

Comments
 (0)