From 8f6f8baad8cc08430568175e68b3f0eccaed30b4 Mon Sep 17 00:00:00 2001 From: Steve C Date: Sun, 7 Jan 2024 16:07:10 -0500 Subject: [PATCH] add coverage to workflow (#8) --- .github/workflows/post-coverage.yml | 23 +++++++++++++++ .github/workflows/test.yml | 44 +++++++++++++++++++++++++++++ pyproject.toml | 1 + requirements_dev.txt | 1 + 4 files changed, 69 insertions(+) create mode 100644 .github/workflows/post-coverage.yml diff --git a/.github/workflows/post-coverage.yml b/.github/workflows/post-coverage.yml new file mode 100644 index 0000000..4441ae4 --- /dev/null +++ b/.github/workflows/post-coverage.yml @@ -0,0 +1,23 @@ +name: Post coverage comment + +on: + workflow_run: + workflows: ["test"] + types: + - completed + +jobs: + test: + name: Display coverage + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + permissions: + pull-requests: write + contents: write + actions: read + steps: + - name: Post comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc144fc..09e6817 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,3 +42,47 @@ jobs: run: | source ./venv/bin/activate PYTHONPATH="$(pwd)" pytest + + coverage: + name: Coverage + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + steps: + - uses: actions/checkout@v4 + + - name: Set up CPython 3.12 + uses: actions/setup-python@v2 + with: + python-version: "3.12" + + - name: Install dependencies + run: | + python -m venv venv + source ./venv/bin/activate + pip install --upgrade pip setuptools wheel pytest setuptools-rust + pip install -U -r requirements_dev.txt + - name: Installing distribution (dev mode) + # this adds the .so to the inner lib files so we can test + run: | + source ./venv/bin/activate + python ./setup.py develop + - name: Run tests + shell: bash + run: | + source ./venv/bin/activate + PYTHONPATH="$(pwd)" coverage run -m pytest + + - name: Coverage comment + id: coverage_comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ 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: + name: python-coverage-comment-action + path: python-coverage-comment-action.txt diff --git a/pyproject.toml b/pyproject.toml index 402bfb2..4a8a29a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ requires = ["setuptools", "wheel", "setuptools-rust"] omit = [ "neofoodclub/types/*", ] +relative_files = true [tool.coverage.report] exclude_lines = [ diff --git a/requirements_dev.txt b/requirements_dev.txt index d21b604..4f196d3 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,3 +1,4 @@ +coverage numpy orjson pytest