Skip to content

Commit

Permalink
build on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Nov 4, 2021
1 parent 81fa5fe commit 05276f8
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 132 deletions.
40 changes: 0 additions & 40 deletions .appveyor.yml

This file was deleted.

213 changes: 213 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,213 @@
name: "Build"

on:
pull_request:
types: [ "opened", "synchronize", "edited", "reopened" ]
paths-ignore:
- doc/**
push:
paths-ignore:
- doc/**
branches:
- main
- v*.*

env:
php-extensions: mbstring, intl, mysqli, pgsql, sqlsrv-5.10.0-beta1, pdo_sqlsrv-5.10.0-beta1
php-extensions-key: v1
php-tools: "composer:v2, pecl"

jobs:
phpstan:
name: PHPStan

runs-on: ubuntu-latest

strategy:
matrix:
php-version: [ '7.4', '8.0', '8.1' ]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP with pecl extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Run PHPStan
run: composer phpstan

tests:
name: Tests

strategy:
fail-fast: false
matrix:
php-version: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]

runs-on: ubuntu-latest

services:
mysql57:
image: mysql:5.7
env:
MYSQL_DATABASE: nextras_dbal_test
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -ppass"
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 10
mysql80:
image: mysql:8.0
ports:
- 3307:3306
options: --health-cmd="mysqladmin ping -ppass" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=nextras_dbal_test --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
mariadb105:
image: mariadb:10.5
env:
MYSQL_DATABASE: nextras_dbal_test
MYSQL_ROOT_PASSWORD: root
ports:
- 3308:3306
options: >-
--health-cmd "mysqladmin ping -ppass"
--health-interval 10s
--health-start-period 10s
--health-timeout 5s
--health-retries 10
postgres96:
image: postgres:9.6
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nextras_dbal_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres13:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nextras_dbal_test
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mssql:
image: mcr.microsoft.com/mssql/server:latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: YourStrong!Passw0rd
MSSQL_PID: Developer
ports:
- 1433:1433
options: >-
--name=mssql
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Create MS SQL Database
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE nextras_dbal_test'

- name: Setup PHP cache environment
id: php-extensions-cache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.php-extensions }}
key: ${{ env.php-extensions-key }}

- name: Cache PHP extensions
uses: actions/cache@v2
with:
path: ${{ steps.php-extensions-cache.outputs.dir }}
key: ${{ steps.php-extensions-cache.outputs.key }}
restore-keys: ${{ steps.php-extensions-cache.outputs.key }}

- name: Setup PHP with pecl extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.php-extensions }}
tools: ${{ env.php-tools }}
coverage: pcov

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress --no-suggest

- name: Init config
run: cp ./tests/databases.github.ini ./tests/databases.ini

- name: Tests
run: ./tests/run.sh ./tests/cases --coverage ./clover.xml --coverage-src ./src

- name: Print failed expectations
if: ${{ failure() }}
run: |
find tests -name \*.actual -exec echo "--- {}" \; -exec cat {} \; -exec echo \; -exec echo \; && \
find tests -name \*.log -exec echo "--- {}" \; -exec cat {} \; -exec echo \; -exec echo \;
- name: Send coverage report
env:
COVERALLS_PARALLEL: "true"
COVERALLS_FLAG_NAME: run-${{ matrix.php-version }}
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls --prefer-dist --no-interaction --no-progress --no-suggest && \
php-coveralls -v --coverage_clover=./clover.xml --json_path=./coveralls-upload.json
coverage-finish:
name: Code coverage finish
needs: tests
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -k "https://coveralls.io/webhook?repo_name=$GITHUB_REPOSITORY&repo_token=$COVERALLS_REPO_TOKEN" -d "payload[build_num]=$GITHUB_RUN_ID&payload[status]=done"
2 changes: 1 addition & 1 deletion .phpstan.neon
Expand Up @@ -2,7 +2,7 @@ includes:
- phar://%rootDir%/phpstan.phar/conf/bleedingEdge.neon

parameters:
level: max
level: 8
paths:
- src

Expand Down
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -23,9 +23,9 @@
"nette/finder": "~2.5",
"nette/neon": "~3.0",
"phpstan/extension-installer": "1.0.5",
"phpstan/phpstan": "0.12.48",
"phpstan/phpstan-deprecation-rules": "0.12.5",
"phpstan/phpstan-strict-rules": "0.12.5",
"phpstan/phpstan": "1.0.0",
"phpstan/phpstan-deprecation-rules": "1.0.0",
"phpstan/phpstan-strict-rules": "1.0.0",
"symfony/config": "~4.4 || ~5.0",
"symfony/dependency-injection": "~4.4 || ~5.0",
"symfony/http-kernel": "~4.4 || ~5.0",
Expand Down
Expand Up @@ -19,7 +19,7 @@ class NextrasDbalExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration($container->getParameter('kernel.debug'));
$configuration = new Configuration((bool) $container->getParameter('kernel.debug'));
$config = $this->processConfiguration($configuration, $configs);

$defaultConnectionName = $config['default_connection'];
Expand Down
1 change: 1 addition & 0 deletions src/Connection.php
Expand Up @@ -348,6 +348,7 @@ private function createDriver(): IDriver
return $this->config['driver'];
} else {
$name = ucfirst($this->config['driver']);
/** @var class-string<IDriver> $class */
$class = "Nextras\\Dbal\\Drivers\\{$name}\\{$name}Driver";
return new $class();
}
Expand Down
1 change: 0 additions & 1 deletion src/Drivers/Mysqli/MysqliDriver.php
Expand Up @@ -378,7 +378,6 @@ public function convertIdentifierToSql(string $value): string
public function convertDateTimeToSql(DateTimeInterface $value): string
{
$valueTimezone = $value->getTimezone();
assert($value instanceof DateTime || $value instanceof DateTimeImmutable);
assert($valueTimezone !== false); // @phpstan-ignore-line
if ($valueTimezone->getName() !== $this->connectionTz->getName()) {
if ($value instanceof DateTimeImmutable) {
Expand Down
8 changes: 6 additions & 2 deletions src/Drivers/Pgsql/PgsqlDriver.php
Expand Up @@ -18,6 +18,7 @@
use Nextras\Dbal\Drivers\Exception\UniqueConstraintViolationException;
use Nextras\Dbal\Drivers\IDriver;
use Nextras\Dbal\Exception\InvalidArgumentException;
use Nextras\Dbal\Exception\InvalidStateException;
use Nextras\Dbal\Exception\NotSupportedException;
use Nextras\Dbal\ILogger;
use Nextras\Dbal\Platforms\IPlatform;
Expand Down Expand Up @@ -296,7 +297,11 @@ public function convertToPhp(string $value, $nativeType)
public function convertStringToSql(string $value): string
{
assert($this->connection !== null);
return pg_escape_literal($this->connection, $value);
$escaped = pg_escape_literal($this->connection, $value);
if ($escaped === false) {
throw new InvalidStateException();
}
return $escaped;
}


Expand Down Expand Up @@ -345,7 +350,6 @@ public function convertIdentifierToSql(string $value): string
public function convertDateTimeToSql(DateTimeInterface $value): string
{
$valueTimezone = $value->getTimezone();
assert($value instanceof DateTime || $value instanceof DateTimeImmutable);
assert($valueTimezone !== false); // @phpstan-ignore-line
if ($valueTimezone->getName() !== $this->connectionTz->getName()) {
if ($value instanceof DateTimeImmutable) {
Expand Down

0 comments on commit 05276f8

Please sign in to comment.