Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
### `0.1.19`
### `0.1.20`
- fix critical upload issues on V2 endpoint

### `0.1.19`
- fix colorize

### `0.1.18`

- refactor and move to use v2 endpoint
- use Timeout::Error

### `0.1.17`

- refactor upload method and add more logging

### `0.1.10`
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: test install build deploy

deploy:
$(eval VERSION := $(shell cat lib/codecov.rb | grep 'VERSION = ' | cut -d\" -f2))
$(eval VERSION := $(shell cat lib/codecov.rb | grep 'VERSION = ' | cut -d\' -f2))
git tag v$(VERSION) -m ""
git push origin v$(VERSION)
gem build codecov.gemspec
Expand Down
61 changes: 48 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# codecov-ruby
[![Gem Version](https://badge.fury.io/rb/codecov.svg)](https://badge.fury.io/rb/codecov) [![Build Status](https://secure.travis-ci.org/codecov/codecov-ruby.svg?branch=master)](http://travis-ci.org/codecov/codecov-ruby) [![codecov.io](https://codecov.io/github/codecov/codecov-ruby/coverage.svg?branch=master)](https://codecov.io/github/codecov/codecov-ruby?branch=master)
# Codecov Ruby Uploader

## Usage
[![Codecov](https://codecov.io/github/codecov/codecov-ruby/coverage.svg?branch=master)](https://codecov.io/github/codecov/codecov-ruby?branch=master)
[![Gem Version](https://badge.fury.io/rb/codecov.svg)](https://badge.fury.io/rb/codecov.svg)
[![Build Status](https://secure.travis-ci.org/codecov/codecov-ruby.svg?branch=master)](http://travis-ci.org/codecov/codecov-ruby)

[Codecov.io](https://codecov.io/) upload support for Ruby.

## Quick Start

> Add to your `Gemfile`

Expand All @@ -19,12 +24,34 @@ require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
```

> In your CI Environment Variables *(not needed for [https://travis-ci.org/](https://travis-ci.org/))*

> In your CI Environment Variables
```sh
CODECOV_TOKEN="your repo token"
```
Find you repo token on your repo page at [codecov.io][1]. Repo tokens are **not** required for public repos on Travis-Ci, CircleCI, or AppVeyor CI.
Find you repo token on your repo page at [codecov.io](https://codecov.io). Repo tokens are **not** required for public repos on Travis-Ci, CircleCI, or AppVeyor CI.

## Supported CIs
| CI/CD |
| ----- |
| [Appveyor CI](https://www.appveyor.com/) |
| [Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) |
| [Bitbucket Pipelines](https://bitbucket.org/product/features/pipelines) |
| [Bitrise CI](https://www.bitrise.io/) |
| [Buildkite CI](https://buildkite.com/) |
| [Circle CI](https://circleci.com/) |
| [Codeship CI](https://codeship.com/) |
| [Drone CI](https://drone.io/) |
| [GitLab CI](https://docs.gitlab.com/ee/ci/) |
| [Heroku CI](https://www.heroku.com/continuous-integration) |
| [Jenkins CI](https://www.jenkins.io/) |
| [Semaphore CI](https://semaphoreci.com/) |
| [Shippable](https://www.shippable.com/) |
| [Solano CI](https://xebialabs.com/technology/solano-ci/) |
| [TeamCity CI](https://www.jetbrains.com/teamcity/) |
| [Travis CI](https://travis-ci.org/) |
| [Wercker CI](https://devcenter.wercker.com/) |

## Advanced Usage

#### Submit only in CI example

Expand All @@ -35,21 +62,29 @@ if ENV['CI'] == 'true'
end
```

### CI Companies Supported
Jenkins, Travis CI, Codeship, Circle CI, Semaphore, drone.io, AppVeyor, Wercker, Magnum, Shippable, Gitlab CI, Buildkite and Bitrise. Otherwise fallbacks on `git`.
## Useful Links

### Caveat
[FAQ](https://docs.codecov.io/docs/frequently-asked-questions)
[Recipe List](https://docs.codecov.io/docs/common-recipe-list)
[Error Reference](https://docs.codecov.io/docs/error-reference)
[Changelog](./CHANGELOG.md)
[Support](https://codecov.io/support)
[Community Boards](https://community.codecov.io)

## Caveats

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)
- https://github.com/colszowka/simplecov/blob/master/README.md#default-root-filter-and-coverage-for-things-outside-of-it

### Enterprise
## Maintainers

- [thomasrockhu](https://github.com/thomasrockhu)

## Enterprise

For companies using Codecov Enterprise you will need to specify the following parameters.
```sh
CODECOV_URL="https://codecov.mycompany.com"
CODECOV_SLUG="owner/repo"
CODECOV_TOKEN="repository token or global token"
```


[1]: https://codecov.io/
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require 'bundler'
require 'rubygems'
require 'rake/testtask'

helper = Bundler::GemHelper.new
helper.install_gem
Bundler::GemHelper.install_tasks

Rake::TestTask.new(:test) do |test|
Expand Down
2 changes: 1 addition & 1 deletion codecov.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = 'codecov'
s.version = '0.1.19'
s.version = '0.1.20'
s.platform = Gem::Platform::RUBY
s.authors = ['codecov']
s.email = ['hello@codecov.io']
Expand Down
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true
55 changes: 41 additions & 14 deletions lib/codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
require 'net/http'
require 'simplecov'
require 'colorize'
require 'tempfile'
require 'zlib'

class SimpleCov::Formatter::Codecov
VERSION = '0.1.19'
VERSION = '0.1.20'

### CIs
RECOGNIZED_CIS = [
Expand Down Expand Up @@ -95,7 +94,8 @@ def detect_ci
def build_params(ci)
params = {
'token' => ENV['CODECOV_TOKEN'],
'flags' => ENV['CODECOV_FLAG'] || ENV['CODECOV_FLAGS']
'flags' => ENV['CODECOV_FLAG'] || ENV['CODECOV_FLAGS'],
'package' => "ruby-#{VERSION}"
}

case ci
Expand Down Expand Up @@ -314,15 +314,10 @@ def create_report(report)
def gzip_report(report)
puts ['==>'.green, 'Gzipping contents'].join(' ')

file = Tempfile.new
Zlib::GzipWriter.open(file.path) do |gz|
gz.write report
end
file.rewind
gzipped_report = file.read
file.close
gzip = Zlib::GzipWriter.new(StringIO.new)
gzip << report

gzipped_report
gzip.close.string
end

def upload_to_codecov(ci, report)
Expand All @@ -335,7 +330,7 @@ def upload_to_codecov(ci, report)
query = URI.encode_www_form(params)
query_without_token = URI.encode_www_form(params_secret_token)

gzipped_report = gzip_report(report)
gzipped_report = gzip_report(report['codecov'])

report['params'] = params
report['query'] = query
Expand All @@ -358,8 +353,9 @@ def upload_to_v2(url, report, query, query_without_token)
req = Net::HTTP::Post.new(
"#{uri.path}?#{query}",
{
'X-Reduced-Redundancy' => 'false',
'Content-Type' => 'text/plain'
'Content-Encoding' => 'gzip',
'Content-Type' => 'text/plain',
'X-Content-Encoding' => 'gzip'
}
)
req.body = report
Expand All @@ -381,6 +377,7 @@ def format(result)
ci = detect_ci
report = create_report(result)
response = upload_to_codecov(ci, report)

report['result'] = JSON.parse(response.body)
handle_report_response(report)
net_blockers(:on)
Expand All @@ -395,11 +392,41 @@ def format(result)
# @return [Hash]
def result_to_codecov(result)
{
'codecov' => result_to_codecov_report(result),
'coverage' => result_to_codecov_coverage(result),
'messages' => result_to_codecov_messages(result)
}
end

def result_to_codecov_report(result)
report = file_network.join("\n").concat("\n")
report = report.concat({ 'coverage' => result_to_codecov_coverage(result) }.to_json)
report
end

def file_network
invalid_file_types = [
'woff', 'eot', 'otf', # fonts
'gif', 'png', 'jpg', 'jpeg', 'psd', # images
'ptt', 'pptx', 'numbers', 'pages', 'md', 'txt', 'xlsx', 'docx', 'doc', 'pdf', 'csv', # docs
'yml', 'yaml', '.gitignore'
].freeze

invalid_directories = [
'node_modules/'
]

puts ['==>'.green, 'Appending file network'].join(' ')
network = []
Dir['**/*'].keep_if do |file|
if File.file?(file) && !file.end_with?(*invalid_file_types) && !file.include?(*invalid_directories)
network.push(file)
end
end
network.push('<<<<<< network')
network
end

# Format SimpleCov coverage data for the Codecov.io coverage API.
#
# @param result [SimpleCov::Result] The coverage data to process.
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'bundler/setup'

require 'simplecov'
SimpleCov.start 'rails' do
SimpleCov.start do
add_filter '/test/'
end
require 'codecov'
Expand Down