|
| 1 | +name: Test Workflow with Coverage |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + paths: |
| 9 | + - 'src/backend-api/**/*.py' |
| 10 | + - 'src/backend-api/pyproject.toml' |
| 11 | + - 'src/backend-api/pytest.ini' |
| 12 | + - '.github/workflows/test.yml' |
| 13 | + pull_request: |
| 14 | + types: |
| 15 | + - opened |
| 16 | + - ready_for_review |
| 17 | + - reopened |
| 18 | + - synchronize |
| 19 | + branches: |
| 20 | + - main |
| 21 | + - dev |
| 22 | + paths: |
| 23 | + - 'src/backend-api/**/*.py' |
| 24 | + - 'src/backend-api/pyproject.toml' |
| 25 | + - 'src/backend-api/pytest.ini' |
| 26 | + - '.github/workflows/test.yml' |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + actions: read |
| 31 | + pull-requests: write |
| 32 | + |
| 33 | +jobs: |
| 34 | + backend_tests: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v5 |
| 40 | + |
| 41 | + - name: Set up Python |
| 42 | + uses: actions/setup-python@v6 |
| 43 | + with: |
| 44 | + python-version: "3.12" |
| 45 | + |
| 46 | + - name: Install Backend Dependencies |
| 47 | + run: | |
| 48 | + python -m pip install --upgrade pip |
| 49 | + cd src/backend-api |
| 50 | + pip install -e . |
| 51 | + pip install pytest pytest-cov |
| 52 | +
|
| 53 | + - name: Check if Backend Test Files Exist |
| 54 | + id: check_backend_tests |
| 55 | + run: | |
| 56 | + if [ -z "$(find src/backend-api/src/tests -type f -name 'test_*.py' 2>/dev/null)" ]; then |
| 57 | + echo "No backend test files found, skipping backend tests." |
| 58 | + echo "skip_backend_tests=true" >> $GITHUB_ENV |
| 59 | + else |
| 60 | + echo "Backend test files found, running tests." |
| 61 | + echo "skip_backend_tests=false" >> $GITHUB_ENV |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Run Backend Tests with Coverage |
| 65 | + if: env.skip_backend_tests == 'false' |
| 66 | + run: | |
| 67 | + cd src/backend-api |
| 68 | + PYTHONPATH=src/app pytest src/tests \ |
| 69 | + -c /dev/null \ |
| 70 | + --rootdir=. \ |
| 71 | + --cov=src/app \ |
| 72 | + --cov-report=term-missing \ |
| 73 | + --cov-report=xml:reports/coverage.xml \ |
| 74 | + --junitxml=pytest.xml \ |
| 75 | + -v |
| 76 | +
|
| 77 | + - name: Pytest Coverage Comment |
| 78 | + if: | |
| 79 | + always() && |
| 80 | + github.event_name == 'pull_request' && |
| 81 | + github.event.pull_request.head.repo.fork == false && |
| 82 | + env.skip_backend_tests == 'false' |
| 83 | + uses: MishaKav/pytest-coverage-comment@26f986d2599c288bb62f623d29c2da98609e9cd4 # v1.6.0 |
| 84 | + with: |
| 85 | + pytest-xml-coverage-path: src/backend-api/reports/coverage.xml |
| 86 | + junitxml-path: src/backend-api/pytest.xml |
| 87 | + report-only-changed-files: true |
| 88 | + |
| 89 | + - name: Skip Backend Tests |
| 90 | + if: env.skip_backend_tests == 'true' |
| 91 | + run: | |
| 92 | + echo "Skipping backend tests because no test files were found." |
0 commit comments