diff --git a/.github/workflows/continuous-integration.yml.tpl b/.github/workflows/continuous-integration.yml.tpl index e787dbb..3e2490e 100644 --- a/.github/workflows/continuous-integration.yml.tpl +++ b/.github/workflows/continuous-integration.yml.tpl @@ -1,5 +1,8 @@ name: "Continuous integration" +# To enable code coverage reporting, +# ensure that the project variable "CODE_COVERAGE" is set to "true" + on: push: branches: @@ -33,3 +36,35 @@ jobs: glpi-version: "${{ matrix.glpi-version }}" php-version: "${{ matrix.php-version }}" db-image: "${{ matrix.db-image }}" + code-coverage: ${{ vars.CODE_COVERAGE == 'true' }} # Value is obtained from project variables + + coverage-report: + needs: "ci" + if: vars.CODE_COVERAGE == 'true' && github.event_name == 'pull_request' + runs-on: "ubuntu-latest" + name: "Coverage report" + steps: + - name: "Download coverage report" + uses: "actions/download-artifact@v4" + with: + name: "coverage-report" + + - name: "Generate coverage summary" + uses: "irongut/CodeCoverageSummary@v1.3.0" + with: + filename: cobertura.xml + badge: true + fail_below_min: false + format: markdown + hide_branch_rate: false + hide_complexity: true + indicators: true + output: both + thresholds: '50 75' + + - name: "Add coverage comment" + uses: "marocchino/sticky-pull-request-comment@v2" + if: ${{ github.event_name == 'pull_request' }} + with: + header: coverage + path: code-coverage-results.md diff --git a/README.md b/README.md index 47f13e4..ed8fa34 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,11 @@ You can also provide a destination path (ie. if your `empty` directory is not in * `{UNAME}` will be replaced by the uppercased name, * `{YEAR}` will be replaced by the current year. +## Enabling Code coverage +By default, code coverage is disabled. + +If you want to enable it, you have to set your project environment variable `CODE_COVERAGE` to `true`. + ## Updating Your Plugin To import the changes made to the _pluginsGLPI empty_ template into your project,