Skip to content

Commit

Permalink
Added history tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
prollandoc committed Sep 10, 2021
1 parent 687be33 commit 1f3a702
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ jobs:
```
> Note that the `Run test suite` step will generate a [`clover` file containing the coverage information](https://openclover.org/documentation). This action will use this file to generate the report.

#### Badge generation

If a "badge" property is defined in the configuration, the update action will generate an SVG badge and commit it in the coverage branch.

#### Coverage history

A file named `coverage-history.json`, persisted in the coverage branch, will be updated at each base coverage update. By querying it and using it in a visualization tool, you'll be able to share metrics regarding your coverage history easily.

### Check

```yaml
Expand Down
20 changes: 20 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10699,6 +10699,7 @@ const COVERAGE_BRANCH = 'coverage';
const COVERAGE_FILES = JSON.parse(core.getInput('files'));
const TOKEN = core.getInput('token');
const REPO = `https://${process.env.GITHUB_ACTOR}:${TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
const HISTORY_FILENAME = 'coverage-history.json';

const fail = (message) => {
core.setFailed(message);
Expand Down Expand Up @@ -10811,6 +10812,13 @@ const fetchBaseCoverage = summaryFile => fetch(`https://raw.githubusercontent.co
}
});

const fetchHistory = () => fetch(`https://raw.githubusercontent.com/${process.env.GITHUB_REPOSITORY}/${COVERAGE_BRANCH}/${HISTORY_FILENAME}`, {
headers: {
'Authorization': `token ${TOKEN}`,
'Accept': 'application/vnd.github.v3.raw'
}
});

const sumCoverages = coverages => {
const out = {
total: 0,
Expand Down Expand Up @@ -10898,6 +10906,8 @@ const buildResultMessage = (oldCoverage, newCoverage) => {
const update = async coverages => {
console.log('Updating base coverage...');
const workingDir = await clone();
const historyFile = await fetchHistory();
const history = historyFile.status === 200 ? (await historyFile.json()) : {};

for (const summaryFile of Object.keys(coverages)) {
const conf = COVERAGE_FILES.find(e => e.summary === summaryFile);
Expand All @@ -10910,7 +10920,17 @@ const update = async coverages => {

fs.writeFileSync(`${workingDir}/${conf.badge}`, await badgeContent.text());
}

if (typeof history[conf.label] === 'undefined') {
history[conf.label] = [];
}

history[conf.label].push({
time: (new Date()).toISOString(),
coverage: coverages[summaryFile].coverage
});
}
fs.writeFileSync(`${workingDir}/${HISTORY_FILENAME}`, JSON.stringify(history));

console.log('Pushing to coverage branch');
await push(workingDir);
Expand Down
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const COVERAGE_BRANCH = 'coverage';
const COVERAGE_FILES = JSON.parse(core.getInput('files'));
const TOKEN = core.getInput('token');
const REPO = `https://${process.env.GITHUB_ACTOR}:${TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
const HISTORY_FILENAME = 'coverage-history.json';

const fail = (message) => {
core.setFailed(message);
Expand Down Expand Up @@ -124,6 +125,13 @@ const fetchBaseCoverage = summaryFile => fetch(`https://raw.githubusercontent.co
}
});

const fetchHistory = () => fetch(`https://raw.githubusercontent.com/${process.env.GITHUB_REPOSITORY}/${COVERAGE_BRANCH}/${HISTORY_FILENAME}`, {
headers: {
'Authorization': `token ${TOKEN}`,
'Accept': 'application/vnd.github.v3.raw'
}
});

const sumCoverages = coverages => {
const out = {
total: 0,
Expand Down Expand Up @@ -211,6 +219,8 @@ const buildResultMessage = (oldCoverage, newCoverage) => {
const update = async coverages => {
console.log('Updating base coverage...');
const workingDir = await clone();
const historyFile = await fetchHistory();
const history = historyFile.status === 200 ? (await historyFile.json()) : {};

for (const summaryFile of Object.keys(coverages)) {
const conf = COVERAGE_FILES.find(e => e.summary === summaryFile);
Expand All @@ -223,7 +233,17 @@ const update = async coverages => {

fs.writeFileSync(`${workingDir}/${conf.badge}`, await badgeContent.text());
}

if (typeof history[conf.label] === 'undefined') {
history[conf.label] = [];
}

history[conf.label].push({
time: (new Date()).toISOString(),
coverage: coverages[summaryFile].coverage
});
}
fs.writeFileSync(`${workingDir}/${HISTORY_FILENAME}`, JSON.stringify(history));

console.log('Pushing to coverage branch');
await push(workingDir);
Expand Down

0 comments on commit 1f3a702

Please sign in to comment.