Merge pull request #4061 from Icinga/github-actions

GitHub actions
This commit is contained in:
Johannes Meyer 2020-01-23 14:50:41 +01:00 committed by GitHub
commit c4bfbdb720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 137 additions and 76 deletions

113
.github/workflows/php.yml vendored Normal file
View File

@ -0,0 +1,113 @@
name: PHP Tests
on:
push:
branches:
- master
- release/*
pull_request:
branches:
- master
jobs:
lint:
name: Static analysis for php ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
os: ['ubuntu-latest']
include:
- php: '5.6'
allow_failure: true
- php: '7.0'
allow_failure: true
steps:
- name: Checkout code base
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
tools: phpcs
- name: Setup dependencies
run: composer require -n --no-progress overtrue/phplint
- name: PHP Lint
if: success() || matrix.allow_failure
run: ./vendor/bin/phplint -n --exclude={^vendor/.*} --exclude=library/Icinga/Util/String.php -- .
- name: PHP CodeSniffer
if: success() || matrix.allow_failure
run: phpcs
test:
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
phpunit-version: 5.7.27
mockery-version: 0.9.9 # *Any* other version is not compatible with PHP 5.6 and anything above phpunit 6
strategy:
fail-fast: false
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
os: ['ubuntu-latest']
services:
mysql:
image: mariadb
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: icinga_unittest
MYSQL_USER: icinga_unittest
MYSQL_PASSWORD: icinga_unittest
options: >-
--health-cmd "mysql -s -uroot -proot -e'SHOW DATABASES;' 2> /dev/null | grep icinga_unittest > test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306/tcp
pgsql:
image: postgres
env:
POSTGRES_USER: icinga_unittest
POSTGRES_PASSWORD: icinga_unittest
POSTGRES_DB: icinga_unittest
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432/tcp
steps:
- name: Checkout code base
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php }}
tools: phpunit:${{ env.phpunit-version }}
extensions: mysql, pgsql, ldap
- name: Setup dependencies
run: |
sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8
composer require -n --no-progress mockery/mockery:${{ env.mockery-version }}
- name: PHPUnit
env:
ICINGAWEB_TEST_MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
ICINGAWEB_TEST_PGSQL_PORT: ${{ job.services.pgsql.ports['5432'] }}
run: phpunit -c modules/test/phpunit.xml --verbose

View File

@ -1,71 +0,0 @@
language: php
dist: xenial
sudo: false
php:
- '5.6'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- nightly
env:
- CHECK=phpunit
matrix:
include:
- env: CHECK=phpcs
php: '7.4'
- env: CHECK=phpcs
php: '7.3'
- env: CHECK=phpcs
php: '7.2'
- env: CHECK=phpcs
php: '7.1'
- env: CHECK=phpcs
php: '5.6'
- env: CHECK=syntax
php: 'nightly'
- env: CHECK=syntax
php: '7.4'
- env: CHECK=syntax
php: '7.3'
- env: CHECK=syntax
php: '7.2'
- env: CHECK=syntax
php: '7.1'
- env: CHECK=syntax
php: '5.6'
allow_failures:
- php: nightly
services:
- mysql
- postgresql
cache:
directories:
- vendor
branches:
only:
- master
- /^v\d/
notifications:
email: false
# also see: test/setup_vendor.sh
before_script:
- php -m
- '[ -z $LOCALE_GEN ] || sudo locale-gen en_US.UTF-8 de_DE.UTF-8 fr_FR.UTF-8'
- '[ -z $ENABLE_LDAP ] || phpenv config-add test/travis-ldap.ini'
- test/setup_vendor.sh
- 'if [ "$CHECK" = phpunit ]; then test/travis_database.sh; fi'
script:
# also see: modules/test/application/clicommands/PhpCommand.php
- 'if [ "$CHECK" = phpcs ]; then php vendor/phpcs.phar; fi'
- 'if [ "$CHECK" = phpunit ]; then php vendor/phpunit.phar -c modules/test/phpunit.xml --verbose; fi'
- 'if [ "$CHECK" = syntax ]; then php test/check-syntax.php -e "^(\./)?vendor/" -e Icinga/Util/String.php; fi'

View File

@ -1,6 +1,7 @@
# Icinga Web 2
[![Build Status](https://travis-ci.org/Icinga/icingaweb2.png?branch=master)](https://travis-ci.org/Icinga/icingaweb2)
[![PHP Support](https://img.shields.io/badge/php-%3E%3D%205.6-777BB4?logo=PHP)](https://php.net/)
![Build Status](https://github.com/icinga/icingaweb2/workflows/PHP%20Tests/badge.svg?branch=master)
[![Github Tag](https://img.shields.io/github/tag/Icinga/icingaweb2.svg)](https://github.com/Icinga/icingaweb2)
![Icinga Logo](https://icinga.com/wp-content/uploads/2014/06/icinga_logo.png)

View File

@ -210,7 +210,19 @@ namespace Icinga\Test {
protected function createDbConfigFor($name)
{
if (array_key_exists($name, self::$dbConfiguration)) {
return new ConfigObject(self::$dbConfiguration[$name]);
$config = new ConfigObject(self::$dbConfiguration[$name]);
$host = getenv(sprintf('ICINGAWEB_TEST_%s_HOST', strtoupper($name)));
if ($host) {
$config['host'] = $host;
}
$port = getenv(sprintf('ICINGAWEB_TEST_%s_PORT', strtoupper($name)));
if ($port) {
$config['port'] = $port;
}
return $config;
}
throw new RuntimeException('Configuration for database type not available: ' . $name);

View File

@ -24,9 +24,15 @@ set_include_path(implode(PATH_SEPARATOR, [
get_include_path()
]));
require_once 'Mockery/Loader.php';
$mockeryLoader = new \Mockery\Loader;
$mockeryLoader->register();
$vendorAutoload = $basePath . '/vendor/autoload.php';
if (file_exists($vendorAutoload)) {
require_once $vendorAutoload;
} else {
require_once 'Mockery/Loader.php';
$mockeryLoader = new \Mockery\Loader;
$mockeryLoader->register();
}
require_once($icingaLibPath . '/Test/ClassLoader.php');