Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(readme): switch to dynamic coverage badge #116

Merged
merged 1 commit into from
Jan 29, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog Light
[![Build Status](https://github.com/cdcabrera/changelog-light/workflows/Build/badge.svg?branch=main)](https://github.com/cdcabrera/changelog-light/actions?query=workflow%3ABuild)
[![codecov](https://codecov.io/gh/cdcabrera/changelog-light/branch/main/graph/badge.svg)](https://codecov.io/gh/cdcabrera/changelog-light)
![coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fcdcabrera%2Fchangelog-light%2Fmain%2Fpackage.json&query=%24.coverage.pct&suffix=%25&label=coverage&color=9F3FC0)
[![License](https://img.shields.io/github/license/cdcabrera/changelog-light.svg)](https://github.com/cdcabrera/changelog-light/blob/main/LICENSE)

Generate a changelog with [conventional commit types](https://www.conventionalcommits.org).
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"build:deps": "bash ./scripts/dependencies.sh --doctor -u --doctorInstall \"yarn\" --doctorTest \"yarn test:deps\"",
"build:docs": "run-s -l test:docs docs:md",
"docs:md": "node ./scripts/readme.docs.js",
"release": "node ./bin/cli.js",
"release": "run-s release:test release:coverage release:commit",
"release:commit": "node ./bin/cli.js",
"release:coverage": "node ./scripts/coverage.build.js",
"release:test": "export CI=true; jest --collectCoverage --coverageReporters=\"json-summary\"",
"start": "./bin/cli.js",
"test": "run-s -l test:lint test:spell* test:ci",
"test:ci": "export CI=true; jest --collectCoverage",
Expand All @@ -47,6 +50,12 @@
"test:spell-docs": "cspell ./README.md ./CONTRIBUTING.md --config ./cspell.config.json",
"test:spell": "cspell './src/**/*.js' './tests/**/*.js' --config ./cspell.config.json"
},
"coverage": {
"total": 214,
"covered": 202,
"skipped": 0,
"pct": 94.39
},
"jest": {
"roots": [
"src"
Expand Down
30 changes: 30 additions & 0 deletions scripts/coverage.build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require('fs');
const path = require('path');

/**
* Add release coverage totals to package.json for dynamic badge display.
*
* @param {object} options
* @param {string} options.coverageJson
* @param {string} options.packageJson
*/
const addCoverageTotals = ({
coverageJson = path.join(process.cwd(), 'coverage/coverage-summary.json'),
packageJson = path.join(process.cwd(), 'package.json')
} = {}) => {
try {
if (!fs.existsSync(coverageJson) || !fs.existsSync(packageJson)) {
return;
}
const { total } = require(coverageJson);
const resultJsonStr = fs.readFileSync(packageJson);
const resultJson = { ...JSON.parse(resultJsonStr.toString()) };

resultJson.coverage = { ...total?.lines };
fs.writeFileSync(packageJson, JSON.stringify(resultJson, null, 2) + '\n');
} catch (e) {
console.error(new Error(`Add coverage totals: ${e.message}`));
}
};

addCoverageTotals();
Loading