Skip to content

Commit

Permalink
Fix coverage job
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Sep 13, 2024
1 parent 76e76dc commit ce502e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 71 deletions.
81 changes: 10 additions & 71 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ concurrency:

env:
FORCE_COLOR: "1" # Make tools pretty
DEFAULT_PYTHON_VERSION: "3.11" # keep in sync with tox.ini
PIP_DISABLE_PIP_VERSION_CHECK: "1" # Don't check for pip updates

permissions: {}

Expand All @@ -32,7 +30,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
Expand All @@ -41,7 +39,7 @@ jobs:
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Define a cache for the virtual environment based on the dependencies file
with:
path: |
Expand All @@ -51,15 +49,15 @@ jobs:
- name: Install the project dependencies
run: poetry install --with test
- name: Run the test
run: poetry run coverage run -m pytest
- name: "Upload coverage data to GH artifacts 📤"
run: |
poetry run coverage run -m pytest
poetry run coverage xml
- name: Upload Coverage to Codecov
if: matrix.python-version == '3.11' && matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
uses: codecov/codecov-action@v4
with:
name: coverage-data
path: .coverage
if-no-files-found: ignore
include-hidden-files: true
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

build-site:
name: "build docs"
Expand Down Expand Up @@ -91,76 +89,17 @@ jobs:
run: |
poetry run sphinx-build docs docs/_build -W
coverage:
name: "Check coverage"
needs: run-pytest
runs-on: ubuntu-latest
# avoid running this on schedule, releases, or workflow_call
if: github.event.workflow_run.event != 'schedule' && github.event.workflow_run.event != 'release' && github.event.workflow_run.event != 'workflow_call'
permissions:
contents: write
pull-requests: write
steps:
- name: "Checkout repository 🛎"
uses: actions/checkout@v4
- name: "Setup CI environment 🛠"
uses: ./.github/actions/set-dev-env
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- run: python -Im pip install --upgrade coverage[toml]
- name: "Download coverage data 📥"
uses: actions/download-artifact@v4
with:
pattern: coverage-data

- name: "Get coverage data & fail if it's <80%"
run: |
# if we decide to check cov across versions and combine
# python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
# report and write to summary.
python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
# report again and fail if under 80%.
python -Im coverage report --fail-under=80
- name: "Upload HTML report if check failed 📤"
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
if: ${{ failure() }}

# seems we need to call this from the main CI workflow first
- name: "Coverage comment 💬"
uses: py-cov-action/python-coverage-comment-action@v3
id: coverage_comment
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Store Pull Request comment to be posted 📤"
uses: actions/upload-artifact@v4
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
# leave default names
name: python-coverage-comment-action
path: python-coverage-comment-action.txt

run-pyright:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install poetry
uses: abatilo/actions-poetry@v3
- name: Setup poetry
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Define a cache for the virtual environment based on the dependencies file
with:
path: |
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ testpaths = ["test_lours", "lours"]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

# Only measure coverage for the lours package
[tool.coverage.run]
source = ["lours"]

0 comments on commit ce502e3

Please sign in to comment.