Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ on:
required: false
type: string
default: ""
code-coverage:
required: false
type: boolean
default: false

jobs:
ci:
Expand Down Expand Up @@ -259,18 +263,46 @@ jobs:
shell: "bash"
run: |
sudo service apache2 start
- name: "Setup coverage driver"
if: ${{ !cancelled() && inputs.code-coverage == true }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For activation, I think we need to follow the same logic as the other steps and test for the presence of the configuration file instead of defining a variable.

Suggested change
if: ${{ !cancelled() && inputs.code-coverage == true }}
if: ${{ !cancelled() && hashFiles(format('{0}/cobertura.xml', inputs.plugin-key)) != '' }}

Same logic every time you test 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: |
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down