codecov 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +127 -0
- data/LICENSE +21 -0
- data/README.md +111 -0
- data/lib/codecov.rb +4 -613
- data/lib/codecov/formatter.rb +126 -0
- data/lib/codecov/uploader.rb +546 -0
- data/lib/codecov/version.rb +1 -1
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3ac8f8595023909dff3989e3b5026a2f3959a1b5264f64abcbef36373535ec9
|
4
|
+
data.tar.gz: dc49c63c9cf98c9052f558c1556bd00963086947580d2eb00deaef201ec31aa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcec7277a8f503f2db6365c1233075d0ecb6727acf2d97e557b40725e0a097735749f64470ea120071e65a6488794875309c19759d7297431f43ea5f6c61100a
|
7
|
+
data.tar.gz: fb195f5011e4baa21f01a1c9131628d009b69ba500b499188bdf8c48b29b8630792307d955dedf4215e1f8ad16478bb5ef4a92cad011cf00e413e847a551153e
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
### `0.5.0`
|
2
|
+
- #137 Place uploader in try/rescue block and add pass_ci_if_error flag
|
3
|
+
|
4
|
+
### `0.4.3`
|
5
|
+
- #135 Shorten coverage message on formatter
|
6
|
+
|
7
|
+
### `0.4.2`
|
8
|
+
- #134 Wrap file creation in try/catch
|
9
|
+
|
10
|
+
### `0.4.1`
|
11
|
+
- #133 Write down to file when using the formatter
|
12
|
+
|
13
|
+
### `0.4.0`
|
14
|
+
- #130 Split uploader from formatter
|
15
|
+
|
16
|
+
### `0.3.0`
|
17
|
+
- #124 Ruby 3.0 support
|
18
|
+
- #125 open simplecov requirement to 0.21.x
|
19
|
+
|
20
|
+
### `0.2.15`
|
21
|
+
- #118 Include codecov/version in the gem
|
22
|
+
|
23
|
+
### `0.2.14`
|
24
|
+
- #107 Add EditorConfig file
|
25
|
+
- #113 Return version constant, don't duplicate version value
|
26
|
+
- #117 Update simplecov dependency versions
|
27
|
+
|
28
|
+
### `0.2.13`
|
29
|
+
- [#105](https://github.com/codecov/codecov-ruby/pull/105) Remove unnecessary dependency for ruby standard gem
|
30
|
+
- [#110](https://github.com/codecov/codecov-ruby/pull/110) Fix GitHub Actions
|
31
|
+
- [#111](https://github.com/codecov/codecov-ruby/pull/111) Fix branch name detection for GitHub Actions CI
|
32
|
+
|
33
|
+
### `0.2.12`
|
34
|
+
- [#102](https://github.com/codecov/codecov-ruby/pull/102) Fix value of params[:pr] when useing CodeBuild
|
35
|
+
|
36
|
+
### `0.2.11`
|
37
|
+
- Add vendor/ to invalid directories
|
38
|
+
|
39
|
+
### `0.2.10`
|
40
|
+
- Adds better logging on error cases
|
41
|
+
- Add more invalid directories in the network
|
42
|
+
|
43
|
+
### `0.2.9`
|
44
|
+
- Remove `String` specific colors
|
45
|
+
- Add support for Codebuild CI
|
46
|
+
|
47
|
+
### `0.2.8`
|
48
|
+
- Remove `colorize` dependency
|
49
|
+
|
50
|
+
### `0.2.7`
|
51
|
+
- Fix for enterprise users unable to upload using the v4 uploader
|
52
|
+
|
53
|
+
### `0.2.6`
|
54
|
+
- Fix issue with `push` events on GitHub Actions
|
55
|
+
|
56
|
+
### `0.2.5`
|
57
|
+
- Revert single use of VERSION
|
58
|
+
|
59
|
+
### `0.2.4`
|
60
|
+
- Adds support for GitHub Actions CI
|
61
|
+
|
62
|
+
### `0.2.3`
|
63
|
+
- Support uploads for jruby 9.1 and 9.2
|
64
|
+
|
65
|
+
### `0.2.2`
|
66
|
+
- Handle SocketError and better error handling of v4 failures
|
67
|
+
|
68
|
+
### `0.2.1`
|
69
|
+
- Properly handle 400 cases when using the v4 endpoint
|
70
|
+
|
71
|
+
### `0.2.0`
|
72
|
+
- move to the v4 upload endpoint with the v2 as a fallback
|
73
|
+
|
74
|
+
### `0.1.20`
|
75
|
+
- fix critical upload issues on V2 endpoint
|
76
|
+
|
77
|
+
### `0.1.19`
|
78
|
+
- fix colorize
|
79
|
+
|
80
|
+
### `0.1.18`
|
81
|
+
- refactor and move to use v2 endpoint
|
82
|
+
- use Timeout::Error
|
83
|
+
|
84
|
+
### `0.1.17`
|
85
|
+
- refactor upload method and add more logging
|
86
|
+
|
87
|
+
### `0.1.10`
|
88
|
+
- update numerous ci environments
|
89
|
+
- dont fail if cannot upload to codecov
|
90
|
+
|
91
|
+
### `0.1.3`
|
92
|
+
- add buildkite
|
93
|
+
|
94
|
+
### `0.1.2`
|
95
|
+
- add slug argument
|
96
|
+
- use slug for uploading
|
97
|
+
- add Accept to uploads
|
98
|
+
|
99
|
+
### `0.1.1`
|
100
|
+
- fix #6, thanks @justmatt
|
101
|
+
- add semaphore thread number
|
102
|
+
|
103
|
+
### `0.1.0`
|
104
|
+
- added more CircleCI env
|
105
|
+
|
106
|
+
### `0.0.11`
|
107
|
+
- send AppVeyor pr# with reports
|
108
|
+
|
109
|
+
### `0.0.10`
|
110
|
+
- fix AppVeyor for public repos
|
111
|
+
|
112
|
+
### `0.0.9`
|
113
|
+
- remove tmp.json creation
|
114
|
+
|
115
|
+
### `0.0.8`
|
116
|
+
- added more jenkins environment references
|
117
|
+
|
118
|
+
### `0.0.7`
|
119
|
+
- added GitLab CI Runner support
|
120
|
+
|
121
|
+
### `0.0.5`
|
122
|
+
- added line messages by @coderanger
|
123
|
+
- fixed skip lines during reporting by @coderanger
|
124
|
+
|
125
|
+
### `0.0.4`
|
126
|
+
- added more test
|
127
|
+
- added more CI providers
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Codecov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Codecov Ruby Uploader
|
2
|
+
|
3
|
+
## DEPRECATION WARNING
|
4
|
+
|
5
|
+
All versions of the Ruby uploader prior to `0.2.0` will no longer be supported
|
6
|
+
and will be removed from public use on or after *2020-08-17*.
|
7
|
+
Please upgrade to the latest versions to continue using this uploader.
|
8
|
+
|
9
|
+
[![Codecov](https://codecov.io/github/codecov/codecov-ruby/coverage.svg?branch=master)](https://codecov.io/github/codecov/codecov-ruby?branch=master)
|
10
|
+
[![Gem Version](https://badge.fury.io/rb/codecov.svg)](https://rubygems.org/gems/codecov)
|
11
|
+
[![Build Status](https://secure.travis-ci.org/codecov/codecov-ruby.svg?branch=master)](http://travis-ci.org/codecov/codecov-ruby)
|
12
|
+
[![Codecov](https://circleci.com/gh/codecov/codecov-ruby.svg?style=svg)](https://circleci.com/gh/codecov/codecov-ruby)
|
13
|
+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fcodecov-ruby.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fcodecov-ruby?ref=badge_shield)
|
14
|
+
|
15
|
+
|
16
|
+
[Codecov.io](https://codecov.io/) upload support for Ruby.
|
17
|
+
|
18
|
+
## Quick Start
|
19
|
+
|
20
|
+
Add to your `Gemfile`:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'codecov', require: false, group: 'test'
|
24
|
+
```
|
25
|
+
|
26
|
+
Add to the top of your `tests/helper.rb` file:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'simplecov'
|
30
|
+
SimpleCov.start
|
31
|
+
|
32
|
+
require 'codecov'
|
33
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
34
|
+
```
|
35
|
+
|
36
|
+
Add CI Environment Variable:
|
37
|
+
|
38
|
+
```sh
|
39
|
+
CODECOV_TOKEN="your repo token"
|
40
|
+
```
|
41
|
+
|
42
|
+
Find you repo token on your repo page at [codecov.io](https://codecov.io).
|
43
|
+
Repo tokens are **not** required for public repos on Travis-Ci, CircleCI, or AppVeyor CI.
|
44
|
+
|
45
|
+
## Supported CIs
|
46
|
+
| CI/CD |
|
47
|
+
| ----- |
|
48
|
+
| [AppVeyor CI](https://www.appveyor.com/) |
|
49
|
+
| [Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) |
|
50
|
+
| [Bitbucket Pipelines](https://bitbucket.org/product/features/pipelines) |
|
51
|
+
| [Bitrise CI](https://www.bitrise.io/) |
|
52
|
+
| [Buildkite CI](https://buildkite.com/) |
|
53
|
+
| [CodeBuild CI](https://aws.amazon.com/codebuild/) |
|
54
|
+
| [CodePipeline](https://aws.amazon.com/codepipeline/) |
|
55
|
+
| [Circle CI](https://circleci.com/) |
|
56
|
+
| [Codeship CI](https://codeship.com/) |
|
57
|
+
| [Drone CI](https://drone.io/) |
|
58
|
+
| [GitLab CI](https://docs.gitlab.com/ee/ci/) |
|
59
|
+
| [Heroku CI](https://www.heroku.com/continuous-integration) |
|
60
|
+
| [Jenkins CI](https://www.jenkins.io/) |
|
61
|
+
| [Semaphore CI](https://semaphoreci.com/) |
|
62
|
+
| [Shippable](https://www.shippable.com/) |
|
63
|
+
| [Solano CI](https://xebialabs.com/technology/solano-ci/) |
|
64
|
+
| [TeamCity CI](https://www.jetbrains.com/teamcity/) |
|
65
|
+
| [Travis CI](https://travis-ci.org/) |
|
66
|
+
| [Wercker CI](https://devcenter.wercker.com/) |
|
67
|
+
|
68
|
+
## Advanced Usage
|
69
|
+
|
70
|
+
#### Submit only in CI example
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
if ENV['CI'] == 'true'
|
74
|
+
require 'codecov'
|
75
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
## Useful Links
|
80
|
+
|
81
|
+
[FAQ](https://docs.codecov.io/docs/frequently-asked-questions)
|
82
|
+
[Recipe List](https://docs.codecov.io/docs/common-recipe-list)
|
83
|
+
[Error Reference](https://docs.codecov.io/docs/error-reference)
|
84
|
+
[Changelog](./CHANGELOG.md)
|
85
|
+
[Support](https://codecov.io/support)
|
86
|
+
[Community Boards](https://community.codecov.io)
|
87
|
+
|
88
|
+
## Caveats
|
89
|
+
|
90
|
+
1. There are known issues when `Simplecov.track_files` is enabled. We recommend that you require all code files in your tests so that SimpleCov can provide Codecov with properly mapped coverage report metrics. [codecov/support#133]( https://github.com/codecov/support/issues/133)
|
91
|
+
- https://github.com/colszowka/simplecov/blob/master/README.md#default-root-filter-and-coverage-for-things-outside-of-it
|
92
|
+
2. `git` must be installed.
|
93
|
+
- https://github.com/codecov/codecov-ruby/blob/5e3dae3/lib/codecov.rb#L284-L295
|
94
|
+
|
95
|
+
## Maintainers
|
96
|
+
|
97
|
+
- [thomasrockhu](https://github.com/thomasrockhu)
|
98
|
+
|
99
|
+
## Enterprise
|
100
|
+
|
101
|
+
For companies using Codecov Enterprise you will need to specify the following parameters:
|
102
|
+
|
103
|
+
```sh
|
104
|
+
CODECOV_URL="https://codecov.mycompany.com"
|
105
|
+
CODECOV_SLUG="owner/repo"
|
106
|
+
CODECOV_TOKEN="repository token or global token"
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
## License
|
111
|
+
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fcodecov-ruby.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fcodecov-ruby?ref=badge_large)
|
data/lib/codecov.rb
CHANGED
@@ -6,621 +6,12 @@ require 'net/http'
|
|
6
6
|
require 'simplecov'
|
7
7
|
require 'zlib'
|
8
8
|
|
9
|
-
require_relative 'codecov/
|
9
|
+
require_relative 'codecov/formatter'
|
10
|
+
require_relative 'codecov/uploader'
|
10
11
|
|
11
12
|
class SimpleCov::Formatter::Codecov
|
12
|
-
### CIs
|
13
|
-
RECOGNIZED_CIS = [
|
14
|
-
APPVEYOR = 'Appveyor CI',
|
15
|
-
AZUREPIPELINES = 'Azure Pipelines',
|
16
|
-
BITBUCKET = 'Bitbucket',
|
17
|
-
BITRISE = 'Bitrise CI',
|
18
|
-
BUILDKITE = 'Buildkite CI',
|
19
|
-
CIRCLE = 'Circle CI',
|
20
|
-
CODEBUILD = 'Codebuild CI',
|
21
|
-
CODESHIP = 'Codeship CI',
|
22
|
-
DRONEIO = 'Drone CI',
|
23
|
-
GITHUB = 'GitHub Actions',
|
24
|
-
GITLAB = 'GitLab CI',
|
25
|
-
HEROKU = 'Heroku CI',
|
26
|
-
JENKINS = 'Jenkins CI',
|
27
|
-
SEMAPHORE = 'Semaphore CI',
|
28
|
-
SHIPPABLE = 'Shippable',
|
29
|
-
SOLANO = 'Solano CI',
|
30
|
-
TEAMCITY = 'TeamCity CI',
|
31
|
-
TRAVIS = 'Travis CI',
|
32
|
-
WERCKER = 'Wercker CI'
|
33
|
-
].freeze
|
34
|
-
|
35
|
-
def display_header
|
36
|
-
puts [
|
37
|
-
'',
|
38
|
-
' _____ _',
|
39
|
-
' / ____| | |',
|
40
|
-
'| | ___ __| | ___ ___ _____ __',
|
41
|
-
'| | / _ \ / _\`|/ _ \/ __/ _ \ \ / /',
|
42
|
-
'| |___| (_) | (_| | __/ (_| (_) \ V /',
|
43
|
-
' \_____\___/ \__,_|\___|\___\___/ \_/',
|
44
|
-
" Ruby-#{::Codecov::VERSION}",
|
45
|
-
''
|
46
|
-
].join("\n")
|
47
|
-
end
|
48
|
-
|
49
|
-
def detect_ci
|
50
|
-
ci = if (ENV['CI'] == 'True') && (ENV['APPVEYOR'] == 'True')
|
51
|
-
APPVEYOR
|
52
|
-
elsif !ENV['TF_BUILD'].nil?
|
53
|
-
AZUREPIPELINES
|
54
|
-
elsif (ENV['CI'] == 'true') && !ENV['BITBUCKET_BRANCH'].nil?
|
55
|
-
BITBUCKET
|
56
|
-
elsif (ENV['CI'] == 'true') && (ENV['BITRISE_IO'] == 'true')
|
57
|
-
BITRISE
|
58
|
-
elsif (ENV['CI'] == 'true') && (ENV['BUILDKITE'] == 'true')
|
59
|
-
BUILDKITE
|
60
|
-
elsif (ENV['CI'] == 'true') && (ENV['CIRCLECI'] == 'true')
|
61
|
-
CIRCLE
|
62
|
-
elsif ENV['CODEBUILD_CI'] == 'true'
|
63
|
-
CODEBUILD
|
64
|
-
elsif (ENV['CI'] == 'true') && (ENV['CI_NAME'] == 'codeship')
|
65
|
-
CODESHIP
|
66
|
-
elsif ((ENV['CI'] == 'true') || (ENV['CI'] == 'drone')) && (ENV['DRONE'] == 'true')
|
67
|
-
DRONEIO
|
68
|
-
elsif (ENV['CI'] == 'true') && (ENV['GITHUB_ACTIONS'] == 'true')
|
69
|
-
GITHUB
|
70
|
-
elsif !ENV['GITLAB_CI'].nil?
|
71
|
-
GITLAB
|
72
|
-
elsif ENV['HEROKU_TEST_RUN_ID']
|
73
|
-
HEROKU
|
74
|
-
elsif !ENV['JENKINS_URL'].nil?
|
75
|
-
JENKINS
|
76
|
-
elsif (ENV['CI'] == 'true') && (ENV['SEMAPHORE'] == 'true')
|
77
|
-
SEMAPHORE
|
78
|
-
elsif (ENV['CI'] == 'true') && (ENV['SHIPPABLE'] == 'true')
|
79
|
-
SHIPPABLE
|
80
|
-
elsif ENV['TDDIUM'] == 'true'
|
81
|
-
SOLANO
|
82
|
-
elsif ENV['CI_SERVER_NAME'] == 'TeamCity'
|
83
|
-
TEAMCITY
|
84
|
-
elsif (ENV['CI'] == 'true') && (ENV['TRAVIS'] == 'true')
|
85
|
-
TRAVIS
|
86
|
-
elsif (ENV['CI'] == 'true') && !ENV['WERCKER_GIT_BRANCH'].nil?
|
87
|
-
WERCKER
|
88
|
-
end
|
89
|
-
|
90
|
-
if !RECOGNIZED_CIS.include?(ci)
|
91
|
-
puts [red('x>'), 'No CI provider detected.'].join(' ')
|
92
|
-
else
|
93
|
-
puts "==> #{ci} detected"
|
94
|
-
end
|
95
|
-
|
96
|
-
ci
|
97
|
-
end
|
98
|
-
|
99
|
-
def build_params(ci)
|
100
|
-
params = {
|
101
|
-
'token' => ENV['CODECOV_TOKEN'],
|
102
|
-
'flags' => ENV['CODECOV_FLAG'] || ENV['CODECOV_FLAGS'],
|
103
|
-
'package' => "ruby-#{::Codecov::VERSION}"
|
104
|
-
}
|
105
|
-
|
106
|
-
case ci
|
107
|
-
when APPVEYOR
|
108
|
-
# http://www.appveyor.com/docs/environment-variables
|
109
|
-
params[:service] = 'appveyor'
|
110
|
-
params[:branch] = ENV['APPVEYOR_REPO_BRANCH']
|
111
|
-
params[:build] = ENV['APPVEYOR_JOB_ID']
|
112
|
-
params[:pr] = ENV['APPVEYOR_PULL_REQUEST_NUMBER']
|
113
|
-
params[:job] = ENV['APPVEYOR_ACCOUNT_NAME'] + '/' + ENV['APPVEYOR_PROJECT_SLUG'] + '/' + ENV['APPVEYOR_BUILD_VERSION']
|
114
|
-
params[:slug] = ENV['APPVEYOR_REPO_NAME']
|
115
|
-
params[:commit] = ENV['APPVEYOR_REPO_COMMIT']
|
116
|
-
when AZUREPIPELINES
|
117
|
-
params[:service] = 'azure_pipelines'
|
118
|
-
params[:branch] = ENV['BUILD_SOURCEBRANCH']
|
119
|
-
params[:pull_request] = ENV['SYSTEM_PULLREQUEST_PULLREQUESTNUMBER']
|
120
|
-
params[:job] = ENV['SYSTEM_JOBID']
|
121
|
-
params[:build] = ENV['BUILD_BUILDID']
|
122
|
-
params[:build_url] = "#{ENV['SYSTEM_TEAMFOUNDATIONSERVERURI']}/#{ENV['SYSTEM_TEAMPROJECT']}/_build/results?buildId=#{ENV['BUILD_BUILDID']}"
|
123
|
-
params[:commit] = ENV['BUILD_SOURCEVERSION']
|
124
|
-
params[:slug] = ENV['BUILD_REPOSITORY_ID']
|
125
|
-
when BITBUCKET
|
126
|
-
# https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html
|
127
|
-
params[:service] = 'bitbucket'
|
128
|
-
params[:branch] = ENV['BITBUCKET_BRANCH']
|
129
|
-
# BITBUCKET_COMMIT does not always provide full commit sha due to a bug https://jira.atlassian.com/browse/BCLOUD-19393#
|
130
|
-
params[:commit] = (ENV['BITBUCKET_COMMIT'].length < 40 ? nil : ENV['BITBUCKET_COMMIT'])
|
131
|
-
params[:build] = ENV['BITBUCKET_BUILD_NUMBER']
|
132
|
-
when BITRISE
|
133
|
-
# http://devcenter.bitrise.io/faq/available-environment-variables/
|
134
|
-
params[:service] = 'bitrise'
|
135
|
-
params[:branch] = ENV['BITRISE_GIT_BRANCH']
|
136
|
-
params[:pr] = ENV['BITRISE_PULL_REQUEST']
|
137
|
-
params[:build] = ENV['BITRISE_BUILD_NUMBER']
|
138
|
-
params[:build_url] = ENV['BITRISE_BUILD_URL']
|
139
|
-
params[:commit] = ENV['BITRISE_GIT_COMMIT']
|
140
|
-
params[:slug] = ENV['BITRISEIO_GIT_REPOSITORY_OWNER'] + '/' + ENV['BITRISEIO_GIT_REPOSITORY_SLUG']
|
141
|
-
when BUILDKITE
|
142
|
-
# https://buildkite.com/docs/guides/environment-variables
|
143
|
-
params[:service] = 'buildkite'
|
144
|
-
params[:branch] = ENV['BUILDKITE_BRANCH']
|
145
|
-
params[:build] = ENV['BUILDKITE_BUILD_NUMBER']
|
146
|
-
params[:job] = ENV['BUILDKITE_JOB_ID']
|
147
|
-
params[:build_url] = ENV['BUILDKITE_BUILD_URL']
|
148
|
-
params[:slug] = ENV['BUILDKITE_PROJECT_SLUG']
|
149
|
-
params[:commit] = ENV['BUILDKITE_COMMIT']
|
150
|
-
when CIRCLE
|
151
|
-
# https://circleci.com/docs/environment-variables
|
152
|
-
params[:service] = 'circleci'
|
153
|
-
params[:build] = ENV['CIRCLE_BUILD_NUM']
|
154
|
-
params[:job] = ENV['CIRCLE_NODE_INDEX']
|
155
|
-
params[:slug] = if !ENV['CIRCLE_PROJECT_REPONAME'].nil?
|
156
|
-
ENV['CIRCLE_PROJECT_USERNAME'] + '/' + ENV['CIRCLE_PROJECT_REPONAME']
|
157
|
-
else
|
158
|
-
ENV['CIRCLE_REPOSITORY_URL'].gsub(/^.*:/, '').gsub(/\.git$/, '')
|
159
|
-
end
|
160
|
-
params[:pr] = ENV['CIRCLE_PR_NUMBER']
|
161
|
-
params[:branch] = ENV['CIRCLE_BRANCH']
|
162
|
-
params[:commit] = ENV['CIRCLE_SHA1']
|
163
|
-
when CODEBUILD
|
164
|
-
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
|
165
|
-
params[:service] = 'codebuild'
|
166
|
-
params[:branch] = ENV['CODEBUILD_WEBHOOK_HEAD_REF'].split('/')[2]
|
167
|
-
params[:build] = ENV['CODEBUILD_BUILD_ID']
|
168
|
-
params[:commit] = ENV['CODEBUILD_RESOLVED_SOURCE_VERSION']
|
169
|
-
params[:job] = ENV['CODEBUILD_BUILD_ID']
|
170
|
-
params[:slug] = ENV['CODEBUILD_SOURCE_REPO_URL'].match(/.*github.com\/(?<slug>.*).git/)['slug']
|
171
|
-
params[:pr] = if ENV['CODEBUILD_SOURCE_VERSION']
|
172
|
-
matched = ENV['CODEBUILD_SOURCE_VERSION'].match(%r{pr/(?<pr>.*)})
|
173
|
-
matched.nil? ? ENV['CODEBUILD_SOURCE_VERSION'] : matched['pr']
|
174
|
-
end
|
175
|
-
when CODESHIP
|
176
|
-
# https://www.codeship.io/documentation/continuous-integration/set-environment-variables/
|
177
|
-
params[:service] = 'codeship'
|
178
|
-
params[:branch] = ENV['CI_BRANCH']
|
179
|
-
params[:commit] = ENV['CI_COMMIT_ID']
|
180
|
-
params[:build] = ENV['CI_BUILD_NUMBER']
|
181
|
-
params[:build_url] = ENV['CI_BUILD_URL']
|
182
|
-
when DRONEIO
|
183
|
-
# https://semaphoreapp.com/docs/available-environment-variables.html
|
184
|
-
params[:service] = 'drone.io'
|
185
|
-
params[:branch] = ENV['DRONE_BRANCH']
|
186
|
-
params[:commit] = ENV['DRONE_COMMIT_SHA']
|
187
|
-
params[:job] = ENV['DRONE_JOB_NUMBER']
|
188
|
-
params[:build] = ENV['DRONE_BUILD_NUMBER']
|
189
|
-
params[:build_url] = ENV['DRONE_BUILD_LINK'] || ENV['DRONE_BUILD_URL'] || ENV['CI_BUILD_URL']
|
190
|
-
params[:pr] = ENV['DRONE_PULL_REQUEST']
|
191
|
-
params[:tag] = ENV['DRONE_TAG']
|
192
|
-
when GITHUB
|
193
|
-
# https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
|
194
|
-
params[:service] = 'github-actions'
|
195
|
-
if (ENV['GITHUB_HEAD_REF'] || '').empty?
|
196
|
-
params[:branch] = ENV['GITHUB_REF'].sub('refs/heads/', '')
|
197
|
-
else
|
198
|
-
params[:branch] = ENV['GITHUB_HEAD_REF']
|
199
|
-
# PR refs are in the format: refs/pull/7/merge for pull_request events
|
200
|
-
params[:pr] = ENV['GITHUB_REF'].split('/')[2]
|
201
|
-
end
|
202
|
-
params[:slug] = ENV['GITHUB_REPOSITORY']
|
203
|
-
params[:build] = ENV['GITHUB_RUN_ID']
|
204
|
-
params[:commit] = ENV['GITHUB_SHA']
|
205
|
-
when GITLAB
|
206
|
-
# http://doc.gitlab.com/ci/examples/README.html#environmental-variables
|
207
|
-
# https://gitlab.com/gitlab-org/gitlab-ci-runner/blob/master/lib/build.rb#L96
|
208
|
-
# GitLab Runner v9 renamed some environment variables, so we check both old and new variable names.
|
209
|
-
params[:service] = 'gitlab'
|
210
|
-
params[:branch] = ENV['CI_BUILD_REF_NAME'] || ENV['CI_COMMIT_REF_NAME']
|
211
|
-
params[:build] = ENV['CI_BUILD_ID'] || ENV['CI_JOB_ID']
|
212
|
-
slug = ENV['CI_BUILD_REPO'] || ENV['CI_REPOSITORY_URL']
|
213
|
-
params[:slug] = slug.split('/', 4)[-1].sub('.git', '') if slug
|
214
|
-
params[:commit] = ENV['CI_BUILD_REF'] || ENV['CI_COMMIT_SHA']
|
215
|
-
when HEROKU
|
216
|
-
params[:service] = 'heroku'
|
217
|
-
params[:branch] = ENV['HEROKU_TEST_RUN_BRANCH']
|
218
|
-
params[:build] = ENV['HEROKU_TEST_RUN_ID']
|
219
|
-
params[:commit] = ENV['HEROKU_TEST_RUN_COMMIT_VERSION']
|
220
|
-
when JENKINS
|
221
|
-
# https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project
|
222
|
-
# https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables
|
223
|
-
params[:service] = 'jenkins'
|
224
|
-
params[:branch] = ENV['ghprbSourceBranch'] || ENV['GIT_BRANCH']
|
225
|
-
params[:commit] = ENV['ghprbActualCommit'] || ENV['GIT_COMMIT']
|
226
|
-
params[:pr] = ENV['ghprbPullId']
|
227
|
-
params[:build] = ENV['BUILD_NUMBER']
|
228
|
-
params[:root] = ENV['WORKSPACE']
|
229
|
-
params[:build_url] = ENV['BUILD_URL']
|
230
|
-
when SEMAPHORE
|
231
|
-
# https://semaphoreapp.com/docs/available-environment-variables.html
|
232
|
-
params[:service] = 'semaphore'
|
233
|
-
params[:branch] = ENV['BRANCH_NAME']
|
234
|
-
params[:commit] = ENV['REVISION']
|
235
|
-
params[:build] = ENV['SEMAPHORE_BUILD_NUMBER']
|
236
|
-
params[:job] = ENV['SEMAPHORE_CURRENT_THREAD']
|
237
|
-
params[:slug] = ENV['SEMAPHORE_REPO_SLUG']
|
238
|
-
when SHIPPABLE
|
239
|
-
# http://docs.shippable.com/en/latest/config.html#common-environment-variables
|
240
|
-
params[:service] = 'shippable'
|
241
|
-
params[:branch] = ENV['BRANCH']
|
242
|
-
params[:build] = ENV['BUILD_NUMBER']
|
243
|
-
params[:build_url] = ENV['BUILD_URL']
|
244
|
-
params[:pull_request] = ENV['PULL_REQUEST']
|
245
|
-
params[:slug] = ENV['REPO_NAME']
|
246
|
-
params[:commit] = ENV['COMMIT']
|
247
|
-
when SOLANO
|
248
|
-
# http://docs.solanolabs.com/Setup/tddium-set-environment-variables/
|
249
|
-
params[:service] = 'solano'
|
250
|
-
params[:branch] = ENV['TDDIUM_CURRENT_BRANCH']
|
251
|
-
params[:commit] = ENV['TDDIUM_CURRENT_COMMIT']
|
252
|
-
params[:build] = ENV['TDDIUM_TID']
|
253
|
-
params[:pr] = ENV['TDDIUM_PR_ID']
|
254
|
-
when TEAMCITY
|
255
|
-
# https://confluence.jetbrains.com/display/TCD8/Predefined+Build+Parameters
|
256
|
-
# Teamcity does not automatically make build parameters available as environment variables.
|
257
|
-
# Add the following environment parameters to the build configuration
|
258
|
-
# env.TEAMCITY_BUILD_BRANCH = %teamcity.build.branch%
|
259
|
-
# env.TEAMCITY_BUILD_ID = %teamcity.build.id%
|
260
|
-
# env.TEAMCITY_BUILD_URL = %teamcity.serverUrl%/viewLog.html?buildId=%teamcity.build.id%
|
261
|
-
# env.TEAMCITY_BUILD_COMMIT = %system.build.vcs.number%
|
262
|
-
# env.TEAMCITY_BUILD_REPOSITORY = %vcsroot.<YOUR TEAMCITY VCS NAME>.url%
|
263
|
-
params[:service] = 'teamcity'
|
264
|
-
params[:branch] = ENV['TEAMCITY_BUILD_BRANCH']
|
265
|
-
params[:build] = ENV['TEAMCITY_BUILD_ID']
|
266
|
-
params[:build_url] = ENV['TEAMCITY_BUILD_URL']
|
267
|
-
params[:commit] = ENV['TEAMCITY_BUILD_COMMIT']
|
268
|
-
params[:slug] = ENV['TEAMCITY_BUILD_REPOSITORY'].split('/', 4)[-1].sub('.git', '')
|
269
|
-
when TRAVIS
|
270
|
-
# http://docs.travis-ci.com/user/ci-environment/#Environment-variables
|
271
|
-
params[:service] = 'travis'
|
272
|
-
params[:branch] = ENV['TRAVIS_BRANCH']
|
273
|
-
params[:pull_request] = ENV['TRAVIS_PULL_REQUEST']
|
274
|
-
params[:job] = ENV['TRAVIS_JOB_ID']
|
275
|
-
params[:slug] = ENV['TRAVIS_REPO_SLUG']
|
276
|
-
params[:build] = ENV['TRAVIS_JOB_NUMBER']
|
277
|
-
params[:commit] = ENV['TRAVIS_COMMIT']
|
278
|
-
params[:env] = ENV['TRAVIS_RUBY_VERSION']
|
279
|
-
when WERCKER
|
280
|
-
# http://devcenter.wercker.com/articles/steps/variables.html
|
281
|
-
params[:service] = 'wercker'
|
282
|
-
params[:branch] = ENV['WERCKER_GIT_BRANCH']
|
283
|
-
params[:build] = ENV['WERCKER_MAIN_PIPELINE_STARTED']
|
284
|
-
params[:slug] = ENV['WERCKER_GIT_OWNER'] + '/' + ENV['WERCKER_GIT_REPOSITORY']
|
285
|
-
params[:commit] = ENV['WERCKER_GIT_COMMIT']
|
286
|
-
end
|
287
|
-
|
288
|
-
if params[:branch].nil?
|
289
|
-
# find branch, commit, repo from git command
|
290
|
-
branch = `git rev-parse --abbrev-ref HEAD`.strip
|
291
|
-
params[:branch] = branch != 'HEAD' ? branch : 'master'
|
292
|
-
end
|
293
|
-
|
294
|
-
if !ENV['VCS_COMMIT_ID'].nil?
|
295
|
-
params[:commit] = ENV['VCS_COMMIT_ID']
|
296
|
-
|
297
|
-
elsif params[:commit].nil?
|
298
|
-
params[:commit] = `git rev-parse HEAD`.strip
|
299
|
-
end
|
300
|
-
|
301
|
-
slug = ENV['CODECOV_SLUG']
|
302
|
-
params[:slug] = slug unless slug.nil?
|
303
|
-
|
304
|
-
params[:pr] = params[:pr].sub('#', '') unless params[:pr].nil?
|
305
|
-
|
306
|
-
params
|
307
|
-
end
|
308
|
-
|
309
|
-
def retry_request(req, https)
|
310
|
-
retries = 3
|
311
|
-
begin
|
312
|
-
response = https.request(req)
|
313
|
-
rescue Timeout::Error, SocketError => e
|
314
|
-
retries -= 1
|
315
|
-
|
316
|
-
if retries.zero?
|
317
|
-
puts 'Timeout or connection error uploading coverage reports to Codecov. Out of retries.'
|
318
|
-
puts e
|
319
|
-
return response
|
320
|
-
end
|
321
|
-
|
322
|
-
puts 'Timeout or connection error uploading coverage reports to Codecov. Retrying...'
|
323
|
-
puts e
|
324
|
-
retry
|
325
|
-
rescue StandardError => e
|
326
|
-
puts 'Error uploading coverage reports to Codecov. Sorry'
|
327
|
-
puts e.class.name
|
328
|
-
puts e
|
329
|
-
puts "Backtrace:\n\t#{e.backtrace}"
|
330
|
-
return response
|
331
|
-
end
|
332
|
-
|
333
|
-
response
|
334
|
-
end
|
335
|
-
|
336
|
-
def create_report(report)
|
337
|
-
result = {
|
338
|
-
'meta' => {
|
339
|
-
'version' => 'codecov-ruby/v' + ::Codecov::VERSION
|
340
|
-
}
|
341
|
-
}
|
342
|
-
result.update(result_to_codecov(report))
|
343
|
-
result
|
344
|
-
end
|
345
|
-
|
346
|
-
def gzip_report(report)
|
347
|
-
puts [green('==>'), 'Gzipping contents'].join(' ')
|
348
|
-
|
349
|
-
io = StringIO.new
|
350
|
-
gzip = Zlib::GzipWriter.new(io)
|
351
|
-
gzip << report
|
352
|
-
gzip.close
|
353
|
-
|
354
|
-
io.string
|
355
|
-
end
|
356
|
-
|
357
|
-
def upload_to_codecov(ci, report)
|
358
|
-
url = ENV['CODECOV_URL'] || 'https://codecov.io'
|
359
|
-
is_enterprise = url != 'https://codecov.io'
|
360
|
-
|
361
|
-
params = build_params(ci)
|
362
|
-
params_secret_token = params.clone
|
363
|
-
params_secret_token['token'] = 'secret'
|
364
|
-
|
365
|
-
query = URI.encode_www_form(params)
|
366
|
-
query_without_token = URI.encode_www_form(params_secret_token)
|
367
|
-
|
368
|
-
gzipped_report = gzip_report(report['codecov'])
|
369
|
-
|
370
|
-
report['params'] = params
|
371
|
-
report['query'] = query
|
372
|
-
|
373
|
-
puts [green('==>'), 'Uploading reports'].join(' ')
|
374
|
-
puts " url: #{url}"
|
375
|
-
puts " query: #{query_without_token}"
|
376
|
-
|
377
|
-
response = false
|
378
|
-
unless is_enterprise
|
379
|
-
response = upload_to_v4(url, gzipped_report, query, query_without_token)
|
380
|
-
return false if response == false
|
381
|
-
end
|
382
|
-
|
383
|
-
response || upload_to_v2(url, gzipped_report, query, query_without_token)
|
384
|
-
end
|
385
|
-
|
386
|
-
def upload_to_v4(url, report, query, query_without_token)
|
387
|
-
uri = URI.parse(url.chomp('/') + '/upload/v4')
|
388
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
389
|
-
https.use_ssl = !url.match(/^https/).nil?
|
390
|
-
|
391
|
-
puts [green('-> '), 'Pinging Codecov'].join(' ')
|
392
|
-
puts "#{url}#{uri.path}?#{query_without_token}"
|
393
|
-
|
394
|
-
req = Net::HTTP::Post.new(
|
395
|
-
"#{uri.path}?#{query}",
|
396
|
-
{
|
397
|
-
'X-Reduced-Redundancy' => 'false',
|
398
|
-
'X-Content-Encoding' => 'application/x-gzip',
|
399
|
-
'Content-Type' => 'text/plain'
|
400
|
-
}
|
401
|
-
)
|
402
|
-
response = retry_request(req, https)
|
403
|
-
if !response&.code || response.code == '400'
|
404
|
-
puts red(response&.body)
|
405
|
-
return false
|
406
|
-
end
|
407
|
-
|
408
|
-
reports_url = response.body.lines[0]
|
409
|
-
s3target = response.body.lines[1]
|
410
|
-
puts [green('-> '), 'Uploading to'].join(' ')
|
411
|
-
puts s3target
|
412
|
-
|
413
|
-
uri = URI(s3target)
|
414
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
415
|
-
https.use_ssl = true
|
416
|
-
req = Net::HTTP::Put.new(
|
417
|
-
s3target,
|
418
|
-
{
|
419
|
-
'Content-Encoding' => 'gzip',
|
420
|
-
'Content-Type' => 'text/plain'
|
421
|
-
}
|
422
|
-
)
|
423
|
-
req.body = report
|
424
|
-
res = retry_request(req, https)
|
425
|
-
if res&.body == ''
|
426
|
-
{
|
427
|
-
'uploaded' => true,
|
428
|
-
'url' => reports_url,
|
429
|
-
'meta' => {
|
430
|
-
'status' => res.code
|
431
|
-
},
|
432
|
-
'message' => 'Coverage reports upload successfully'
|
433
|
-
}.to_json
|
434
|
-
else
|
435
|
-
puts [black('-> '), 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
|
436
|
-
puts red(res&.body || 'nil')
|
437
|
-
nil
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
def upload_to_v2(url, report, query, query_without_token)
|
442
|
-
uri = URI.parse(url.chomp('/') + '/upload/v2')
|
443
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
444
|
-
https.use_ssl = !url.match(/^https/).nil?
|
445
|
-
|
446
|
-
puts [green('-> '), 'Uploading to Codecov'].join(' ')
|
447
|
-
puts "#{url}#{uri.path}?#{query_without_token}"
|
448
|
-
|
449
|
-
req = Net::HTTP::Post.new(
|
450
|
-
"#{uri.path}?#{query}",
|
451
|
-
{
|
452
|
-
'Accept' => 'application/json',
|
453
|
-
'Content-Encoding' => 'gzip',
|
454
|
-
'Content-Type' => 'text/plain',
|
455
|
-
'X-Content-Encoding' => 'gzip'
|
456
|
-
}
|
457
|
-
)
|
458
|
-
req.body = report
|
459
|
-
res = retry_request(req, https)
|
460
|
-
res&.body
|
461
|
-
end
|
462
|
-
|
463
|
-
def handle_report_response(report)
|
464
|
-
if report['result']['uploaded']
|
465
|
-
puts " View reports at #{report['result']['url']}"
|
466
|
-
else
|
467
|
-
puts red(' X> Failed to upload coverage reports')
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
13
|
def format(result, disable_net_blockers = true)
|
472
|
-
|
473
|
-
|
474
|
-
display_header
|
475
|
-
ci = detect_ci
|
476
|
-
report = create_report(result)
|
477
|
-
response = upload_to_codecov(ci, report)
|
478
|
-
if response == false
|
479
|
-
report['result'] = { 'uploaded' => false }
|
480
|
-
return report
|
481
|
-
end
|
482
|
-
|
483
|
-
report['result'] = JSON.parse(response)
|
484
|
-
handle_report_response(report)
|
485
|
-
|
486
|
-
net_blockers(:on) if disable_net_blockers
|
487
|
-
report
|
488
|
-
end
|
489
|
-
|
490
|
-
private
|
491
|
-
|
492
|
-
# Format SimpleCov coverage data for the Codecov.io API.
|
493
|
-
#
|
494
|
-
# @param result [SimpleCov::Result] The coverage data to process.
|
495
|
-
# @return [Hash]
|
496
|
-
def result_to_codecov(result)
|
497
|
-
{
|
498
|
-
'codecov' => result_to_codecov_report(result),
|
499
|
-
'coverage' => result_to_codecov_coverage(result),
|
500
|
-
'messages' => result_to_codecov_messages(result)
|
501
|
-
}
|
502
|
-
end
|
503
|
-
|
504
|
-
def result_to_codecov_report(result)
|
505
|
-
report = file_network.join("\n").concat("\n")
|
506
|
-
report = report.concat({ 'coverage' => result_to_codecov_coverage(result) }.to_json)
|
507
|
-
report
|
508
|
-
end
|
509
|
-
|
510
|
-
def file_network
|
511
|
-
invalid_file_types = [
|
512
|
-
'woff', 'eot', 'otf', # fonts
|
513
|
-
'gif', 'png', 'jpg', 'jpeg', 'psd', # images
|
514
|
-
'ptt', 'pptx', 'numbers', 'pages', 'md', 'txt', 'xlsx', 'docx', 'doc', 'pdf', 'csv', # docs
|
515
|
-
'yml', 'yaml', '.gitignore'
|
516
|
-
].freeze
|
517
|
-
|
518
|
-
invalid_directories = [
|
519
|
-
'node_modules/',
|
520
|
-
'public/',
|
521
|
-
'storage/',
|
522
|
-
'tmp/',
|
523
|
-
'vendor/'
|
524
|
-
]
|
525
|
-
|
526
|
-
puts [green('==>'), 'Appending file network'].join(' ')
|
527
|
-
network = []
|
528
|
-
Dir['**/*'].keep_if do |file|
|
529
|
-
if File.file?(file) && !file.end_with?(*invalid_file_types) && invalid_directories.none? { |dir| file.include?(dir) }
|
530
|
-
network.push(file)
|
531
|
-
end
|
532
|
-
end
|
533
|
-
|
534
|
-
network.push('<<<<<< network')
|
535
|
-
network
|
536
|
-
end
|
537
|
-
|
538
|
-
# Format SimpleCov coverage data for the Codecov.io coverage API.
|
539
|
-
#
|
540
|
-
# @param result [SimpleCov::Result] The coverage data to process.
|
541
|
-
# @return [Hash<String, Array>]
|
542
|
-
def result_to_codecov_coverage(result)
|
543
|
-
result.files.each_with_object({}) do |file, memo|
|
544
|
-
memo[shortened_filename(file)] = file_to_codecov(file)
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
# Format SimpleCov coverage data for the Codecov.io messages API.
|
549
|
-
#
|
550
|
-
# @param result [SimpleCov::Result] The coverage data to process.
|
551
|
-
# @return [Hash<String, Hash>]
|
552
|
-
def result_to_codecov_messages(result)
|
553
|
-
result.files.each_with_object({}) do |file, memo|
|
554
|
-
memo[shortened_filename(file)] = file.lines.each_with_object({}) do |line, lines_memo|
|
555
|
-
lines_memo[line.line_number.to_s] = 'skipped' if line.skipped?
|
556
|
-
end
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
# Format coverage data for a single file for the Codecov.io API.
|
561
|
-
#
|
562
|
-
# @param file [SimpleCov::SourceFile] The file to process.
|
563
|
-
# @return [Array<nil, Integer>]
|
564
|
-
def file_to_codecov(file)
|
565
|
-
# Initial nil is required to offset line numbers.
|
566
|
-
[nil] + file.lines.map do |line|
|
567
|
-
if line.skipped?
|
568
|
-
nil
|
569
|
-
else
|
570
|
-
line.coverage
|
571
|
-
end
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
# Get a filename relative to the project root. Based on
|
576
|
-
# https://github.com/colszowka/simplecov-html, copyright Christoph Olszowka.
|
577
|
-
#
|
578
|
-
# @param file [SimeplCov::SourceFile] The file to use.
|
579
|
-
# @return [String]
|
580
|
-
def shortened_filename(file)
|
581
|
-
file.filename.gsub(/^#{SimpleCov.root}/, '.').gsub(%r{^\./}, '')
|
582
|
-
end
|
583
|
-
|
584
|
-
# Toggle VCR and WebMock on or off
|
585
|
-
#
|
586
|
-
# @param switch Toggle switch for Net Blockers.
|
587
|
-
# @return [Boolean]
|
588
|
-
def net_blockers(switch)
|
589
|
-
throw 'Only :on or :off' unless %i[on off].include? switch
|
590
|
-
|
591
|
-
if defined?(VCR)
|
592
|
-
case switch
|
593
|
-
when :on
|
594
|
-
VCR.turn_on!
|
595
|
-
when :off
|
596
|
-
VCR.turn_off!(ignore_cassettes: true)
|
597
|
-
end
|
598
|
-
end
|
599
|
-
|
600
|
-
if defined?(WebMock)
|
601
|
-
# WebMock on by default
|
602
|
-
# VCR depends on WebMock 1.8.11; no method to check whether enabled.
|
603
|
-
case switch
|
604
|
-
when :on
|
605
|
-
WebMock.enable!
|
606
|
-
when :off
|
607
|
-
WebMock.disable!
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
true
|
612
|
-
end
|
613
|
-
|
614
|
-
# Convenience color methods
|
615
|
-
def black(str)
|
616
|
-
str.nil? ? '' : "\e[30m#{str}\e[0m"
|
617
|
-
end
|
618
|
-
|
619
|
-
def red(str)
|
620
|
-
str.nil? ? '' : "\e[31m#{str}\e[0m"
|
621
|
-
end
|
622
|
-
|
623
|
-
def green(str)
|
624
|
-
str.nil? ? '' : "\e[32m#{str}\e[0m"
|
14
|
+
report = Codecov::SimpleCov::Formatter.new.format(result)
|
15
|
+
Codecov::Uploader.upload(report, disable_net_blockers)
|
625
16
|
end
|
626
17
|
end
|