diff --git a/.github/actions/unit-test/action.yml b/.github/actions/unit-test/action.yml index ccc3300af..7a8eca168 100644 --- a/.github/actions/unit-test/action.yml +++ b/.github/actions/unit-test/action.yml @@ -36,6 +36,18 @@ inputs: default: "" type: string + codecov-token: + description: Token for Codecov upload + required: false + default: "" + type: string + + coverage-file: + description: Coverage file path + required: false + default: "" + type: string + runs: using: "composite" steps: @@ -71,11 +83,11 @@ runs: - name: Run pytest run: | - if [ "${{ inputs.pytest-markers }}" = "" ]; then - pytest - else - pytest -m "${{ inputs.pytest-markers }}" - fi + if [ "${{ inputs.pytest-markers }}" = "" ]; then + export COVERAGE_FILE=.cov/${{ inputs.coverage-file }} && pytest --cov --cov-report=xml:.cov/xml --cov-report=html:.cov/html + else + export COVERAGE_FILE=.cov/${{ inputs.coverage-file }} && pytest -m "${{ inputs.pytest-markers }}" --cov --cov-report=xml:.cov/xml --cov-report=html:.cov/html + fi shell: bash env: PYDYNA_RUN_CONTAINER: ${{ inputs.docker-image }} @@ -96,10 +108,16 @@ runs: name: server_output_tests.txt path: server_output.txt - - name: Upload coverage results - if: ${{ inputs.server-logs == 'true' }} + - name: Upload coverage files + if: ${{ inputs.coverage-file }} uses: actions/upload-artifact@v4 with: - name: coverage-html - path: .cov/html - retention-days: 7 + name: coverage-${{ inputs.coverage-file }}-${{ inputs.python-version }} + path: coverage.xml + + - name: Stop container + if: ${{ inputs.docker-image != '' && inputs.pytest-markers != 'keywords' }} + run: | + docker stop kw_server + docker rm kw_server + shell: bash \ No newline at end of file diff --git a/.github/workflows/ci_cd_pr.yml b/.github/workflows/ci_cd_pr.yml index f143ffa5f..62f53738d 100644 --- a/.github/workflows/ci_cd_pr.yml +++ b/.github/workflows/ci_cd_pr.yml @@ -19,6 +19,7 @@ env: PACKAGE_NAMESPACE: 'ansys.dyna.core' DOCUMENTATION_CNAME: "dyna.docs.pyansys.com" PYDYNA_RUN_CONTAINER: ${{ github.event.inputs.PyDynaRunContainer || 'ghcr.io/ansys/pydyna-run:latest'}} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -148,12 +149,32 @@ jobs: library-name: ${{ env.PACKAGE_NAME }} operating-system: ${{ matrix.os }} python-version: ${{ matrix.python-version }} + + keyword-testing: + name: "Keyword testing for matrix" + # needs: [smoke-tests] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + python-version: ['3.10', '3.11', '3.12', '3.13'] + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Run test with "keywords" marker + uses: ./.github/actions/unit-test + with: + python-version: ${{ matrix.python-version }} + github-token: ${{ secrets.GITHUB_TOKEN }} + pytest-markers: keywords + coverage-file: keywords run-testing: name: Test the "run" subpackage runs-on: ubuntu-latest - needs: [smoke-tests] + # needs: [smoke-tests] steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 @@ -166,36 +187,58 @@ jobs: docker-image: ${{ env.PYDYNA_RUN_CONTAINER }} pytest-markers: run license-server: ${{ secrets.LICENSE_SERVER }} - - keyword-testing: - name: "Keyword testing" - runs-on: ${{ matrix.os }} - needs: [smoke-tests] - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest] - python-version: ['3.10', '3.11', '3.12', '3.13'] - steps: - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - - uses: ./.github/actions/unit-test - with: - python-version: ${{ matrix.python-version }} - github-token: ${{ secrets.GITHUB_TOKEN }} - pytest-markers: keywords + coverage-file: run unit-tests: name: "Testing" runs-on: ubuntu-latest - needs: [run-testing, keyword-testing] + # needs: [keyword-testing, run-testing, codegen-testing] steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: ./.github/actions/unit-test + - name: Run test without marker + uses: ./.github/actions/unit-test with: python-version: ${{ env.MAIN_PYTHON_VERSION }} github-token: ${{ secrets.GITHUB_TOKEN }} server-logs: true + codecov-token: ${{ secrets.CODECOV_TOKEN }} + coverage-file: unittests + + upload-coverage: + name: "Combine coverage" + runs-on: ubuntu-latest + needs: [run-testing, unit-tests] + steps: + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Download coverage files + uses: actions/download-artifact@v4 + with: + pattern: "coverage-*" + path: .cov + + - name: Combine coverage files + run: | + ls -la + pip install coverage codecov + coverage combine .cov/*/coverage.xml + coverage xml -o .cov/coverage.xml + coverage html -d .cov/html + codecov -f .cov/coverage.xml -t ${{ env.CODECOV_TOKEN }} || echo "Codecov did not collect coverage reports" + + - name: Upload coverage results + uses: actions/upload-artifact@v4 + with: + name: coverage-html + path: .cov/html + retention-days: 7 + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 + env: + CODECOV_TOKEN: ${{ env.CODECOV_TOKEN }} + with: + files: .cov/xml build-library: name: "Build library" diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..4c3f86183 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +coverage: + range: 75..100 + round: down + precision: 2 + status: + project: + default: + target: 90% + patch: off + + +codecov: + notify: + wait_for_ci: yes \ No newline at end of file diff --git a/doc/changelog/909.added.md b/doc/changelog/909.added.md new file mode 100644 index 000000000..024ab838a --- /dev/null +++ b/doc/changelog/909.added.md @@ -0,0 +1 @@ +Add coverage diff --git a/pyproject.toml b/pyproject.toml index 4876180ad..9d0dce578 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,6 +119,9 @@ src_paths = ["doc", "src", "tests"] [tool.coverage.run] source = ["ansys.dyna.core"] +omit = [ + "src/ansys/dyna/core/keywords/keyword_classes/auto/*" +] [tool.coverage.report] show_missing = true @@ -126,7 +129,7 @@ show_missing = true [tool.pytest.ini_options] minversion = "7.1" -addopts = "-ra --cov=ansys.dyna.core --cov-report html:.cov/html --cov-report xml:.cov/xml --cov-report term -vv" +addopts = "-ra --cov=ansys.dyna.core" testpaths = ["tests"] markers = """ run: tests that exercise the `run` subpackage