Skip to content
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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:

- `junit_folder`: (Optional) A folder containing JUnit XML files. Make sure the name of each file reflects the name of the test suite. In this way, different test suite runs can be grouped under the same test suite.

- `subdirectory`: (Optional) Path prefix for the project being measured. Set this when reporting coverage for a subproject in a monorepo (e.g. `app`, `packages/web`). Multiple jobs running for the same commit with different `subdirectory` values are stored as separate uploads and rolled up into a single consolidated coverage status (see [Monorepo support](#monorepo-support)).

- `devhub_api_key`: (Required) You will need to create an API key in the settings of your installed app and save it as a secret in GitHub
Actions settings.

Expand All @@ -63,6 +65,37 @@ jobs:

- `percentage`: The coverage percentage.

## Monorepo support

For monorepos with multiple projects under one repository, run the action once per project with a different `subdirectory:`. Each upload is stored separately, and the `coverbot` commit status reflects the **consolidated** total across every upload received for that sha.

```yaml
jobs:
coverage-app:
steps:
- uses: devhub-tools/coverbot-action@v1
with:
format: elixir
file: app/cover/excoveralls.json
subdirectory: app
domain: ${{ vars.DEVHUB_DOMAIN }}
devhub_api_key: ${{ secrets.DEVHUB_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}

coverage-web:
steps:
- uses: devhub-tools/coverbot-action@v1
with:
format: lcov
file: web/coverage/lcov.info
subdirectory: web
domain: ${{ vars.DEVHUB_DOMAIN }}
devhub_api_key: ${{ secrets.DEVHUB_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
```

Each job posts to the same `coverbot` status; whichever finishes second sees both totals summed in the message (e.g. `30 lines covered out of 200 (15.00%)`).

## Add the coverage badge to your README.md

```markdown
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36712,6 +36712,7 @@ function run() {
relevant,
percentage,
files,
subdirectory: subdirectory || null,
owner: repoOwner,
repo,
default_branch: (_a = github.context.payload.repository) === null || _a === void 0 ? void 0 : _a.default_branch,
Expand Down Expand Up @@ -36748,7 +36749,7 @@ function run() {
}
octokit.rest.checks.update(Object.assign(Object.assign({}, github.context.repo), { check_run_id: checkRun.id, conclusion: res.result.state }));
if (relevantForPatch && relevantForPatch > 0) {
octokit.rest.repos.createCommitStatus(Object.assign(Object.assign({}, github.context.repo), { sha: res.result.sha, state: Number(patchPercentage) >= Number(percentage) ? "success" : "failure", context: "coverbot (patch)", description: `${coveredForPatch} lines covered out of ${relevantForPatch} (${patchPercentage}%)`, target_url: `https://${domain}/coverbot/coverage/${res.result.id}` }));
octokit.rest.repos.createCommitStatus(Object.assign(Object.assign({}, github.context.repo), { sha: res.result.sha, state: Number(patchPercentage) >= Number(percentage) ? "success" : "failure", context: "coverbot (patch)", description: `${coveredForPatch} lines covered out of ${relevantForPatch} (${patchPercentage}%)`, target_url: `https://${domain}/coverbot/coverage/${res.result.repository_id}/${res.result.sha}` }));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function run(): Promise<void> {
relevant,
percentage,
files,
subdirectory: subdirectory || null,
owner: repoOwner,
repo,
default_branch: github.context.payload.repository?.default_branch,
Expand Down Expand Up @@ -105,7 +106,7 @@ async function run(): Promise<void> {
state: Number(patchPercentage) >= Number(percentage) ? "success" : "failure",
context: "coverbot (patch)",
description: `${coveredForPatch} lines covered out of ${relevantForPatch} (${patchPercentage}%)`,
target_url: `https://${domain}/coverbot/coverage/${res.result.id}`,
target_url: `https://${domain}/coverbot/coverage/${res.result.repository_id}/${res.result.sha}`,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/post-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TypedResponse } from "@actions/http-client/lib/interfaces"

type CoverageResponse = {
id: string
repository_id: string
sha: string
state: "failure" | "success"
message: string
Expand Down
Loading