Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use global plugin CI configuration #2

Merged
merged 7 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 0 additions & 6 deletions .github/actions/init_containers-start.sh

This file was deleted.

8 changes: 0 additions & 8 deletions .github/actions/install.sh

This file was deleted.

5 changes: 0 additions & 5 deletions .github/actions/lint.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .github/actions/teardown_containers-cleanup.sh

This file was deleted.

2 changes: 0 additions & 2 deletions .github/actions/tests.sh

This file was deleted.

98 changes: 15 additions & 83 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,93 +8,25 @@ on:
tags:
- "*"
pull_request:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
lint:
name: "Lint"
runs-on: "ubuntu-latest"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
strategy:
fail-fast: false
matrix:
include:
- {php-version: "7.4"}
steps:
- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"
tools: "composer, cs2pr"
- name: "Get Composer cache directory"
id: "composer-cache"
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Restore dependencies cache"
uses: "actions/cache@v3"
with:
path: "${{ steps.composer-cache.outputs.dir }}"
key: "${{ github.job }}-${{ matrix.php-version }}-dependencies-${{ hashFiles('**/composer.lock') }}"

- name: "Install Composer dependencies"
run: |
composer install --ansi --no-interaction --no-progress --prefer-dist

- name: "PHP Parallel Lint"
run: |
vendor/bin/parallel-lint --colors --checkstyle --exclude ./vendor/ . | cs2pr

- name: "PHP_CodeSniffer"
run: |
vendor/bin/phpcs -q --report=checkstyle | cs2pr

- name: "Check for missing/outdated headers"
run: |
vendor/bin/licence-headers-check --ansi --no-interaction

unit-tests:
name: "unit-tests"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
include:
- {php-version: "7.4"}
steps:
- name: "Clean workspace"
run: |
echo "APP_CONTAINER_HOME=${{ runner.temp }}/app_home" >> $GITHUB_ENV
rm -rf "${{ env.APPLICATION_ROOT }}/*"

- name: "Checkout"
uses: "actions/checkout@v3"

- name: "Initialize containers"
run: |
.github/actions/init_containers-start.sh

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: "Install dependencies"
uses: "ramsey/composer-install@v2"

- name: "Install GLPI & plugin"
run: |
.github/actions/install.sh

- name: "Run PHPUnit"
run: |
.github/actions/tests.sh

- name: "Cleanup containers"
if: always()
run: |
${{ github.workspace }}/.github/actions/teardown_containers-cleanup.sh
- {glpi-version: "10.0.x", php-version: "7.4", db-image: "mysql:5.7"}
- {glpi-version: "10.0.x", php-version: "8.0", db-image: "mysql:8.0"}
- {glpi-version: "10.0.x", php-version: "8.1", db-image: "mariadb:10.2"}
- {glpi-version: "10.0.x", php-version: "8.2", db-image: "mariadb:11.0"}
- {glpi-version: "10.0.x", php-version: "8.3-rc", db-image: "mysql:8.0"}
uses: "glpi-project/plugin-ci-workflows/.github/workflows/continuous-integration.yml@v1"
with:
plugin-key: "centreon"
glpi-version: "${{ matrix.glpi-version }}"
php-version: "${{ matrix.php-version }}"
db-image: "${{ matrix.db-image }}"
2 changes: 1 addition & 1 deletion ajax/setDowntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

header("Content-Type: text/html; charset=UTF-8");

if (isset($_POST)) {
if (isset($_POST['params'])) {
$params = $_POST['params'];
$hostid = (int) $_POST['hostid'];
$host = new Host();
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
"glpi-project/tools": "^0.4",
"glpi-project/tools": "^0.7.1",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.7"
},
Expand Down
2 changes: 2 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*/
function plugin_centreon_install()
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down Expand Up @@ -72,6 +73,7 @@ function plugin_centreon_install()
*/
function plugin_centreon_uninstall()
{
/** @var DBmysql $DB */
global $DB;

$tables = [GlpiPlugin\Centreon\Host::getTable(),];
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 2
bootstrapFiles:
- ../../inc/based_config.php
paths:
- src
- front
- ajax
- hook.php
- setup.php
scanDirectories:
- ../../inc
- ../../src
stubFiles:
- ../../stubs/glpi_constants.php
rules:
- GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule
9 changes: 9 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap = "tests/bootstrap.php">
trasher marked this conversation as resolved.
Show resolved Hide resolved
<testsuites>
<testsuite name="Plugin test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 1 addition & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*/
function plugin_init_centreon()
{
/** @var array $PLUGIN_HOOKS */
global $PLUGIN_HOOKS;

$PLUGIN_HOOKS['csrf_compliant']['centreon'] = true;
Expand Down
1 change: 1 addition & 0 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function connectionRequest(array $params = [])

public function diagnostic()
{
$result = [];
try {
$test = $this->connectionRequest(['throw' => true]);

Expand Down
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}


public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)

Check failure on line 53 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:7.4 - mysql:5.7 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Config::getTabNameForItem() is incompatible with type bool.

Check failure on line 53 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.1 - mariadb:10.2 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Config::getTabNameForItem() is incompatible with type bool.

Check failure on line 53 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.0 - mysql:8.0 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Config::getTabNameForItem() is incompatible with type bool.

Check failure on line 53 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.2 - mariadb:11.0 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Config::getTabNameForItem() is incompatible with type bool.

Check failure on line 53 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.3-rc - mysql:8.0 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Config::getTabNameForItem() is incompatible with type bool.
{
switch ($item->getType()) {
case \Config::class:
Expand All @@ -62,7 +62,7 @@
public static function displayTabContentForItem(
CommonGLPI $item,
$tabnum = 1,
$withtemplate = 0

Check failure on line 65 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:7.4 - mysql:5.7 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Config::displayTabContentForItem() is incompatible with type bool.

Check failure on line 65 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.1 - mariadb:10.2 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Config::displayTabContentForItem() is incompatible with type bool.

Check failure on line 65 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.0 - mysql:8.0 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Config::displayTabContentForItem() is incompatible with type bool.

Check failure on line 65 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.2 - mariadb:11.0 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Config::displayTabContentForItem() is incompatible with type bool.

Check failure on line 65 in src/Config.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.3-rc - mysql:8.0 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Config::displayTabContentForItem() is incompatible with type bool.
) {
switch ($item->getType()) {
case \Config::class:
Expand All @@ -74,6 +74,7 @@

public static function showForConfig(\Config $config, $withtemplate = 0)
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

if (!self::canView()) {
Expand Down
1 change: 1 addition & 0 deletions src/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
if ($res["security"]["token"] != null) {
$list = $api->getHostsList();
if ($list != null) {
$items_centreon = [];
foreach ($list["result"] as $item_centreon) {
$items_centreon[] = [
'centreon_id' => $item_centreon["id"],
Expand Down Expand Up @@ -355,7 +356,7 @@
}
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)

Check failure on line 359 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:7.4 - mysql:5.7 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Host::getTabNameForItem() is incompatible with type bool.

Check failure on line 359 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.1 - mariadb:10.2 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Host::getTabNameForItem() is incompatible with type bool.

Check failure on line 359 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.0 - mysql:8.0 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Host::getTabNameForItem() is incompatible with type bool.

Check failure on line 359 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.2 - mariadb:11.0 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Host::getTabNameForItem() is incompatible with type bool.

Check failure on line 359 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.3-rc - mysql:8.0 / Continuous integration

Default value of the parameter #2 $withtemplate (int) of method GlpiPlugin\Centreon\Host::getTabNameForItem() is incompatible with type bool.
{
if ($item instanceof CommonDBTM) {
$nb = countElementsInTable(
Expand All @@ -370,7 +371,7 @@
return '';
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)

Check failure on line 374 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:7.4 - mysql:5.7 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Host::displayTabContentForItem() is incompatible with type bool.

Check failure on line 374 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.1 - mariadb:10.2 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Host::displayTabContentForItem() is incompatible with type bool.

Check failure on line 374 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.0 - mysql:8.0 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Host::displayTabContentForItem() is incompatible with type bool.

Check failure on line 374 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.2 - mariadb:11.0 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Host::displayTabContentForItem() is incompatible with type bool.

Check failure on line 374 in src/Host.php

View workflow job for this annotation

GitHub Actions / GLPI 10.0.x - php:8.3-rc - mysql:8.0 / Continuous integration

Default value of the parameter #3 $withtemplate (int) of method GlpiPlugin\Centreon\Host::displayTabContentForItem() is incompatible with type bool.
{
if ($item instanceof CommonDBTM) {
return self::showForItem($item, $withtemplate);
Expand Down
Loading