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

Commit b145b19

Browse files
Merge branch 'master' into pipe
2 parents d460065 + 4a7561e commit b145b19

25 files changed

+386
-114
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ language: node_js
33
sudo: false
44

55
node_js:
6+
- "8"
7+
- "7"
68
- "6"
79
- "5"
810
- "4"
9-
- "0.12"
10-
- "0.11"
11-
- "0.10"
1211
- "iojs"
1312

1413
after_success:
15-
- ./bin/codecov -e TRAVIS_NODE_VERSION
14+
- ./bin/codecov -e TRAVIS_NODE_VERSION -f coverage/coverage.json

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Codecov NodeJS Uploader
22

33
[![NPM version][npm-image]][npm-url]
4-
[![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)
4+
[![Build Status][travis-image]][travis-url]
5+
[![Build Status][appveyor-image]][appveyor-url]
6+
[![codecov.io](https://codecov.io/github/codecov/codecov-node/coverage.svg?branch=master)](https://codecov.io/github/codecov/codecov-node?branch=master)
57
[![Dependency Status][depstat-image]][depstat-url]
68
[![Dev Dependency Status][devdepstat-image]][devdepstat-url]
79

@@ -10,7 +12,11 @@
1012
## Installation:
1113
Add the latest version of `codecov` to your package.json:
1214
```
13-
npm install codecov --save
15+
npm install codecov --save-dev
16+
```
17+
or
18+
```
19+
yarn add codecov --dev
1420
```
1521

1622
## Usage:
@@ -24,7 +30,7 @@ This library currently supports the following CI companies: [Travis CI](https://
2430
#### Upload repo tokens
2531
> Repo tokens are **not** required for public repos tested on Travis-Org, CircleCI or AppVeyor.
2632
27-
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.
33+
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.
2834

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

67+
[appveyor-image]: https://ci.appveyor.com/api/projects/status/ea1suiv0tprnq61l?svg=true
68+
[appveyor-url]: https://ci.appveyor.com/project/eddiemoore/codecov-node/branch/master
69+
6170
[npm-url]: https://npmjs.org/package/codecov
6271
[npm-image]: https://img.shields.io/npm/v/codecov.svg
6372

@@ -74,3 +83,12 @@ nyc npm test
7483
nyc report --reporter=text-lcov > coverage.lcov
7584
./node_modules/.bin/codecov
7685
```
86+
87+
## Change Log
88+
- v2.0.0 No longer supports node v0.10 because of the execSync.
89+
- v2.0.1 Publish as latest instead of next.
90+
- v2.0.2 Display correct version number in console.
91+
- v2.1.0 Flags supported http://docs.codecov.io/docs/flags
92+
- v2.2.0 Support for Jenkins Blue Ocean. Clean reports after upload. Fix for Gitlab.
93+
- v2.3.0 Added support for Windows. Updated dependencies.
94+
- v3.0.0 No longer supports node v0.12 because of new version of request

appveyor.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
environment:
2+
matrix:
3+
- nodejs_version: "8"
4+
- nodejs_version: "7"
5+
- nodejs_version: "6"
6+
- nodejs_version: "5"
7+
- nodejs_version: "4"
8+
- nodejs_version: "1.0"
9+
10+
max_jobs: 4
11+
12+
clone_depth: 50
13+
14+
init:
15+
- git config --global core.autocrlf true
16+
17+
install:
18+
- ps: Install-Product node $env:nodejs_version
19+
- npm install
20+
21+
test_script:
22+
- cmd: SET PATH=C:\MinGW\bin;%PATH%
23+
- npm run test
24+
25+
after_test:
26+
- node .\bin\codecov -f coverage\coverage.json
27+
28+
build: off
29+
30+
deploy: off

bin/codecov

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ var args = argv.option([
1414
{name: 'gcov-args', type: 'string', description: "extra arguments to pass to gcov"},
1515
{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"},
1616
{name: 'commit', short: 'c', type: 'string', description: "Commit sha, set automatically"},
17+
{name: 'clear', short: 'C', type: 'boolean', description: "Remove all discovered reports after uploading"},
1718
{name: 'branch', short: 'b', type: 'string', description: "Branch name"},
1819
{name: 'build', short: 'B', type: 'string', description: "Specify a custom build number to distinguish ci jobs, provided automatically for supported ci companies"},
1920
{name: 'slug', short: 'r', type: 'string', description: "Specify repository slug for Enterprise ex. owner/repo"},
2021
{name: 'url', short: 'u', type: 'string', description: "Your Codecov endpoint"},
22+
{name: 'flags', short: 'F', type: 'string', description: "Codecov Flags"},
2123
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"}
2224
]).run();
2325

circle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
machine:
22
node:
3-
version: 0.12.7
3+
version: 4
44

55
test:
66
post:
7-
- ./bin/codecov
7+
- ./bin/codecov -f coverage/coverage.json
88

99
deployment:
1010
suite:

codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage:
2+
parsers:
3+
javascript:
4+
enable_partials: no

lib/codecov.js

Lines changed: 111 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ var path = require('path');
33
var request = require('request');
44
var urlgrey = require('urlgrey');
55
var execSync = require('child_process').execSync;
6-
if (!execSync) {
7-
var exec = require('execSync').exec;
8-
var execSync = function(cmd){
9-
return exec(cmd).stdout;
10-
};
11-
}
126

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

15-
var version = "v1.0.1";
9+
var version = 'v' + require('../package.json').version;
10+
11+
var patterns, more_patterns = '';
1612

17-
var patterns = "-type f \\( -name '*coverage.*' " +
13+
var isWindows = process.platform.match(/win32/) || process.platform.match(/win64/)
14+
15+
if(!isWindows) {
16+
patterns
17+
= "-type f \\( -name '*coverage.*' " +
1818
"-or -name 'nosetests.xml' " +
1919
"-or -name 'jacoco*.xml' " +
2020
"-or -name 'clover.xml' " +
@@ -72,7 +72,68 @@ var patterns = "-type f \\( -name '*coverage.*' " +
7272
"-not -path '*/$bower_components/*' " +
7373
"-not -path '*/node_modules/*' " +
7474
"-not -path '*/conftest_*.c.gcov'";
75-
75+
}
76+
else {
77+
patterns
78+
= '/a-d /b /s *coverage.* ' +
79+
'/s nosetests.xml ' +
80+
'/s jacoco*.xml ' +
81+
'/s clover.xml ' +
82+
'/s report.xml ' +
83+
'/s cobertura.xml ' +
84+
'/s luacov.report.out ' +
85+
'/s lcov.info ' +
86+
'/s *.lcov ' +
87+
'/s gcov.info ' +
88+
'/s *.gcov ' +
89+
'/s *.lst' +
90+
'| findstr /i /v \\.sh$ ' +
91+
'| findstr /i /v \\.data$ ' +
92+
'| findstr /i /v \\.py$ ' +
93+
'| findstr /i /v \\.class$ ' +
94+
'| findstr /i /v \\.xcconfig$ ' +
95+
'| findstr /i /v Coverage\\.profdata$ ' +
96+
'| findstr /i /v phpunit-code-coverage\\.xml$ ' +
97+
'| findstr /i /v coverage\\.serialized$ ' +
98+
'| findstr /i /v \\.pyc$ ' +
99+
'| findstr /i /v \\.cfg$ ' +
100+
'| findstr /i /v \\.egg$ ' +
101+
'| findstr /i /v \\.whl$ ' +
102+
'| findstr /i /v \\.html$ ' +
103+
'| findstr /i /v \\.js$ ' +
104+
'| findstr /i /v \\.cpp$ ' +
105+
'| findstr /i /v coverage\\.jade$ ' +
106+
'| findstr /i /v include\\.lst$ ' +
107+
'| findstr /i /v inputFiles\\.lst$ ' +
108+
'| findstr /i /v createdFiles\\.lst$ ' +
109+
'| findstr /i /v coverage\\.html$ ' +
110+
'| findstr /i /v scoverage\\.measurements\\..* ' +
111+
'| findstr /i /v test_.*_coverage\\.txt ' +
112+
'| findstr /i /v \\vendor\\ ' +
113+
'| findstr /i /v \\htmlcov\\ ' +
114+
'| findstr /i /v \\home\\cainus\\ ' +
115+
'| findstr /i /v \\js\\generated\\coverage\\ ' +
116+
'| findstr /i /v \\virtualenv\\ ' +
117+
'| findstr /i /v \\virtualenvs\\ ' +
118+
'| findstr /i /v \\\\.virtualenv\\ ' +
119+
'| findstr /i /v \\\\.virtualenvs\\ ' +
120+
'| findstr /i /v \\\\.env\\ ' +
121+
'| findstr /i /v \\\\.envs\\ ' +
122+
'| findstr /i /v \\env\\ ' +
123+
'| findstr /i /v \\envs\\ ' +
124+
'| findstr /i /v \\\\.venv\\ ' +
125+
'| findstr /i /v \\\\.venvs\\ ' +
126+
'| findstr /i /v \\venv\\ ' +
127+
'| findstr /i /v \\venvs\\ ' +
128+
'| findstr /i /v \\\\.git\\ ' +
129+
'| findstr /i /v \\\\.hg\\ ' +
130+
'| findstr /i /v \\\\.tox\\ ' +
131+
'| findstr /i /v \\__pycache__\\ ' +
132+
'| findstr /i /v \\\\.egg-info* ' +
133+
'| findstr /i /v \\\\$bower_components\\ ' +
134+
'| findstr /i /v \\node_modules\\ ' +
135+
'| findstr /i /v \\conftest_.*\\.c\\.gcov ';
136+
}
76137

77138

78139
var sendToCodecovV2 = function(codecov_endpoint, query, upload_body, on_success, on_failure){
@@ -106,7 +167,7 @@ var sendToCodecovV3 = function(codecov_endpoint, query, upload_body, on_success,
106167
// Direct to S3
107168
request.post(
108169
{
109-
url : urlgrey(codecov_endpoint + '/upload/v3').query(query).toString(),
170+
url : urlgrey(codecov_endpoint + '/upload/v4').query(query).toString(),
110171
body : '',
111172
headers : {
112173
'Content-Type': 'text/plain',
@@ -123,7 +184,7 @@ var sendToCodecovV3 = function(codecov_endpoint, query, upload_body, on_success,
123184
url : result.split('\n')[1],
124185
body : upload_body,
125186
headers : {
126-
'Content-Type': 'plain/text',
187+
'Content-Type': 'text/plain',
127188
'x-amz-acl': 'public-read'
128189
}
129190
}, function(err, response, result){
@@ -186,6 +247,11 @@ var upload = function(args, on_success, on_failure){
186247
query.slug = args.options.slug;
187248
}
188249

250+
var flags = (args.options.flags || process.env.codecov_flags || process.env.CODECOV_FLAGS);
251+
if (flags) {
252+
query.flags = flags;
253+
}
254+
189255
var token = (args.options.token || process.env.codecov_token || process.env.CODECOV_TOKEN);
190256
if (token){
191257
query.token = token;
@@ -215,19 +281,30 @@ var upload = function(args, on_success, on_failure){
215281
}
216282

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

222288
// Make gcov reports
223289
if ((args.options.disable || '').split(',').indexOf('gcov') === -1) {
224290
try {
225291
console.log('==> Generating gcov reports (skip via --disable=gcov)');
226292
var gcg = args.options['gcov-glob'] || '';
227293
if (gcg) {
228-
gcg = gcg.split(' ').map(function(p){return "-not -path '"+p+"'";}).join(' ');
294+
if(!isWindows) {
295+
gcg = gcg.split(' ').map(function(p){return "-not -path '"+p+"'";}).join(' ');
296+
} else {
297+
gcg = gcg.split(' ').map(function(p){return "^| findstr /i /v "+p;}).join(' ');
298+
}
299+
}
300+
var gcov;
301+
if(!isWindows) {
302+
gcov = "find "+(args.options['gcov-root'] || root)+" -type f -name '*.gcno' "+gcg+" -exec "+(args.options['gcov-exec'] || 'gcov')+" "+(args.options['gcov-args'] || '')+" {} +";
303+
} else {
304+
// @TODO support for root
305+
// not straight forward due to nature of windows command dir
306+
gcov = "for /f \"delims=\" %g in ('dir /a-d /b /s *.gcno "+gcg+"') do "+(args.options['gcov-exec'] || 'gcov')+" "+(args.options['gcov-args'] || '')+" %g";
229307
}
230-
var gcov = "find "+(args.options['gcov-root'] || root)+" -type f -name '*.gcno' "+gcg+" -exec "+(args.options['gcov-exec'] || 'gcov')+" "+(args.options['gcov-args'] || '')+" {} +";
231308
debug.push(gcov);
232309
console.log(' $ '+gcov);
233310
execSync(gcov);
@@ -239,11 +316,20 @@ var upload = function(args, on_success, on_failure){
239316
}
240317

241318
// Detect .bowerrc
242-
var bowerrc = execSync('cd '+root+' && test -f .bowerrc && cat .bowerrc || echo ""').toString().trim(), more_patterns = '';
319+
var bowerrc;
320+
if(!isWindows) {
321+
bowerrc = execSync('test -f .bowerrc && cat .bowerrc || echo ""', { cwd: root }).toString().trim();
322+
} else {
323+
bowerrc = execSync('if exist .bowerrc type .bowerrc', { cwd: root }).toString().trim();
324+
}
243325
if (bowerrc) {
244326
bowerrc = JSON.parse(bowerrc).directory;
245327
if (bowerrc) {
246-
more_patterns = " -not -path '*/" + bowerrc.toString().replace(/\/$/, '') + "/*'";
328+
if(!isWindows) {
329+
more_patterns = " -not -path '*/" + bowerrc.toString().replace(/\/$/, '') + "/*'";
330+
} else {
331+
more_patterns = '| findstr /i /v \\' + bowerrc.toString().replace(/\/$/, '') + '\\';
332+
}
247333
}
248334
}
249335

@@ -265,7 +351,14 @@ var upload = function(args, on_success, on_failure){
265351
}
266352
} else if ((args.options.disable || '').split(',').indexOf('search') === -1) {
267353
console.log('==> Scanning for reports');
268-
var _files = execSync('find ' + root + ' ' + patterns + more_patterns).toString().trim().split('\n');
354+
var _files
355+
if(!isWindows) {
356+
_files = execSync('find ' + root + ' ' + patterns + more_patterns).toString().trim().split('\n');
357+
} else {
358+
// @TODO support for a root directory
359+
// It's not straightforward due to the nature of the dir command
360+
_files = execSync('dir ' + patterns + more_patterns).toString().trim().split('\r\n');
361+
}
269362
if (_files) {
270363
for (var i2 = _files.length - 1; i2 >= 0; i2--) {
271364
file = _files[i2];

lib/detect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var detectProvider = function(){
2424
var local = require('./services/localGit');
2525
config = local.configuration();
2626
if (!config){
27-
throw new Error("Unknown CI servie provider. Unable to upload coverage.");
27+
throw new Error("Unknown CI service provider. Unable to upload coverage.");
2828
}
2929
}
3030
return config;

lib/git.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var execSync = require("child_process").execSync;
2+
3+
module.exports = {
4+
5+
branch: function(){
6+
return execSync("git rev-parse --abbrev-ref HEAD || hg branch").toString().trim();
7+
},
8+
9+
head: function(){
10+
return execSync("git log -1 --pretty=%H || hg id -i --debug | tr -d '+'").toString().trim();
11+
}
12+
13+
};

lib/offline.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// see: http://man7.org/linux/man-pages/man2/accept.2.html#ERRORS
2+
var offlineErrorCodes = [
3+
'EAI_AGAIN',
4+
'ENETDOWN',
5+
'EPROTO',
6+
'ENOPROTOOPT',
7+
'EHOSTDOWN',
8+
'ENONET',
9+
'EHOSTUNREACH',
10+
'EOPNOTSUPP',
11+
'ENETUNREACH'
12+
]
13+
14+
module.exports = offlineErrorCodes;

0 commit comments

Comments
 (0)