diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 00000000..e33aa345 --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,42 @@ +name: "Code Coverage" +on: + pull_request: + branches: [ "main", "master" ] + +jobs: + coverage: + name: Overall Coverage Check + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + + strategy: + matrix: + python-version: ["3.11"] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install tox + run: | + python -m pip install --upgrade pip + pip install tox + + - name: Run Unit Tests with Coverage + run: | + tox -e coverage + + - name: Upload Coverage Report + uses: actions/upload-artifact@v4 + if: always() + with: + name: coverage-report + path: coverage.xml diff --git a/tox.ini b/tox.ini index 1751b2ee..e2fd7d55 100644 --- a/tox.ini +++ b/tox.ini @@ -23,3 +23,11 @@ commands = description = Run integration tests commands = pytest test/integration_tests + +[testenv:coverage] +description = Run unit tests with coverage +deps = + pytest-cov + -e . +commands = + pytest test/unit_tests --cov=sagemaker.hyperpod --cov-report=term-missing --cov-report=xml:coverage.xml --cov-fail-under=70