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

Commit 484767f

Browse files
Return version constant, don't duplicate version value (#113)
* Return version constant, don't duplicate version value Kind of revert 6c2856e without regression of #84 because of `require_relative` instead of `$LOAD_PATH.unshift`. * Update lib/codecov/version.rb Co-authored-by: Tom Hu <thomasrockhu@users.noreply.github.com>
1 parent cdb562f commit 484767f

6 files changed

Lines changed: 18 additions & 11 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: test install build deploy
22

33
deploy:
4-
$(eval VERSION := $(shell cat lib/codecov.rb | grep 'VERSION = ' | cut -d\' -f2))
4+
$(eval VERSION := $(shell cat lib/codecov/version.rb | grep 'VERSION = ' | cut -d\' -f2))
55
git tag v$(VERSION) -m ""
66
git push origin v$(VERSION)
77
gem build codecov.gemspec

codecov.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative 'lib/codecov/version'
4+
35
Gem::Specification.new do |s|
46
s.name = 'codecov'
57
s.authors = ['Steve Peak', 'Tom Hu']
@@ -11,7 +13,7 @@ Gem::Specification.new do |s|
1113
s.license = 'MIT'
1214
s.platform = Gem::Platform::RUBY
1315
s.required_ruby_version = '~> 2.4'
14-
s.version = '0.2.13'
16+
s.version = ::Codecov::VERSION
1517

1618
s.add_dependency 'simplecov', '~> 0.18.0'
1719

lib/codecov.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
require 'simplecov'
77
require 'zlib'
88

9-
class SimpleCov::Formatter::Codecov
10-
VERSION = '0.2.13'
9+
require_relative 'codecov/version'
1110

11+
class SimpleCov::Formatter::Codecov
1212
### CIs
1313
RECOGNIZED_CIS = [
1414
APPVEYOR = 'Appveyor CI',
@@ -41,7 +41,7 @@ def display_header
4141
'| | / _ \ / _\`|/ _ \/ __/ _ \ \ / /',
4242
'| |___| (_) | (_| | __/ (_| (_) \ V /',
4343
' \_____\___/ \__,_|\___|\___\___/ \_/',
44-
" Ruby-#{VERSION}",
44+
" Ruby-#{::Codecov::VERSION}",
4545
''
4646
].join("\n")
4747
end
@@ -100,7 +100,7 @@ def build_params(ci)
100100
params = {
101101
'token' => ENV['CODECOV_TOKEN'],
102102
'flags' => ENV['CODECOV_FLAG'] || ENV['CODECOV_FLAGS'],
103-
'package' => "ruby-#{VERSION}"
103+
'package' => "ruby-#{::Codecov::VERSION}"
104104
}
105105

106106
case ci
@@ -336,7 +336,7 @@ def retry_request(req, https)
336336
def create_report(report)
337337
result = {
338338
'meta' => {
339-
'version' => 'codecov-ruby/v' + VERSION
339+
'version' => 'codecov-ruby/v' + ::Codecov::VERSION
340340
}
341341
}
342342
result.update(result_to_codecov(report))

lib/codecov/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
module Codecov
4+
VERSION = '0.2.13'
5+
end

test/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
SimpleCov.start do
88
add_filter '/test/'
99
end
10-
require 'codecov'
10+
require_relative '../lib/codecov'
1111
SimpleCov.formatter = SimpleCov::Formatter::Codecov if ENV['CI'] == 'true'
1212

1313
require 'minitest/autorun'

test/test_codecov.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'helper'
3+
require_relative 'helper'
44

55
class TestCodecov < Minitest::Test
66
CI = SimpleCov::Formatter::Codecov.new.detect_ci
@@ -47,7 +47,7 @@ def url
4747

4848
def test_defined
4949
assert defined?(SimpleCov::Formatter::Codecov)
50-
assert defined?(SimpleCov::Formatter::Codecov::VERSION)
50+
assert defined?(::Codecov::VERSION)
5151
end
5252

5353
def stub_file(filename, coverage)
@@ -96,7 +96,7 @@ def success_stubs
9696
def assert_successful_upload(data)
9797
assert_equal(data['result']['uploaded'], true)
9898
assert_equal(data['result']['message'], 'Coverage reports upload successfully')
99-
assert_equal(data['meta']['version'], 'codecov-ruby/v' + SimpleCov::Formatter::Codecov::VERSION)
99+
assert_equal(data['meta']['version'], 'codecov-ruby/v' + ::Codecov::VERSION)
100100
assert_equal(data['coverage'].to_json, {
101101
'lib/something.rb' => [nil, 1, 0, 0, nil, 1, nil],
102102
'lib/somefile.rb' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil]

0 commit comments

Comments
 (0)