diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 39773f7..f1ff898 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -24,6 +24,10 @@ on: required: false type: string default: "" + code-coverage: + required: false + type: boolean + default: false jobs: ci: @@ -259,18 +263,46 @@ jobs: shell: "bash" run: | sudo service apache2 start + - name: "Setup coverage driver" + if: ${{ !cancelled() && inputs.code-coverage == true }} + shell: "bash" + run: | + if ! php -m | grep -q -E 'xdebug|pcov'; then + echo -e "\033[0;33mInstalling PCOV driver...\033[0m" + sudo pecl install pcov || true + fi + - name: "PHPUnit" if: ${{ !cancelled() && hashFiles(format('{0}/phpunit.xml', inputs.plugin-key)) != '' }} + env: + PCOV_ENABLED: "${{ inputs.code-coverage && '1' || '0' }}" + XDEBUG_MODE: "${{ inputs.code-coverage && 'coverage' || 'off' }}" run: | echo -e "\033[0;33mExecuting PHPUnit...\033[0m" + PHPUNIT_FLAGS="--colors=always" + PHP_CMD="php" + + if [[ "${{ inputs.code-coverage }}" == "true" ]]; then + PHPUNIT_FLAGS="$PHPUNIT_FLAGS --coverage-text --coverage-cobertura=cobertura.xml" + # Explicitly load PCOV if needed + PHP_CMD="php -d extension=pcov.so" + fi + if [[ -f "vendor/bin/phpunit" ]]; then - vendor/bin/phpunit --colors=always + $PHP_CMD vendor/bin/phpunit $PHPUNIT_FLAGS elif [[ -f "../../vendor/bin/phpunit" ]]; then - ../../vendor/bin/phpunit --colors=always + $PHP_CMD ../../vendor/bin/phpunit $PHPUNIT_FLAGS else echo -e "\033[0;31mPHPUnit binary not found!\033[0m" exit 1 fi + - name: "Upload coverage report" + uses: "actions/upload-artifact@v4" + if: ${{ !cancelled() && inputs.code-coverage == true }} + with: + name: "coverage-report" + path: "/var/www/glpi/plugins/${{ inputs.plugin-key }}/cobertura.xml" + overwrite: true - name: "Jest" if: ${{ !cancelled() && hashFiles(format('{0}/jest.config.js', inputs.plugin-key)) != '' }} run: | diff --git a/README.md b/README.md index c72f8c8..5a3ca5b 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ jobs: plugin-key: "myplugin" # The version of GLPI on which to run the tests. - glpi-version: "10.0.x" + glpi-version: "11.0.x" # The version of PHP on which to run the tests. - php-version: "8.1" + php-version: "8.2" # The database docker image on which to run the tests. db-image: "mariadb:11.4" @@ -49,6 +49,9 @@ jobs: # Optional extra services (possible values: "openldap"). extra-services: "openldap" + + # Whether to enable code coverage generation (default: false). + code-coverage: true ``` The available `glpi-version`/`php-version` combinations corresponds to the `ghcr.io/glpi-project/githubactions-glpi-apache` images tags