Skip to content

Commit

Permalink
fix!: better total coverage (#42)
Browse files Browse the repository at this point in the history
* better total badge

* bundle

* better table

* whoopsie bundle

* bundle
  • Loading branch information
timcreatedit authored Dec 21, 2023
1 parent ed77c85 commit 3b8bf88
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 130 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ inputs:
default: "total"
required: false
enforce_forbidden_decrease:
description: 'Whether the action should fail if the coverage decreases. Can be set to "none", "single", or "total". Defaults to "total".'
default: "total"
description: 'Whether the action should fail if the coverage decreases. Can be set to "none", "single", or "total". Defaults to "none".'
default: "none"
required: false
generate_badges:
description: "Whether to generate badges for the coverage on 'push' workflow triggers. Defaults to true."
Expand Down
125 changes: 70 additions & 55 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions src/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@ import * as fs from 'fs'
import { Config } from './config'
import {
CoveredProject,
getProjectPercentage,
getTotalPercentage
getProjectLineCoverage as getProjectLineCoverage,
getTotalPercentage as getTotalLineCoverage
} from './lcov'

export async function generateBadges(
projects: CoveredProject[]
): Promise<void> {
for (const project of projects.filter(p => p.coverage)) {
const percentage = getProjectPercentage(project)
if (percentage === undefined) {
const lineCoverage = getProjectLineCoverage(project)
if (lineCoverage === undefined) {
continue
}
const svg = await buildSvg(
project.name,
Config.upperCoverageThreshold,
Config.lowerCoverageThreshold,
percentage
lineCoverage.percentage
)

const path = project.pubspecFile.split('/').slice(0, -1).join('/')
// write svg to file
fs.writeFileSync(`${path}/coverage.svg`, svg)
}
const totalPercentage = getTotalPercentage(projects)
if (totalPercentage === undefined) {
return
if (projects.length > 1) {
const totalLineCoverage = getTotalLineCoverage(projects)
if (totalLineCoverage === undefined) {
return
}
const svg = await buildSvg(
'Test Coverage',
Config.upperCoverageThreshold,
Config.lowerCoverageThreshold,
totalLineCoverage.percentage
)
fs.writeFileSync(`./coverage-total.svg`, svg)
}
const svg = await buildSvg(
'Test Coverage',
Config.upperCoverageThreshold,
Config.lowerCoverageThreshold,
totalPercentage
)
fs.writeFileSync(`./coverage-total.svg`, svg)
}

export async function buildSvg(
Expand Down
Loading

0 comments on commit 3b8bf88

Please sign in to comment.