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

Commit c0db3b2

Browse files
Specify gem version only once (#40)
* Specify gem version only once * Fix gem version to current one * Update version * rubocop * simplecov as a dev dependency * Remove? * Use separate file for version Co-authored-by: Thomas Hu <[email protected]> Co-authored-by: Thomas Hu <[email protected]>
1 parent 3fe7460 commit c0db3b2

5 files changed

Lines changed: 20 additions & 13 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/version.rb | grep 'LATEST = ' | cut -d\' -f2))
55
git tag v$(VERSION) -m ""
66
git push origin v$(VERSION)
77
gem build codecov.gemspec

codecov.gemspec

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

3+
lib = File.expand_path('lib', __dir__)
4+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5+
require 'version'
6+
37
Gem::Specification.new do |s|
48
s.name = 'codecov'
5-
s.version = '0.2.3'
9+
s.version = Version::LATEST
610
s.platform = Gem::Platform::RUBY
711
s.authors = ['codecov']
812
s.email = ['[email protected]']

lib/codecov.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
require 'colorize'
88
require 'zlib'
99

10-
class SimpleCov::Formatter::Codecov
11-
VERSION = '0.2.3'
10+
require 'version'
1211

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

104104
case ci
@@ -317,7 +317,7 @@ def retry_request(req, https)
317317
def create_report(report)
318318
result = {
319319
'meta' => {
320-
'version' => 'codecov-ruby/v' + SimpleCov::Formatter::Codecov::VERSION
320+
'version' => 'codecov-ruby/v' + Version::LATEST
321321
}
322322
}
323323
result.update(result_to_codecov(report))

lib/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+
class Version
4+
LATEST = '0.2.3'
5+
end

test/test_codecov.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def url
3535

3636
def test_defined
3737
assert defined?(SimpleCov::Formatter::Codecov)
38-
assert defined?(SimpleCov::Formatter::Codecov::VERSION)
38+
assert defined?(Version::LATEST)
3939
end
4040

4141
def stub_file(filename, coverage)
@@ -50,7 +50,7 @@ def stub_file(filename, coverage)
5050
stub('SimpleCov::SourceFile', filename: filename, lines: lines)
5151
end
5252

53-
def upload(success=true)
53+
def upload(success = true)
5454
formatter = SimpleCov::Formatter::Codecov.new
5555
result = stub('SimpleCov::Result', files: [
5656
stub_file('/path/lib/something.rb', [1, 0, 0, nil, 1, nil]),
@@ -61,9 +61,7 @@ def upload(success=true)
6161
data = formatter.format(result, false)
6262
puts data
6363
puts data['params']
64-
if success
65-
assert_successful_upload(data)
66-
end
64+
assert_successful_upload(data) if success
6765
WebMock.reset!
6866
data
6967
end
@@ -85,7 +83,7 @@ def success_stubs
8583
def assert_successful_upload(data)
8684
assert_equal(data['result']['uploaded'], true)
8785
assert_equal(data['result']['message'], 'Coverage reports upload successfully')
88-
assert_equal(data['meta']['version'], 'codecov-ruby/v' + SimpleCov::Formatter::Codecov::VERSION)
86+
assert_equal(data['meta']['version'], 'codecov-ruby/v' + Version::LATEST)
8987
assert_equal(data['coverage'].to_json, {
9088
'lib/something.rb' => [nil, 1, 0, 0, nil, 1, nil],
9189
'lib/somefile.rb' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil]

0 commit comments

Comments
 (0)