Skip to content

Commit

Permalink
chore: release (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
timcreatedit authored Apr 7, 2024
2 parents b9a5b66 + 3e47b87 commit ddadcb2
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 70 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ jobs:
Below you will find a short list of all available configuration options, and
what they do.

- `lower_threshold` (optional, default: `100`): The lower threshold for code
- `lower_threshold` (optional, default: `0`): The lower threshold for code
coverage, anything below this is considered a failure.
- `upper_threshold` (optional, default: `100`): The threshold for the coverage
to be considered 'good', anything below this is considered critical.
- `upper_threshold` (optional, default: `0`): The threshold for the coverage to
be considered 'good', anything below this is considered critical.
- `compare_against_base` (optional, default: `true`): Whether to compare against
the base when running in a PR.
- `enforce_threshold` (optional, default: `'total'`): Whether the action should
Expand Down
100 changes: 100 additions & 0 deletions __tests__/message.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { CoveredProject } from '../src/lcov'
import { buildMessage } from '../src/message'

describe('buildMessage', () => {
it('returns an empty string when projects array is empty', () => {
const projects = []
const sha = 'abcdef1234567890'
const result = buildMessage(projects, sha)
expect(result).toEqual('')
})

const projectA = {
name: 'project_a',
description: 'Description A',
pubspecFile: 'packages/project_a/pubspec.yaml',
coverage: [],
coverageBefore: [],
coverageFile: 'packages/project_a/coverage/lcov.info'
}

const projectB = {
name: 'project_b',
description: 'Description B',
pubspecFile: 'packages/project_b/pubspec.yaml',
coverage: [],
coverageBefore: [],
coverageFile: 'packages/project_b/coverage/lcov.info'
}

it('returns the correct message when projects array has one project', () => {
const projects: CoveredProject[] = [projectA]
const sha = 'abcdef1234567890'
const result = buildMessage(projects, sha)
expect(result).toEqual(expected1Project)
})

it('returns the correct message when projects array has two projects', () => {
const projects: CoveredProject[] = [projectA, projectB]
const sha = 'abcdef1234567890'
const result = buildMessage(projects, sha)
expect(result).toEqual(expected2Projects)
})
})

const expected1Project = `# Coverage Report
This is an automatic coverage report for abcdef12, proudly generated by [Dart Coverage Assistant](https://github.com/whynotmake-it/dart-coverage-assistant) 🎯🧪.
## \`project_a\`
Description A
![0% - fail](http://img.shields.io/badge/project_a-0.00%25-critical)\t➡️ 0.00%
<details>
<summary>Coverage Details for <strong>project_a</strong></summary>
| File | Line Percentage | Line Count |
| --- | --- | --- |
</details>
`

const expected2Projects = `# Coverage Report
This is an automatic coverage report for abcdef12, proudly generated by [Dart Coverage Assistant](https://github.com/whynotmake-it/dart-coverage-assistant) 🎯🧪.
## Monorepo coverage
This repository contains 2 Dart projects. This is is the total coverage across all of them:
![0% - fail](http://img.shields.io/badge/0.00%25-critical)\t➡️ 0.00%
## \`project_a\`
Description A
![0% - fail](http://img.shields.io/badge/project_a-0.00%25-critical)\t➡️ 0.00%
<details>
<summary>Coverage Details for <strong>project_a</strong></summary>
| File | Line Percentage | Line Count |
| --- | --- | --- |
</details>
## \`project_b\`
Description B
![0% - fail](http://img.shields.io/badge/project_b-0.00%25-critical)\t➡️ 0.00%
<details>
<summary>Coverage Details for <strong>project_b</strong></summary>
| File | Line Percentage | Line Count |
| --- | --- | --- |
</details>
`
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ inputs:
default: "${{ github.head_ref }}"
required: false
lower_threshold:
description: "The lower threshold for code coverage, anything below this is considered a failure. Defaults to 100"
default: "100"
description: "The lower threshold for code coverage, anything below this is considered a failure. Defaults to 0."
default: "0"
required: false
upper_threshold:
description: "The threshold for the coverage to be considered 'good', anything below this is considered critical. Defaults to 100"
default: "100"
description: "The threshold for the coverage to be considered 'good', anything below this is considered critical. Defaults to 0, we are proud of all coverage here!"
default: "0"
required: false
compare_against_base:
description: "Whether to compare against the base when running in a PR. Defaults to true."
Expand Down
43 changes: 20 additions & 23 deletions dist/index.js

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "dart-coverage-assistant",
"description": "Magical code coverage reports for your Flutter and Dart projects",
"version": "0.0.0",
"author": "",
"version": "0.0.1",
"author": "whynotmake.it",
"private": true,
"homepage": "https://github.com/actions/typescript-action",
"homepage": "https://whynotmake.it",
"repository": {
"type": "git",
"url": "git+https://github.com/actions/typescript-action.git"
"url": "git+https://github.com/whynotmake-it/dart-coverage-assistant"
},
"bugs": {
"url": "https://github.com/actions/typescript-action/issues"
"url": "https://github.com/whynotmake-it/dart-coverage-assistant/issues"
},
"keywords": [
"actions",
Expand Down
6 changes: 1 addition & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ export async function run(): Promise<void> {
const pr = context.payload.pull_request
if (pr) {
core.info(`Building message...`)
const message = buildMessage(
coveredProjects,
pr.html_url ?? '',
pr.head.sha
)
const message = buildMessage(coveredProjects, pr.head.sha)

core.setOutput('message', message)
try {
Expand Down
59 changes: 29 additions & 30 deletions src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ import {
import { Config } from './config'
import { buildBadgeUrl } from './badge'

export function buildMessage(
projects: CoveredProject[],
url: string,
sha: string
): string {
/**
* Builds a markdown message containing the coverage report.
* @param projects The projects to include in the report.
* @param sha The sha of the commit.
* @returns The markdown message.
*/
export function buildMessage(projects: CoveredProject[], sha: string): string {
if (projects.length === 0) {
return ''
}
const shaShort = sha.slice(0, 8)
let md = ''
md += '# Coverage Report\n'
md += `Automatic coverage report for ${shaShort}.\n`
md += '\n'
md += `> Generated by [dart-coverage-assistant](https://github.com/whynotmake-it/dart-coverage-assistant)\n`
md += `This is an automatic coverage report for ${shaShort}, proudly generated by [Dart Coverage Assistant](https://github.com/whynotmake-it/dart-coverage-assistant) 🎯🧪.\n`
md += '\n'
if (projects.length > 1) {
md += buildTotalTable(projects) + '\n'
}

for (const project of projects) {
md += buildTable(project) + '\n'
md += buildForProject(project) + '\n'
}
md += '\n'
return md
}

Expand All @@ -45,16 +44,15 @@ function buildTotalTable(projects: CoveredProject[]): string {
Config.lowerCoverageThreshold,
totalLineCoverage.percentage
)
md += `## Total coverage: \n`
md += `## Monorepo coverage\n`
md += `This repository contains ${projects.length} Dart projects. This is is the total coverage across all of them:\n`
md += '\n'
md += `| Coverage | Diff |\n`
md += `| --- | --- |\n`
md += `| ${badge} | ${buildDiffString(getTotalDiff(projects))} |\n`
md += `${badge}\t${buildDiffString(getTotalDiff(projects))}\n`
}
return md
}

function buildTable(project: CoveredProject): string {
function buildForProject(project: CoveredProject): string {
let md = ''
md += buildHeader(project) + '\n'
md += '\n'
Expand All @@ -68,21 +66,17 @@ function buildHeader(project: CoveredProject): string {
: undefined
const diff = buildDiffString(getDiff(project))

const badgeCell = lineCoverage
? `${buildBadge(
Config.upperCoverageThreshold,
Config.lowerCoverageThreshold,
lineCoverage.percentage
)}`
: ''
const badgeCell = buildBadge(
Config.upperCoverageThreshold,
Config.lowerCoverageThreshold,
lineCoverage?.percentage ?? 0,
project.name
)

let md = `## \`${project.name}\`\n`
md += `${project.description}\n`
md += '\n'
md += `> ${project.description}\n`
md += '\n'
md += '| Coverage | Diff |\n'
md += '| --- | --- |\n'
md += `| ${badgeCell} | ${diff} |\n`
md += `${badgeCell}\t${diff}\n`
return md
}

Expand Down Expand Up @@ -161,9 +155,14 @@ function getTotalDiff(projects: CoveredProject[]): number | undefined {
return current.percentage - before.percentage
}

function buildBadge(upper: number, lower: number, percentage: number): string {
function buildBadge(
upper: number,
lower: number,
percentage: number,
name?: string
): string {
const alt =
percentage >= upper ? 'pass' : percentage >= lower ? 'warning' : 'fail'
const url = buildBadgeUrl(undefined, upper, lower, percentage)
return `![${alt}](${url} "${alt}")`
const url = buildBadgeUrl(name, upper, lower, percentage)
return `![${percentage}% - ${alt}](${url})`
}

0 comments on commit ddadcb2

Please sign in to comment.