Skip to content

Commit

Permalink
add code-coverage-action & badge
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx committed Oct 21, 2022
1 parent 1d752bb commit e695aa4
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/unit-test copy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: unit test copy

on:
push:
branches: [master, dev, ci/**]
pull_request:
branches: [master, dev, ci/**]
workflow_dispatch:
# Keep this to allow for triggering manually

jobs:
unit-test:
strategy:
matrix:
node-version:
# currently devDependencies require node>=8.9
# - 8 # skip
# - 10 # skip
# - 12 # skip
# - 14 # skip
# - 16 # skip
- 18
os:
- windows-latest
- ubuntu-latest
- macos-latest

runs-on: ${{ matrix.os }}

outputs:
coverage: ${{ steps.coverage-value.outputs.coverage }}

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm install
- name: Test
run: npm test

- name: Coverage Value
id: coverage-value
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 18 }}
run: |
COV=$(node -p 't=require(`./coverage/coverage-summary.json`).total,Math.min(...`lines|statements|functions|branches`.split(`|`).map(k=>t[k].pct))')
echo "coverage=$COV" >> $GITHUB_OUTPUT
badges:
needs: [unit-test]
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@v3
with:
ref: gh-pages
- name: Use Node.js
uses: actions/setup-node@v3

- name: Create Badges
run: |
npm i -g badgen-cli
export COV=${{ needs.unit-test.outputs.coverage }}
COLOR=$(node -p '+process.env.COV >= 95 ? `green` : `orange`')
mkdir -p site_tmp/badges
badgen -j coverage -s $COV% -c $COLOR > site_tmp/badges/coverage.svg
- name: Deploy Badges
run: |
cp -r site_tmp/* .
rm -rf site_tmp
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update badges [skip ci]
branch: gh-pages
4 changes: 4 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ jobs:
run: npm install
- name: Test
run: npm test

- name: Update Coverage Badge
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 8 }}
uses: we-cli/coverage-badge-action@main
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
tmp
.nyc_output
coverage
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# jayin

<a href="https://github.com/fritx/jayin"><img width="90" height="20" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>&nbsp;&nbsp;[![unit](https://github.com/fritx/jayin/actions/workflows/unit-test.yml/badge.svg)](https://github.com/fritx/jayin/actions/workflows/unit-test.yml)&nbsp;&nbsp;[![e2e](https://github.com/fritx/jayin/actions/workflows/e2e-test.yml/badge.svg)](https://github.com/fritx/jayin/actions/workflows/e2e-test.yml)
<a href="https://github.com/fritx/jayin"><img width="90" height="20" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>&nbsp;&nbsp;[![cov](https://we-cli.github.io/jayin/badges/coverage.svg)](https://github.com/fritx/jayin/actions/workflows/unit-test.yml)
&nbsp;&nbsp;[![unit](https://github.com/fritx/jayin/actions/workflows/unit-test.yml/badge.svg)](https://github.com/fritx/jayin/actions/workflows/unit-test.yml)&nbsp;&nbsp;[![e2e](https://github.com/fritx/jayin/actions/workflows/e2e-test.yml/badge.svg)](https://github.com/fritx/jayin/actions/workflows/e2e-test.yml)

Let's say you have a gitignore-like file:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"jayin": "index.js"
},
"scripts": {
"test": "nyc mocha --timeout 5000"
"test": "nyc -r text -r json-summary mocha --timeout 5000"
},
"devDependencies": {
"bufferhelper": "^0.2.1",
Expand Down

0 comments on commit e695aa4

Please sign in to comment.