codecov 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/codecov.rb +17 -5
  3. data/test/test_codecov.rb +62 -21
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b59d7f1fb16986a207023da3b8f2130b4014084cf7d73d688c304e761c683513
4
- data.tar.gz: 68ba0cc7cd7cc16d84e88dd2bf20db83f69872eb540de4e9d4128ec0e889888f
3
+ metadata.gz: bc1716ae9ed1cf09a8e880633b225b27e9d4df5706dc7fb12137bcb4297b3a56
4
+ data.tar.gz: deead52d64bb597c8c96de120f0b45156d564a43b7429a48b30f45a66370cb49
5
5
  SHA512:
6
- metadata.gz: c636171303865424027efcfe53b8de75a1b860dc21f70bc43b65d11ea81eb6c1805c4d7a49ab650e7a0dbda992bdfd78e72aa2c6fd881f8d983859bde850ca80
7
- data.tar.gz: b9fc5e08981827a1dc873410222e7590baa41d8c8ba7563803edb35e29d9d2fd2b307a1a3ef85f7893bfd93ef27e79541e419c5cb6842b2ca7564663790a928e
6
+ metadata.gz: 26b3a8a151fabb896829b3cc6c0baf60582ab0bb351f2a2ce51156a5302d0b4cbfcd551172d002d114d369e677e14998dd27f3343d92ef16723332162a5eecf0
7
+ data.tar.gz: e96ce1b8daa6883a6671b544f5cadff5446ea2572c982b2f913e25f104205fefa353e41ec08a49d0e1e9337b736e23f400358b56724c686b614dd07abf7f6f7e
@@ -7,9 +7,9 @@ require 'simplecov'
7
7
  require 'colorize'
8
8
  require 'zlib'
9
9
 
10
- class SimpleCov::Formatter::Codecov
11
- VERSION = '0.2.3'
10
+ require 'version'
12
11
 
12
+ class SimpleCov::Formatter::Codecov
13
13
  ### CIs
14
14
  RECOGNIZED_CIS = [
15
15
  APPVEYOR = 'Appveyor CI',
@@ -20,6 +20,7 @@ class SimpleCov::Formatter::Codecov
20
20
  CIRCLE = 'Circle CI',
21
21
  CODESHIP = 'Codeship CI',
22
22
  DRONEIO = 'Drone CI',
23
+ GITHUB = 'GitHub Actions',
23
24
  GITLAB = 'GitLab CI',
24
25
  HEROKU = 'Heroku CI',
25
26
  JENKINS = 'Jenkins CI',
@@ -40,7 +41,7 @@ class SimpleCov::Formatter::Codecov
40
41
  '| | / _ \ / _\`|/ _ \/ __/ _ \ \ / /',
41
42
  '| |___| (_) | (_| | __/ (_| (_) \ V /',
42
43
  ' \_____\___/ \__,_|\___|\___\___/ \_/',
43
- " Ruby-#{VERSION}",
44
+ " Ruby-#{Version::LATEST}",
44
45
  ''
45
46
  ].join("\n")
46
47
  end
@@ -62,6 +63,8 @@ class SimpleCov::Formatter::Codecov
62
63
  CODESHIP
63
64
  elsif ((ENV['CI'] == 'true') || (ENV['CI'] == 'drone')) && (ENV['DRONE'] == 'true')
64
65
  DRONEIO
66
+ elsif (ENV['CI'] == 'true') && (ENV['GITHUB_ACTIONS'] == 'true')
67
+ GITHUB
65
68
  elsif !ENV['GITLAB_CI'].nil?
66
69
  GITLAB
67
70
  elsif ENV['HEROKU_TEST_RUN_ID']
@@ -95,7 +98,7 @@ class SimpleCov::Formatter::Codecov
95
98
  params = {
96
99
  'token' => ENV['CODECOV_TOKEN'],
97
100
  'flags' => ENV['CODECOV_FLAG'] || ENV['CODECOV_FLAGS'],
98
- 'package' => "ruby-#{VERSION}"
101
+ 'package' => "ruby-#{Version::LATEST}"
99
102
  }
100
103
 
101
104
  case ci
@@ -172,6 +175,15 @@ class SimpleCov::Formatter::Codecov
172
175
  params[:build_url] = ENV['DRONE_BUILD_LINK'] || ENV['DRONE_BUILD_URL'] || ENV['CI_BUILD_URL']
173
176
  params[:pr] = ENV['DRONE_PULL_REQUEST']
174
177
  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']
175
187
  when GITLAB
176
188
  # http://doc.gitlab.com/ci/examples/README.html#environmental-variables
177
189
  # https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb#L96
@@ -305,7 +317,7 @@ class SimpleCov::Formatter::Codecov
305
317
  def create_report(report)
306
318
  result = {
307
319
  'meta' => {
308
- 'version' => 'codecov-ruby/v' + SimpleCov::Formatter::Codecov::VERSION
320
+ 'version' => 'codecov-ruby/v' + Version::LATEST
309
321
  }
310
322
  }
311
323
  result.update(result_to_codecov(report))
@@ -3,21 +3,39 @@
3
3
  require 'helper'
4
4
 
5
5
  class TestCodecov < Minitest::Test
6
- REALENV = {
7
- 'TRAVIS_BRANCH' => ENV['TRAVIS_BRANCH'],
8
- 'TRAVIS_COMMIT' => ENV['TRAVIS_COMMIT'],
9
- 'TRAVIS_REPO_SLUG' => ENV['TRAVIS_REPO_SLUG'],
10
- 'TRAVIS_JOB_NUMBER' => ENV['TRAVIS_JOB_NUMBER'],
11
- 'TRAVIS_PULL_REQUEST' => ENV['TRAVIS_PULL_REQUEST'],
12
- 'TRAVIS_JOB_ID' => ENV['TRAVIS_JOB_ID']
13
- }.freeze
6
+ CI = SimpleCov::Formatter::Codecov.new.detect_ci
7
+
8
+ REALENV =
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
19
+ {
20
+ 'TRAVIS' => ENV['TRAVIS'],
21
+ 'TRAVIS_BRANCH' => ENV['TRAVIS_BRANCH'],
22
+ 'TRAVIS_COMMIT' => ENV['TRAVIS_COMMIT'],
23
+ 'TRAVIS_REPO_SLUG' => ENV['TRAVIS_REPO_SLUG'],
24
+ 'TRAVIS_JOB_NUMBER' => ENV['TRAVIS_JOB_NUMBER'],
25
+ 'TRAVIS_PULL_REQUEST' => ENV['TRAVIS_PULL_REQUEST'],
26
+ 'TRAVIS_JOB_ID' => ENV['TRAVIS_JOB_ID']
27
+ }
28
+ else
29
+ {}
30
+ end.freeze
31
+
14
32
  def url
15
33
  ENV['CODECOV_URL'] || 'https://codecov.io'
16
34
  end
17
35
 
18
36
  def test_defined
19
37
  assert defined?(SimpleCov::Formatter::Codecov)
20
- assert defined?(SimpleCov::Formatter::Codecov::VERSION)
38
+ assert defined?(Version::LATEST)
21
39
  end
22
40
 
23
41
  def stub_file(filename, coverage)
@@ -32,7 +50,7 @@ class TestCodecov < Minitest::Test
32
50
  stub('SimpleCov::SourceFile', filename: filename, lines: lines)
33
51
  end
34
52
 
35
- def upload(success=true)
53
+ def upload(success = true)
36
54
  formatter = SimpleCov::Formatter::Codecov.new
37
55
  result = stub('SimpleCov::Result', files: [
38
56
  stub_file('/path/lib/something.rb', [1, 0, 0, nil, 1, nil]),
@@ -43,9 +61,7 @@ class TestCodecov < Minitest::Test
43
61
  data = formatter.format(result, false)
44
62
  puts data
45
63
  puts data['params']
46
- if success
47
- assert_successful_upload(data)
48
- end
64
+ assert_successful_upload(data) if success
49
65
  WebMock.reset!
50
66
  data
51
67
  end
@@ -67,7 +83,7 @@ class TestCodecov < Minitest::Test
67
83
  def assert_successful_upload(data)
68
84
  assert_equal(data['result']['uploaded'], true)
69
85
  assert_equal(data['result']['message'], 'Coverage reports upload successfully')
70
- assert_equal(data['meta']['version'], 'codecov-ruby/v' + SimpleCov::Formatter::Codecov::VERSION)
86
+ assert_equal(data['meta']['version'], 'codecov-ruby/v' + Version::LATEST)
71
87
  assert_equal(data['coverage'].to_json, {
72
88
  'lib/something.rb' => [nil, 1, 0, 0, nil, 1, nil],
73
89
  'lib/somefile.rb' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil]
@@ -76,6 +92,7 @@ class TestCodecov < Minitest::Test
76
92
 
77
93
  def setup
78
94
  ENV['CI'] = nil
95
+ ENV['GITHUB_ACTIONS'] = nil
79
96
  ENV['TRAVIS'] = nil
80
97
  end
81
98
 
@@ -150,6 +167,12 @@ class TestCodecov < Minitest::Test
150
167
  ENV['ghprbSourceBranch'] = nil
151
168
  ENV['GIT_BRANCH'] = nil
152
169
  ENV['GIT_COMMIT'] = nil
170
+ ENV['GITHUB_ACTIONS'] = nil
171
+ ENV['GITHUB_REF'] = nil
172
+ ENV['GITHUB_HEAD_REF'] = nil
173
+ ENV['GITHUB_REPOSITORY'] = nil
174
+ ENV['GITHUB_RUN_ID'] = nil
175
+ ENV['GITHUB_SHA'] = nil
153
176
  ENV['GITLAB_CI'] = nil
154
177
  ENV['HEROKU_TEST_RUN_ID'] = nil
155
178
  ENV['HEROKU_TEST_RUN_BRANCH'] = nil
@@ -165,13 +188,13 @@ class TestCodecov < Minitest::Test
165
188
  ENV['SEMAPHORE_REPO_SLUG'] = nil
166
189
  ENV['SHIPPABLE'] = nil
167
190
  ENV['TF_BUILD'] = nil
168
- ENV['TRAVIS'] = 'true'
169
- ENV['TRAVIS_BRANCH'] = REALENV['TRAVIS_BRANCH']
170
- ENV['TRAVIS_COMMIT'] = REALENV['TRAVIS_COMMIT']
171
- ENV['TRAVIS_JOB_ID'] = REALENV['TRAVIS_JOB_ID']
172
- ENV['TRAVIS_JOB_NUMBER'] = REALENV['TRAVIS_JOB_NUMBER']
173
- ENV['TRAVIS_PULL_REQUEST'] = REALENV['TRAVIS_PULL_REQUEST']
174
- ENV['TRAVIS_REPO_SLUG'] = REALENV['TRAVIS_REPO_SLUG']
191
+ ENV['TRAVIS'] = nil
192
+ ENV['TRAVIS_BRANCH'] = nil
193
+ ENV['TRAVIS_COMMIT'] = nil
194
+ ENV['TRAVIS_JOB_ID'] = nil
195
+ ENV['TRAVIS_JOB_NUMBER'] = nil
196
+ ENV['TRAVIS_PULL_REQUEST'] = nil
197
+ ENV['TRAVIS_REPO_SLUG'] = nil
175
198
  ENV['VCS_COMMIT_ID'] = nil
176
199
  ENV['WERCKER_GIT_BRANCH'] = nil
177
200
  ENV['WERCKER_GIT_COMMIT'] = nil
@@ -179,6 +202,8 @@ class TestCodecov < Minitest::Test
179
202
  ENV['WERCKER_GIT_REPOSITORY'] = nil
180
203
  ENV['WERCKER_MAIN_PIPELINE_STARTED'] = nil
181
204
  ENV['WORKSPACE'] = nil
205
+
206
+ REALENV.each_pair { |k, v| ENV[k] = v }
182
207
  end
183
208
 
184
209
  def test_git
@@ -400,6 +425,22 @@ class TestCodecov < Minitest::Test
400
425
  assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
401
426
  end
402
427
 
428
+ def test_github
429
+ ENV['CI'] = 'true'
430
+ ENV['GITHUB_ACTIONS'] = 'true'
431
+ ENV['GITHUB_REF'] = 'refs/head/master'
432
+ ENV['GITHUB_REPOSITORY'] = 'codecov/ci-repo'
433
+ ENV['GITHUB_RUN_ID'] = '1'
434
+ ENV['GITHUB_SHA'] = 'c739768fcac68144a3a6d82305b9c4106934d31a'
435
+ ENV['CODECOV_TOKEN'] = 'f881216b-b5c0-4eb1-8f21-b51887d1d506'
436
+ result = upload
437
+ assert_equal('github-actions', result['params'][:service])
438
+ assert_equal('c739768fcac68144a3a6d82305b9c4106934d31a', result['params'][:commit])
439
+ assert_equal('codecov/ci-repo', result['params'][:slug])
440
+ assert_equal('1', result['params'][:build])
441
+ assert_equal('f881216b-b5c0-4eb1-8f21-b51887d1d506', result['params']['token'])
442
+ end
443
+
403
444
  def test_gitlab
404
445
  ENV['GITLAB_CI'] = 'true'
405
446
  ENV['CI_BUILD_REF_NAME'] = 'master'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codecov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - codecov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-27 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize