diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9cd8f49 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: CI + +on: + pull_request: + push: + branches: + - "main" + +concurrency: + group: CI + +jobs: + test: + name: Run tests & display/prepare coverage + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - run: pip install -e . + working-directory: subdir + + - run: pytest + working-directory: subdir + + - name: Coverage comment + id: coverage_comment + uses: py-cov-action/python-coverage-comment-action@032f1914e3f12a555f8ca8322f949c24a829072e + with: + GITHUB_TOKEN: ${{ github.token }} + ANNOTATE_MISSING_LINES: true + ANNOTATION_TYPE: notice + COVERAGE_PATH: subdir + SUBPROJECT_ID: "my-great-project" + + - 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/.github/workflows/coverage-comment.yml b/.github/workflows/coverage-comment.yml new file mode 100644 index 0000000..9d2e6a6 --- /dev/null +++ b/.github/workflows/coverage-comment.yml @@ -0,0 +1,25 @@ +name: Post coverage comment + +on: + workflow_run: + workflows: ["CI"] + types: + - completed + +jobs: + test: + name: Publish coverage Comment + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + permissions: + actions: read + pull-requests: write + contents: write + steps: + - name: Post comment + uses: py-cov-action/python-coverage-comment-action@032f1914e3f12a555f8ca8322f949c24a829072e + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} + COVERAGE_PATH: subdir + SUBPROJECT_ID: "my-great-project" diff --git a/subdir/end_to_end_tests_repo/__init__.py b/subdir/end_to_end_tests_repo/__init__.py new file mode 100644 index 0000000..ea5c570 --- /dev/null +++ b/subdir/end_to_end_tests_repo/__init__.py @@ -0,0 +1,18 @@ +from __future__ import annotations + + +def f(a="", b="", c="", d=""): + elements = [] + if a: + elements.append(a) + + if b: + elements.append(b) + + if c: + elements.append(c) + + if d: + elements.append(d) + + return "-".join(elements) diff --git a/subdir/pyproject.toml b/subdir/pyproject.toml new file mode 100644 index 0000000..035a8ff --- /dev/null +++ b/subdir/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "end-to-end-tests" +version = "0.0.0" +dependencies = [ + "pytest", + "pytest-cov", +] + +[tool.setuptools.packages.find] diff --git a/subdir/setup.cfg b/subdir/setup.cfg new file mode 100644 index 0000000..319c688 --- /dev/null +++ b/subdir/setup.cfg @@ -0,0 +1,9 @@ +[coverage:run] +relative_files = true + +[tool:pytest] +addopts = + --cov-report term-missing --cov-branch --cov-report html + --cov=end_to_end_tests_repo -vv --strict-markers -rfE +testpaths = + tests diff --git a/subdir/tests/cases.csv b/subdir/tests/cases.csv new file mode 100644 index 0000000..9ee88e0 --- /dev/null +++ b/subdir/tests/cases.csv @@ -0,0 +1,2 @@ +a,,,,a +a,b,,,a-b diff --git a/subdir/tests/test_f.py b/subdir/tests/test_f.py new file mode 100644 index 0000000..f48c645 --- /dev/null +++ b/subdir/tests/test_f.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +import csv +import pathlib + +import end_to_end_tests_repo +import pytest + + +def load_csv(): + file = pathlib.Path(__file__).parent / "cases.csv" + return list(csv.reader(file.read_text().splitlines())) + + +@pytest.mark.parametrize("a, b, c, d, expected", load_csv()) +def test_f(a, b, c, d, expected): + assert end_to_end_tests_repo.f(a=a, b=b, c=c, d=d) == expected