Skip to content

Commit

Permalink
Add code from fork and switch to simple form-data library (Node http/…
Browse files Browse the repository at this point in the history
…https) to send.
  • Loading branch information
JT Turner committed Mar 6, 2022
1 parent 4d0b747 commit 2ff6585
Show file tree
Hide file tree
Showing 8 changed files with 648 additions and 932 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [10, 12, 14, 15]
node: [12, 14, 16, 17]
os: [ubuntu-latest, windows-latest]

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Set Node.js version
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

Expand All @@ -32,19 +32,30 @@ jobs:
- name: Run tests
run: npm run test-cov

- name: test token
run: echo "${{ secrets.COVERALLS_REPO_TOKEN }}"

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ${{matrix.os}}-node-${{ matrix.node }}
parallel: true
run: cat ./coverage/lcov.info | node ./bin/coveralls.js
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_SERVICE_NAME: CI-pipeline
COVERALLS_SERVICE_JOB_ID: ${{github.run_id}}
COVERALLS_SERVICE_JOB_NUMBER: ${{github.run_number}}
COVERALLS_FLAG_NAME: ${{matrix.os}}-node-${{ matrix.node }}
COVERALLS_PARALLEL: true
NODE_COVERALLS_DEBUG: 1

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
run: |
curl -kv -d 'payload[build_num]=${{github.run_id}}&payload[status]=done' https://coveralls.io/webhook?repo_token=${COVERALLS_REPO_TOKEN}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status][ci-image]][ci-url] [![Coverage Status][coveralls-image]][coveralls-url]

This is just a fork of [coveralls](https://github.com/nickmerwin/node-coveralls) with updated dependencies and replace [request](https://github.com/request/request) which is deprecated with [GOT](https://www.npmjs.com/package/got). I also replace [xo](https://github.com/xojs/xo) with eslint and prettier with google settings as it also used a bunch of deprecated dependencies.
This is just a fork of [coveralls](https://github.com/nickmerwin/node-coveralls) with updated dependencies and replace [request](https://github.com/request/request) which is deprecated with [form-data](https://www.npmjs.com/package/form-data) which was the library request was using for form posts. I also replace [xo](https://github.com/xojs/xo) with eslint and prettier with google settings as it also used a bunch of deprecated dependencies.

[Coveralls.io](https://coveralls.io/) support for Node.js. Get the great coverage reporting of coveralls.io and add a cool coverage button (like the one above) to your README.

Expand Down Expand Up @@ -55,12 +55,16 @@ There are optional environment variables for other build systems as well:

### GitHub Actions CI

If you use this then there is no reason to have coveralls or coveralls-next library in your package as it has it's own npm version in the step. This doesn't use this library but the original coveralls npm package which will work just the same.

If you are using GitHub Actions CI, you should look into [coverallsapp/github-action](https://github.com/coverallsapp/github-action).

Parallel runs example [workflow.yml](https://github.com/coverallsapp/coveralls-node-demo/blob/master/.github/workflows/workflow.yml)

### [CircleCI Orb](https://circleci.com/)

If you use this then there is no reason to have coveralls or coveralls-next library in your package as it has it's own npm version in the step. This doesn't use this library but the original coveralls npm package which will work just the same.

Here's our Orb for quick integration: [coveralls/coveralls](https://circleci.com/orbs/registry/orb/coveralls/coveralls)

Workflow example: [config.yml](https://github.com/coverallsapp/coveralls-node-demo/blob/master/.circleci/config.yml)
Expand Down
3 changes: 3 additions & 0 deletions lib/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const fs = require('fs');
const path = require('path');
const lcovParse = require('lcov-parse');
const crypto = require('crypto');
const logger = require('./logger')();

const detailsToCoverage = (length, details) => {
Expand Down Expand Up @@ -31,12 +32,14 @@ const convertLcovFileObject = (file, filepath) => {
const rootpath = filepath;
filepath = path.resolve(rootpath, file.file);
const source = fs.readFileSync(filepath, 'utf8');
const md5 = crypto.createHash('md5').update(source).digest('hex');
const lines = source.split('\n');
const coverage = detailsToCoverage(lines.length, file.lines.details);
const branches = detailsToBranches(file.branches.details);

return {
name: path.relative(rootpath, path.resolve(rootpath, file.file)).split(path.sep).join('/'),
source_digest: md5,
source,
coverage,
branches,
Expand Down
10 changes: 5 additions & 5 deletions lib/fetchGitData.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const {exec} = require('child_process');
const {execFile} = require('child_process');
require('./logger')();

function fetchGitData(git, cb) {
Expand Down Expand Up @@ -40,7 +40,7 @@ function fetchGitData(git, cb) {
}

// -- Use git?
exec(`git rev-parse --verify ${git.head.id}`, err => {
execFile('git', ['rev-parse', '--verify', git.head.id], err => {
if (err) {
// git is not available...
git.head.author_name = git.head.author_name || 'Unknown Author';
Expand All @@ -56,7 +56,7 @@ function fetchGitData(git, cb) {
}

function fetchBranch(git, cb) {
exec('git branch', (err, branches) => {
execFile('git', ['branch'], (err, branches) => {
if (err) {
return cb(err);
}
Expand All @@ -69,7 +69,7 @@ function fetchBranch(git, cb) {
const REGEX_COMMIT_DETAILS = /\nauthor (.+?) <([^>]*)>.+\ncommitter (.+?) <([^>]*)>.+[\S\s]*?\n\n(.*)/m;

function fetchHeadDetails(git, cb) {
exec(`git cat-file -p ${git.head.id}`, (err, response) => {
execFile('git', ['cat-file', '-p', git.head.id], (err, response) => {
if (err) {
return cb(err);
}
Expand All @@ -89,7 +89,7 @@ function fetchHeadDetails(git, cb) {
}

function fetchRemotes(git, cb) {
exec('git remote -v', (err, remotes) => {
execFile('git', ['remote', '-v'], (err, remotes) => {
if (err) {
return cb(err);
}
Expand Down
21 changes: 18 additions & 3 deletions lib/sendToCoveralls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const got = require('got');
const FormData = require('form-data');
const index = require('..');

const sendToCoveralls = async (object, cb) => {
Expand All @@ -16,8 +16,23 @@ const sendToCoveralls = async (object, cb) => {
cb(null, {statusCode: 200});
} else {
try {
const response = await got.post(url, {
json: object,
const form = new FormData();
form.append('json', JSON.stringify(object));
const response = await new Promise((resolve, reject) => {
form.submit(url, (err, res) => {
const bodyData = [];
if (err) {
return reject(err);
}
res.on('data', data => bodyData.push(data));
res.on('end', () => {
resolve({
statusCode: res.statusCode,
body: bodyData.join(),
});
});
return;
});
});
cb(null, response);
} catch (error) {
Expand Down
Loading

0 comments on commit 2ff6585

Please sign in to comment.