From 3b091562e173a76351be5428832f68fd0259b63e Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sun, 18 Aug 2024 14:58:20 +0200 Subject: [PATCH] feat(cargo-generate): make code coverage optional --- .github/workflows/ci.yaml.liquid | 2 ++ README.md | 3 --- README.md.liquid | 4 ++-- cargo_generate/script.rhai | 19 ++++++++++++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml.liquid b/.github/workflows/ci.yaml.liquid index c6fb8a7..f279e8a 100644 --- a/.github/workflows/ci.yaml.liquid +++ b/.github/workflows/ci.yaml.liquid @@ -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 @@ -157,3 +158,4 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info fail_ci_if_error: true + {%- endif -%} diff --git a/README.md b/README.md index 8fa4dc4..82cf2c4 100644 --- a/README.md +++ b/README.md @@ -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//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 diff --git a/README.md.liquid b/README.md.liquid index 2a6443f..55125dc 100644 --- a/README.md.liquid +++ b/README.md.liquid @@ -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) diff --git a/cargo_generate/script.rhai b/cargo_generate/script.rhai index 04191af..f31a1d6 100644 --- a/cargo_generate/script.rhai +++ b/cargo_generate/script.rhai @@ -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()); @@ -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;