From 709b61303cc45184510f6464d8033ce211ef38ce Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 3 Apr 2023 17:34:39 -0700 Subject: [PATCH 1/3] Add code coverage --- .github/workflows/pytest.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 02bf93e3..4f5c6b68 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -59,3 +59,18 @@ jobs: -o console_output_style=count \ -p no:sugar \ tests/components/adaptive_lighting + + - name: Run Tests with Coverage + run: | + cd core + pytest --cov=homeassistant --cov-report=html tests/components/adaptive_lighting + + - name: Push Coverage Report to Branch + run: | + git config user.name "GitHub Actions" + git config user.email "actions@users.noreply.github.com" + git checkout -B coverage-report + mv core/htmlcov coverage-report + git add coverage-report + git commit -m "Update coverage report" + git push -f origin coverage-report From 149cf2867d9d724012e91057d989493f484125a1 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 3 Apr 2023 17:35:36 -0700 Subject: [PATCH 2/3] Selective coverage --- .github/workflows/pytest.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 4f5c6b68..409a2871 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -54,8 +54,9 @@ jobs: -qq \ --timeout=9 \ --durations=10 \ - --cov="homeassistant" \ + --cov="homeassistant/components/adaptive_lighting" \ --cov-report=xml \ + --cov-report=html \ -o console_output_style=count \ -p no:sugar \ tests/components/adaptive_lighting From e3e85abaf62c77bfd63d8a5b0373d10ec3fcef75 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 3 Apr 2023 17:38:18 -0700 Subject: [PATCH 3/3] Use ReportGenerator --- .github/workflows/pytest.yaml | 17 ++++++++++++----- Dockerfile | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 409a2871..204c13fe 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -61,17 +61,24 @@ jobs: -p no:sugar \ tests/components/adaptive_lighting - - name: Run Tests with Coverage - run: | - cd core - pytest --cov=homeassistant --cov-report=html tests/components/adaptive_lighting + - name: ReportGenerator + uses: danielpalme/ReportGenerator-GitHub-Action@5.1.19 + with: + reports: 'core/coverage.xml' + targetdir: 'coveragereport' + reporttypes: 'HtmlInline;Cobertura' + assemblyfilters: '+*' + classfilters: '+*' + filefilters: '+*' + verbosity: 'Info' + tag: '${{ github.run_number }}_${{ github.run_id }}' - name: Push Coverage Report to Branch run: | git config user.name "GitHub Actions" git config user.email "actions@users.noreply.github.com" git checkout -B coverage-report - mv core/htmlcov coverage-report + mv coveragereport coverage-report git add coverage-report git commit -m "Update coverage report" git push -f origin coverage-report diff --git a/Dockerfile b/Dockerfile index 45522da8..5358cc78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,7 +49,7 @@ ENTRYPOINT ["python3", \ # Print the 10 slowest tests "--durations=10", \ # Measure code coverage for the 'homeassistant' package - "--cov='homeassistant'", \ + "--cov='homeassistant/components/adaptive_lighting'", \ # Generate an XML report of the code coverage "--cov-report=xml", \ # Generate an HTML report of the code coverage