Skip to content

Commit

Permalink
feat(cargo-generate): make code coverage optional
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbz00 committed Aug 18, 2024
1 parent 55678f5 commit 3b09156
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
- name: Run mdbook test
run: mdbook test
{%- endif -%}
{%- if include_codecov -%}
coverage:
name: Report Code Coverage
runs-on: ubuntu-latest
Expand All @@ -157,3 +158,4 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true
{%- endif -%}
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Create an empty GitHub repository and install [`cargo-generate`](https://github.
cargo generate gibbz00/basic-things
```

#### Tokens

Optional public (graph) codecov token prompt may be filled in by first retrieving it from `https://app.codecov.io/gh/<repository_path>/config/badge`.
CI may expect the presence of both [`CODECOV_TOKEN`](https://docs.codecov.com/docs/adding-the-codecov-token) and [`CARGO_REGISTRY_TOKEN`](https://crates.io/settings/tokens).

### Integrated tools
Expand Down
4 changes: 2 additions & 2 deletions README.md.liquid
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# {{ project-name }}

[![ci_status](https://img.shields.io/github/actions/workflow/status/{{ repository_path }}/ci.yaml?style=for-the-badge)](https://github.com/{{ repository_path }}/actions/workflows/ci.yaml)
{%- if optional_codecov != "" -%}
[![codecov](https://img.shields.io/codecov/c/gh/{{ repository_path }}?token={{ optional_codecov }}&style=for-the-badge)](https://codecov.io/gh/{{ repository_path }})
{%- if codecov_graph_token -%}
[![codecov](https://img.shields.io/codecov/c/gh/{{ repository_path }}?token={{ codecov_graph_token }}&style=for-the-badge)](https://codecov.io/gh/{{ repository_path }})
{%- endif -%}
[![license](https://img.shields.io/github/license/{{ repository_path }}.svg?style=for-the-badge)](https://github.com/{{ repository_path }}/blob/main/LICENSE.md)

Expand Down
19 changes: 18 additions & 1 deletion cargo_generate/script.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template_security_policy();
template_precommit_hooks();
template_book();
prompt_optional_string("architecture_url", "Architecture README.md URL");
prompt_optional_string("codecov", "Public Codecov Token for the README.md badge");
template_code_coverage();

fn template_license() {
variable::set("year", system::date().year.to_string());
Expand Down Expand Up @@ -91,6 +91,23 @@ fn template_precommit_hooks() {
}
}

fn template_code_coverage() {
let include_codecov = prompt_yes_no("include_codecov", "Upload code coverage to Codecov");

if !include_codecov {
file::delete(".github/codecov.yaml");
}

if include_codecov {
let repository_path = variable::get("repository_path");
print("Public Codecov graph token may be found at:")
print(`https://app.codecov.io/gh/${repository_path}/config/badge`)
print("")
print("Include a Covecov badge in README.md?")
prompt_optional_string("codecov_graph_token", "Graph token");
}
}

fn prompt_variable(name, prompt) {
if variable::is_set(name) {
return;
Expand Down

0 comments on commit 3b09156

Please sign in to comment.