From 26c18002c8ebafa8f0a085751715bd9c8a46d784 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 10:39:48 +0100 Subject: [PATCH 1/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 21 +++++++++++++++++--- README.md | 3 +++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 39773f7..53e6c3d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,9 +21,12 @@ on: default: "" extra-services: description: "A list of coma separated services. Available services: openldap." - required: false type: string default: "" + code-coverage: + required: false + type: boolean + default: false jobs: ci: @@ -263,14 +266,26 @@ jobs: if: ${{ !cancelled() && hashFiles(format('{0}/phpunit.xml', inputs.plugin-key)) != '' }} run: | echo -e "\033[0;33mExecuting PHPUnit...\033[0m" + PHPUNIT_FLAGS="--colors=always" + if [[ "${{ inputs.code-coverage }}" == "true" ]]; then + PHPUNIT_FLAGS="$PHPUNIT_FLAGS --coverage-text --coverage-clover=clover.xml" + fi + if [[ -f "vendor/bin/phpunit" ]]; then - vendor/bin/phpunit --colors=always + vendor/bin/phpunit $PHPUNIT_FLAGS elif [[ -f "../../vendor/bin/phpunit" ]]; then - ../../vendor/bin/phpunit --colors=always + ../../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 }}/clover.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..66dee31 100644 --- a/README.md +++ b/README.md @@ -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 From aa3f06c218947d1cba535f25570f755e466c8c17 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 11:09:11 +0100 Subject: [PATCH 2/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 53e6c3d..c225ee0 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -264,6 +264,8 @@ jobs: sudo service apache2 start - name: "PHPUnit" if: ${{ !cancelled() && hashFiles(format('{0}/phpunit.xml', inputs.plugin-key)) != '' }} + env: + PCOV_ENABLED: "${{ inputs.code-coverage && '1' || '0' }}" run: | echo -e "\033[0;33mExecuting PHPUnit...\033[0m" PHPUNIT_FLAGS="--colors=always" From 20279b2a1386945d38a44a45e774ec42d9746c24 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 11:55:09 +0100 Subject: [PATCH 3/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c225ee0..abf6767 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -266,8 +266,10 @@ jobs: 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" + php -m PHPUNIT_FLAGS="--colors=always" if [[ "${{ inputs.code-coverage }}" == "true" ]]; then PHPUNIT_FLAGS="$PHPUNIT_FLAGS --coverage-text --coverage-clover=clover.xml" From 8b0a19d301bb4dcdd41ebd9f04e256d32697b74a Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 14:27:11 +0100 Subject: [PATCH 4/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index abf6767..a1cd266 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -262,6 +262,20 @@ jobs: shell: "bash" run: | sudo service apache2 start + - name: "Setup coverage driver" + if: ${{ !cancelled() && inputs.code-coverage == true }} + run: | + echo "Checking for coverage driver..." + if ! php -m | grep -q -E 'xdebug|pcov'; then + echo -e "\033[0;33mInstalling PCOV driver...\033[0m" + sudo pecl install pcov + sudo docker-php-ext-enable pcov + echo "Verifying installation:" + php -m | grep pcov || echo "PCOV not found in modules after install!" + php --ini + else + echo "Coverage driver already present." + fi - name: "PHPUnit" if: ${{ !cancelled() && hashFiles(format('{0}/phpunit.xml', inputs.plugin-key)) != '' }} env: From 7709dde3504d9a32ca8f2fbd01dfdeca3d9df168 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 15:17:50 +0100 Subject: [PATCH 5/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a1cd266..8d77c69 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -264,6 +264,7 @@ jobs: sudo service apache2 start - name: "Setup coverage driver" if: ${{ !cancelled() && inputs.code-coverage == true }} + shell: "bash" run: | echo "Checking for coverage driver..." if ! php -m | grep -q -E 'xdebug|pcov'; then From 470257cff893a12ddb8199308b346f64fb9b3a57 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 15:25:29 +0100 Subject: [PATCH 6/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8d77c69..293a8d3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -269,14 +269,12 @@ jobs: echo "Checking for coverage driver..." if ! php -m | grep -q -E 'xdebug|pcov'; then echo -e "\033[0;33mInstalling PCOV driver...\033[0m" - sudo pecl install pcov - sudo docker-php-ext-enable pcov - echo "Verifying installation:" - php -m | grep pcov || echo "PCOV not found in modules after install!" - php --ini + # Install pcov but ignore failure if already installed + sudo pecl install pcov || true else echo "Coverage driver already present." fi + - name: "PHPUnit" if: ${{ !cancelled() && hashFiles(format('{0}/phpunit.xml', inputs.plugin-key)) != '' }} env: @@ -286,14 +284,18 @@ jobs: echo -e "\033[0;33mExecuting PHPUnit...\033[0m" php -m PHPUNIT_FLAGS="--colors=always" + PHP_CMD="php" + if [[ "${{ inputs.code-coverage }}" == "true" ]]; then PHPUNIT_FLAGS="$PHPUNIT_FLAGS --coverage-text --coverage-clover=clover.xml" + # Explicitly load PCOV if needed + PHP_CMD="php -d extension=pcov.so" fi if [[ -f "vendor/bin/phpunit" ]]; then - vendor/bin/phpunit $PHPUNIT_FLAGS + $PHP_CMD vendor/bin/phpunit $PHPUNIT_FLAGS elif [[ -f "../../vendor/bin/phpunit" ]]; then - ../../vendor/bin/phpunit $PHPUNIT_FLAGS + $PHP_CMD ../../vendor/bin/phpunit $PHPUNIT_FLAGS else echo -e "\033[0;31mPHPUnit binary not found!\033[0m" exit 1 From 38869ff28b822a296aba4c877f9d738bf08a8ef0 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Tue, 23 Dec 2025 15:42:19 +0100 Subject: [PATCH 7/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 293a8d3..18dbf7b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -266,13 +266,9 @@ jobs: if: ${{ !cancelled() && inputs.code-coverage == true }} shell: "bash" run: | - echo "Checking for coverage driver..." if ! php -m | grep -q -E 'xdebug|pcov'; then echo -e "\033[0;33mInstalling PCOV driver...\033[0m" - # Install pcov but ignore failure if already installed sudo pecl install pcov || true - else - echo "Coverage driver already present." fi - name: "PHPUnit" @@ -282,12 +278,11 @@ jobs: XDEBUG_MODE: "${{ inputs.code-coverage && 'coverage' || 'off' }}" run: | echo -e "\033[0;33mExecuting PHPUnit...\033[0m" - php -m PHPUNIT_FLAGS="--colors=always" PHP_CMD="php" if [[ "${{ inputs.code-coverage }}" == "true" ]]; then - PHPUNIT_FLAGS="$PHPUNIT_FLAGS --coverage-text --coverage-clover=clover.xml" + PHPUNIT_FLAGS="$PHPUNIT_FLAGS --coverage-text --coverage-cobertura=cobertura.xml" # Explicitly load PCOV if needed PHP_CMD="php -d extension=pcov.so" fi @@ -305,7 +300,7 @@ jobs: if: ${{ !cancelled() && inputs.code-coverage == true }} with: name: "coverage-report" - path: "/var/www/glpi/plugins/${{ inputs.plugin-key }}/clover.xml" + 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)) != '' }} From 28f6871f02fe959cc9056fc53db0ab191f2f6b72 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Wed, 31 Dec 2025 11:04:42 +0100 Subject: [PATCH 8/9] feat: enable code coverage --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 18dbf7b..f1ff898 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,6 +21,7 @@ on: default: "" extra-services: description: "A list of coma separated services. Available services: openldap." + required: false type: string default: "" code-coverage: From 50ee37ce4a166fc49d7450b08e1a0f356f4e61d2 Mon Sep 17 00:00:00 2001 From: Benoit VIGNAL Date: Wed, 31 Dec 2025 11:07:19 +0100 Subject: [PATCH 9/9] chore: increase default version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66dee31..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"