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

Commit

Permalink
Merge branch 'master' into pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnetCarpenter committed Mar 13, 2018
2 parents d460065 + 4a7561e commit b145b19
Show file tree
Hide file tree
Showing 25 changed files with 386 additions and 114 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ language: node_js
sudo: false

node_js:
- "8"
- "7"
- "6"
- "5"
- "4"
- "0.12"
- "0.11"
- "0.10"
- "iojs"

after_success:
- ./bin/codecov -e TRAVIS_NODE_VERSION
- ./bin/codecov -e TRAVIS_NODE_VERSION -f coverage/coverage.json
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Codecov NodeJS Uploader

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url] [![codecov.io](https://codecov.io/github/codecov/codecov-node/coverage.svg?branch=master)](https://codecov.io/github/codecov/codecov-node?branch=master)
[![Build Status][travis-image]][travis-url]
[![Build Status][appveyor-image]][appveyor-url]
[![codecov.io](https://codecov.io/github/codecov/codecov-node/coverage.svg?branch=master)](https://codecov.io/github/codecov/codecov-node?branch=master)
[![Dependency Status][depstat-image]][depstat-url]
[![Dev Dependency Status][devdepstat-image]][devdepstat-url]

Expand All @@ -10,7 +12,11 @@
## Installation:
Add the latest version of `codecov` to your package.json:
```
npm install codecov --save
npm install codecov --save-dev
```
or
```
yarn add codecov --dev
```

## Usage:
Expand All @@ -24,7 +30,7 @@ This library currently supports the following CI companies: [Travis CI](https://
#### Upload repo tokens
> Repo tokens are **not** required for public repos tested on Travis-Org, CircleCI or AppVeyor.
Repo tokens are neccessary to distinquish your repository from others. You can find your repo token on your repository page at Codecov. Set this unique uuid to `CODECOV_TOKEN` in your environment variables.
Repo tokens are necessary to distinguish your repository from others. You can find your repo token on your repository page at Codecov. Set this unique uuid to `CODECOV_TOKEN` in your environment variables.

```
export CODECOV_TOKEN=":uuid-repo-token"
Expand Down Expand Up @@ -58,6 +64,9 @@ istanbul cover test.js
[travis-image]: https://travis-ci.org/codecov/codecov-node.svg?branch=master
[travis-url]: https://travis-ci.org/codecov/codecov-node

[appveyor-image]: https://ci.appveyor.com/api/projects/status/ea1suiv0tprnq61l?svg=true
[appveyor-url]: https://ci.appveyor.com/project/eddiemoore/codecov-node/branch/master

[npm-url]: https://npmjs.org/package/codecov
[npm-image]: https://img.shields.io/npm/v/codecov.svg

Expand All @@ -74,3 +83,12 @@ nyc npm test
nyc report --reporter=text-lcov > coverage.lcov
./node_modules/.bin/codecov
```

## Change Log
- v2.0.0 No longer supports node v0.10 because of the execSync.
- v2.0.1 Publish as latest instead of next.
- v2.0.2 Display correct version number in console.
- v2.1.0 Flags supported http://docs.codecov.io/docs/flags
- v2.2.0 Support for Jenkins Blue Ocean. Clean reports after upload. Fix for Gitlab.
- v2.3.0 Added support for Windows. Updated dependencies.
- v3.0.0 No longer supports node v0.12 because of new version of request
30 changes: 30 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
environment:
matrix:
- nodejs_version: "8"
- nodejs_version: "7"
- nodejs_version: "6"
- nodejs_version: "5"
- nodejs_version: "4"
- nodejs_version: "1.0"

max_jobs: 4

clone_depth: 50

init:
- git config --global core.autocrlf true

install:
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- cmd: SET PATH=C:\MinGW\bin;%PATH%
- npm run test

after_test:
- node .\bin\codecov -f coverage\coverage.json

build: off

deploy: off
2 changes: 2 additions & 0 deletions bin/codecov
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ var args = argv.option([
{name: 'gcov-args', type: 'string', description: "extra arguments to pass to gcov"},
{name: 'disable', short: 'X', type: 'string', description: "Disable features. Accepting `search` to disable crawling through directories, `detect` to disable detecting CI provider, `gcov` disable gcov commands"},
{name: 'commit', short: 'c', type: 'string', description: "Commit sha, set automatically"},
{name: 'clear', short: 'C', type: 'boolean', description: "Remove all discovered reports after uploading"},
{name: 'branch', short: 'b', type: 'string', description: "Branch name"},
{name: 'build', short: 'B', type: 'string', description: "Specify a custom build number to distinguish ci jobs, provided automatically for supported ci companies"},
{name: 'slug', short: 'r', type: 'string', description: "Specify repository slug for Enterprise ex. owner/repo"},
{name: 'url', short: 'u', type: 'string', description: "Your Codecov endpoint"},
{name: 'flags', short: 'F', type: 'string', description: "Codecov Flags"},
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"}
]).run();

Expand Down
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
machine:
node:
version: 0.12.7
version: 4

test:
post:
- ./bin/codecov
- ./bin/codecov -f coverage/coverage.json

deployment:
suite:
Expand Down
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
parsers:
javascript:
enable_partials: no
129 changes: 111 additions & 18 deletions lib/codecov.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ var path = require('path');
var request = require('request');
var urlgrey = require('urlgrey');
var execSync = require('child_process').execSync;
if (!execSync) {
var exec = require('execSync').exec;
var execSync = function(cmd){
return exec(cmd).stdout;
};
}

var detectProvider = require('./detect');

var version = "v1.0.1";
var version = 'v' + require('../package.json').version;

var patterns, more_patterns = '';

var patterns = "-type f \\( -name '*coverage.*' " +
var isWindows = process.platform.match(/win32/) || process.platform.match(/win64/)

if(!isWindows) {
patterns
= "-type f \\( -name '*coverage.*' " +
"-or -name 'nosetests.xml' " +
"-or -name 'jacoco*.xml' " +
"-or -name 'clover.xml' " +
Expand Down Expand Up @@ -72,7 +72,68 @@ var patterns = "-type f \\( -name '*coverage.*' " +
"-not -path '*/$bower_components/*' " +
"-not -path '*/node_modules/*' " +
"-not -path '*/conftest_*.c.gcov'";

}
else {
patterns
= '/a-d /b /s *coverage.* ' +
'/s nosetests.xml ' +
'/s jacoco*.xml ' +
'/s clover.xml ' +
'/s report.xml ' +
'/s cobertura.xml ' +
'/s luacov.report.out ' +
'/s lcov.info ' +
'/s *.lcov ' +
'/s gcov.info ' +
'/s *.gcov ' +
'/s *.lst' +
'| findstr /i /v \\.sh$ ' +
'| findstr /i /v \\.data$ ' +
'| findstr /i /v \\.py$ ' +
'| findstr /i /v \\.class$ ' +
'| findstr /i /v \\.xcconfig$ ' +
'| findstr /i /v Coverage\\.profdata$ ' +
'| findstr /i /v phpunit-code-coverage\\.xml$ ' +
'| findstr /i /v coverage\\.serialized$ ' +
'| findstr /i /v \\.pyc$ ' +
'| findstr /i /v \\.cfg$ ' +
'| findstr /i /v \\.egg$ ' +
'| findstr /i /v \\.whl$ ' +
'| findstr /i /v \\.html$ ' +
'| findstr /i /v \\.js$ ' +
'| findstr /i /v \\.cpp$ ' +
'| findstr /i /v coverage\\.jade$ ' +
'| findstr /i /v include\\.lst$ ' +
'| findstr /i /v inputFiles\\.lst$ ' +
'| findstr /i /v createdFiles\\.lst$ ' +
'| findstr /i /v coverage\\.html$ ' +
'| findstr /i /v scoverage\\.measurements\\..* ' +
'| findstr /i /v test_.*_coverage\\.txt ' +
'| findstr /i /v \\vendor\\ ' +
'| findstr /i /v \\htmlcov\\ ' +
'| findstr /i /v \\home\\cainus\\ ' +
'| findstr /i /v \\js\\generated\\coverage\\ ' +
'| findstr /i /v \\virtualenv\\ ' +
'| findstr /i /v \\virtualenvs\\ ' +
'| findstr /i /v \\\\.virtualenv\\ ' +
'| findstr /i /v \\\\.virtualenvs\\ ' +
'| findstr /i /v \\\\.env\\ ' +
'| findstr /i /v \\\\.envs\\ ' +
'| findstr /i /v \\env\\ ' +
'| findstr /i /v \\envs\\ ' +
'| findstr /i /v \\\\.venv\\ ' +
'| findstr /i /v \\\\.venvs\\ ' +
'| findstr /i /v \\venv\\ ' +
'| findstr /i /v \\venvs\\ ' +
'| findstr /i /v \\\\.git\\ ' +
'| findstr /i /v \\\\.hg\\ ' +
'| findstr /i /v \\\\.tox\\ ' +
'| findstr /i /v \\__pycache__\\ ' +
'| findstr /i /v \\\\.egg-info* ' +
'| findstr /i /v \\\\$bower_components\\ ' +
'| findstr /i /v \\node_modules\\ ' +
'| findstr /i /v \\conftest_.*\\.c\\.gcov ';
}


var sendToCodecovV2 = function(codecov_endpoint, query, upload_body, on_success, on_failure){
Expand Down Expand Up @@ -106,7 +167,7 @@ var sendToCodecovV3 = function(codecov_endpoint, query, upload_body, on_success,
// Direct to S3
request.post(
{
url : urlgrey(codecov_endpoint + '/upload/v3').query(query).toString(),
url : urlgrey(codecov_endpoint + '/upload/v4').query(query).toString(),
body : '',
headers : {
'Content-Type': 'text/plain',
Expand All @@ -123,7 +184,7 @@ var sendToCodecovV3 = function(codecov_endpoint, query, upload_body, on_success,
url : result.split('\n')[1],
body : upload_body,
headers : {
'Content-Type': 'plain/text',
'Content-Type': 'text/plain',
'x-amz-acl': 'public-read'
}
}, function(err, response, result){
Expand Down Expand Up @@ -186,6 +247,11 @@ var upload = function(args, on_success, on_failure){
query.slug = args.options.slug;
}

var flags = (args.options.flags || process.env.codecov_flags || process.env.CODECOV_FLAGS);
if (flags) {
query.flags = flags;
}

var token = (args.options.token || process.env.codecov_token || process.env.CODECOV_TOKEN);
if (token){
query.token = token;
Expand Down Expand Up @@ -215,19 +281,30 @@ var upload = function(args, on_success, on_failure){
}

// List git files
var root = args.options.root || query.root || '.';
var root = path.resolve(args.options.root || query.root || '.');
console.log('==> Building file structure');
upload += execSync('cd '+root+' && git ls-files || hg locate').toString().trim() + '\n<<<<<< network\n';
upload += execSync('git ls-files || hg locate', { cwd: root }).toString().trim() + '\n<<<<<< network\n';

// Make gcov reports
if ((args.options.disable || '').split(',').indexOf('gcov') === -1) {
try {
console.log('==> Generating gcov reports (skip via --disable=gcov)');
var gcg = args.options['gcov-glob'] || '';
if (gcg) {
gcg = gcg.split(' ').map(function(p){return "-not -path '"+p+"'";}).join(' ');
if(!isWindows) {
gcg = gcg.split(' ').map(function(p){return "-not -path '"+p+"'";}).join(' ');
} else {
gcg = gcg.split(' ').map(function(p){return "^| findstr /i /v "+p;}).join(' ');
}
}
var gcov;
if(!isWindows) {
gcov = "find "+(args.options['gcov-root'] || root)+" -type f -name '*.gcno' "+gcg+" -exec "+(args.options['gcov-exec'] || 'gcov')+" "+(args.options['gcov-args'] || '')+" {} +";
} else {
// @TODO support for root
// not straight forward due to nature of windows command dir
gcov = "for /f \"delims=\" %g in ('dir /a-d /b /s *.gcno "+gcg+"') do "+(args.options['gcov-exec'] || 'gcov')+" "+(args.options['gcov-args'] || '')+" %g";
}
var gcov = "find "+(args.options['gcov-root'] || root)+" -type f -name '*.gcno' "+gcg+" -exec "+(args.options['gcov-exec'] || 'gcov')+" "+(args.options['gcov-args'] || '')+" {} +";
debug.push(gcov);
console.log(' $ '+gcov);
execSync(gcov);
Expand All @@ -239,11 +316,20 @@ var upload = function(args, on_success, on_failure){
}

// Detect .bowerrc
var bowerrc = execSync('cd '+root+' && test -f .bowerrc && cat .bowerrc || echo ""').toString().trim(), more_patterns = '';
var bowerrc;
if(!isWindows) {
bowerrc = execSync('test -f .bowerrc && cat .bowerrc || echo ""', { cwd: root }).toString().trim();
} else {
bowerrc = execSync('if exist .bowerrc type .bowerrc', { cwd: root }).toString().trim();
}
if (bowerrc) {
bowerrc = JSON.parse(bowerrc).directory;
if (bowerrc) {
more_patterns = " -not -path '*/" + bowerrc.toString().replace(/\/$/, '') + "/*'";
if(!isWindows) {
more_patterns = " -not -path '*/" + bowerrc.toString().replace(/\/$/, '') + "/*'";
} else {
more_patterns = '| findstr /i /v \\' + bowerrc.toString().replace(/\/$/, '') + '\\';
}
}
}

Expand All @@ -265,7 +351,14 @@ var upload = function(args, on_success, on_failure){
}
} else if ((args.options.disable || '').split(',').indexOf('search') === -1) {
console.log('==> Scanning for reports');
var _files = execSync('find ' + root + ' ' + patterns + more_patterns).toString().trim().split('\n');
var _files
if(!isWindows) {
_files = execSync('find ' + root + ' ' + patterns + more_patterns).toString().trim().split('\n');
} else {
// @TODO support for a root directory
// It's not straightforward due to the nature of the dir command
_files = execSync('dir ' + patterns + more_patterns).toString().trim().split('\r\n');
}
if (_files) {
for (var i2 = _files.length - 1; i2 >= 0; i2--) {
file = _files[i2];
Expand Down
2 changes: 1 addition & 1 deletion lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var detectProvider = function(){
var local = require('./services/localGit');
config = local.configuration();
if (!config){
throw new Error("Unknown CI servie provider. Unable to upload coverage.");
throw new Error("Unknown CI service provider. Unable to upload coverage.");
}
}
return config;
Expand Down
13 changes: 13 additions & 0 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var execSync = require("child_process").execSync;

module.exports = {

branch: function(){
return execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim();
},

head: function(){
return execSync("git log -1 --pretty=%H || hg id -i --debug | tr -d '+'").toString().trim();
}

};
14 changes: 14 additions & 0 deletions lib/offline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// see: http://man7.org/linux/man-pages/man2/accept.2.html#ERRORS
var offlineErrorCodes = [
'EAI_AGAIN',
'ENETDOWN',
'EPROTO',
'ENOPROTOOPT',
'EHOSTDOWN',
'ENONET',
'EHOSTUNREACH',
'EOPNOTSUPP',
'ENETUNREACH'
]

module.exports = offlineErrorCodes;
17 changes: 16 additions & 1 deletion lib/services/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@ module.exports = {
commit : process.env.CIRCLE_SHA1,
branch : process.env.CIRCLE_BRANCH,
pr: process.env.CIRCLE_PR_NUMBER,
slug : process.env.CIRCLE_PROJECT_USERNAME + '/' + process.env.CIRCLE_PROJECT_REPONAME,
slug : detectRepoSlug(),
};
function detectRepoSlug(){
if (process.env.CIRCLE_PROJECT_REPONAME) {
// CircleCI 1.0
// CIRCLE_PROJECT_REPONAME=codecov
// CIRCLE_PROJECT_USERNAME=codecov-node
// CIRCLE_REPOSITORY_URL=https://github.com/codecov/codecov-node (note: GitHub Web URL)
return process.env.CIRCLE_PROJECT_USERNAME + '/' + process.env.CIRCLE_PROJECT_REPONAME;
}
if (process.env.CIRCLE_REPOSITORY_URL) {
// CircleCI 2.0
// CIRCLE_REPOSITORY_URL=git@github.com:codecov/codecov-node.git (note: Git/SSH URL)
return process.env.CIRCLE_REPOSITORY_URL.replace(/^.*:/, '').replace(/\.git$/, '');
}
throw new Error('Cannot detect repository slug.');
}
}

};
Loading

0 comments on commit b145b19

Please sign in to comment.