diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 702ce18..b1ee8dc 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -4,7 +4,6 @@ on: branches: - main - develop - - features/** jobs: laravel-tests: diff --git a/.github/workflows/psr12-phpstan.yml b/.github/workflows/psr12-phpstan.yml index e10bde4..077c80c 100644 --- a/.github/workflows/psr12-phpstan.yml +++ b/.github/workflows/psr12-phpstan.yml @@ -69,6 +69,7 @@ jobs: - name: Execute Code Static Analysis (PHP Stan + Larastan) run: | + composer require --dev nunomaduro/larastan vendor/bin/phpstan analyse app -c ./vendor/nunomaduro/larastan/extension.neon --level=4 --no-progress diff --git a/.github/workflows/test-mysql.yml b/.github/workflows/test-mysql.yml new file mode 100644 index 0000000..ad6b111 --- /dev/null +++ b/.github/workflows/test-mysql.yml @@ -0,0 +1,120 @@ +# GithHub Actions Workflow generated with Ghygen +# Original configuration: http://gh-actions-yaml-generator.test?code=8fc497996543799704fb7f0b861d766f +name: Test Mysql +on: + push: + branches: + - main + - develop + - features/** + +jobs: + laravel-tests: + runs-on: ubuntu-latest + # Service container Mysql mysql + services: + # Label used to access the service container + mysql: + # Docker Hub image (also with version) + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: db_test_laravel + ## map the "external" 33306 port with the "internal" 3306 + ports: + - 33306:3306 + # Set health checks to wait until mysql database has started (it takes some seconds to start) + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: [ '7.4' ] + dependency-stability: [ prefer-stable ] + + name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} + + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: '14.x' + - name: Cache node_modules directory + uses: actions/cache@v2 + id: node_modules-cache + with: + path: node_modules + key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }} + - name: Install NPM packages + if: steps.node_modules-cache.outputs.cache-hit != 'true' + run: npm ci + - name: Build frontend + run: npm run development + - name: Install PHP versions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + - name: Get Composer Cache Directory 2 + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v2 + id: actions-cache + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Cache PHP dependencies + uses: actions/cache@v2 + id: vendor-cache + with: + path: vendor + key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + if: steps.vendor-cache.outputs.cache-hit != 'true' + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + + - name: Generate key + run: php artisan key:generate + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + - name: Run Migrations + # Set environment + env: + DB_CONNECTION: mysql + DB_DATABASE: db_test_laravel + DB_PORT: 33306 + DB_USER: root + + run: php artisan migrate + + - name: Show Laravel versions + run: php artisan --version + - name: Show dir + run: pwd + - name: PHP Version + run: php --version + + - name: Execute tests (Unit and Feature tests) via PHPUnit + # Set environment + env: + DB_CONNECTION: mysql + DB_DATABASE: db_test_laravel + DB_PORT: 33306 + DB_USER: root + + run: vendor/bin/phpunit --testdox + + + + + + diff --git a/.github/workflows/test-postgresql.yml b/.github/workflows/test-postgresql.yml new file mode 100644 index 0000000..87e8df7 --- /dev/null +++ b/.github/workflows/test-postgresql.yml @@ -0,0 +1,123 @@ +# GithHub Actions Workflow generated with Ghygen +# Original configuration: http://gh-actions-yaml-generator.test?code=98e5e699690e3ac2ae0ffe404d0ed3e9 +name: Test Postgresql +on: + push: + branches: + - main + - develop + - features/** + +jobs: + laravel-tests: + runs-on: ubuntu-latest + # Service container Postgresql postgresql + services: + # Label used to access the service container + postgres: + # Docker Hub image (also with version) + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: db_test_laravel + ## map the "external" 55432 port with the "internal" 5432 + ports: + - 55432:5432 + # Set health checks to wait until postgresql database has started (it takes some seconds to start) + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: [ '8.0' ] + dependency-stability: [ prefer-stable ] + + name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} + + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: '14.x' + - name: Cache node_modules directory + uses: actions/cache@v2 + id: node_modules-cache + with: + path: node_modules + key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }} + - name: Install NPM packages + if: steps.node_modules-cache.outputs.cache-hit != 'true' + run: npm ci + - name: Build frontend + run: npm run development + - name: Install PHP versions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + - name: Get Composer Cache Directory 2 + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v2 + id: actions-cache + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Cache PHP dependencies + uses: actions/cache@v2 + id: vendor-cache + with: + path: vendor + key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + if: steps.vendor-cache.outputs.cache-hit != 'true' + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + + - name: Generate key + run: php artisan key:generate + - name: Directory Permissions + run: chmod -R 777 storage bootstrap/cache + - name: Run Migrations + # Set environment + env: + DB_CONNECTION: pgsql + DB_DATABASE: db_test_laravel + DB_PORT: 55432 + DB_USERNAME: postgres + DB_PASSWORD: postgres + + run: php artisan migrate + + - name: Show Laravel versions + run: php artisan --version + - name: Show dir + run: pwd + - name: PHP Version + run: php --version + + - name: Execute tests (Unit and Feature tests) via PHPUnit + # Set environment + env: + DB_CONNECTION: pgsql + DB_DATABASE: db_test_laravel + DB_PORT: 55432 + DB_USERNAME: postgres + DB_PASSWORD: postgres + + run: vendor/bin/phpunit --testdox + + + + + + diff --git a/.github/workflows/test-sqlite.yml b/.github/workflows/test-sqlite.yml index 9772d82..3028b96 100644 --- a/.github/workflows/test-sqlite.yml +++ b/.github/workflows/test-sqlite.yml @@ -1,5 +1,5 @@ # GithHub Actions Workflow generated with Ghygen -# Original configuration: http://gh-actions-yaml-generator.test?code=f6057d1792446de0d97898542edb1b7b +# Original configuration: http://gh-actions-yaml-generator.test?code=88087e9e46cb297901790a7eb7aa424c name: Test Sqlite on: push: @@ -15,7 +15,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: [ '8.0' ] + php-versions: [ '7.4' ] dependency-stability: [ prefer-stable ] name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}} @@ -26,7 +26,14 @@ jobs: uses: actions/setup-node@v1 with: node-version: '14.x' + - name: Cache node_modules directory + uses: actions/cache@v2 + id: node_modules-cache + with: + path: node_modules + key: ${{ runner.OS }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }} - name: Install NPM packages + if: steps.node_modules-cache.outputs.cache-hit != 'true' run: npm ci - name: Build frontend run: npm run development @@ -34,6 +41,23 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} + - name: Get Composer Cache Directory 2 + id: composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v2 + id: actions-cache + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + - name: Cache PHP dependencies + uses: actions/cache@v2 + id: vendor-cache + with: + path: vendor + key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }} - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - name: Install Dependencies diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95415c4..2ab560c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,6 @@ on: branches: - main - develop - - features/** jobs: laravel-tests: diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a22575..81fcd46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.2.4 - WIP ### Add +- Add Postgresql database ### Change - Fix Dashboard when some old data is loaded (isMysqlService vs dataType) diff --git a/app/Http/Livewire/ConfiguratorForm.php b/app/Http/Livewire/ConfiguratorForm.php index e7051e4..c30f6cd 100644 --- a/app/Http/Livewire/ConfiguratorForm.php +++ b/app/Http/Livewire/ConfiguratorForm.php @@ -47,6 +47,12 @@ class ConfiguratorForm extends Component public $mysqlVersion; public $mysqlDatabaseName; public $mysqlDatabasePort; + public $postgresqlDatabase; + public $postgresqlPasswordType; // 'skip + public $postgresqlPassword; // password + public $postgresqlVersion; + public $postgresqlDatabaseName; + public $postgresqlDatabasePort; public $stepEnvTemplateFile; // .env.ci public $stepPhpVersions; // 7.4 public $stepNodejs; // false @@ -76,6 +82,10 @@ class ConfiguratorForm extends Component 'mysqlVersion' => 'exclude_unless:databaseType,' . self::DB_TYPE_MYSQL . '|required', 'mysqlDatabaseName' => 'exclude_unless:databaseType,' . self::DB_TYPE_MYSQL . '|required', 'mysqlDatabasePort' => 'exclude_unless:databaseType,' . self::DB_TYPE_MYSQL . '|required|integer', + 'postgresqlVersion' => 'exclude_unless:databaseType,' . self::DB_TYPE_POSTGRESQL . '|required', + 'postgresqlDatabaseName' => 'exclude_unless:databaseType,' . self::DB_TYPE_POSTGRESQL . '|required', + 'postgresqlDatabasePort' => 'exclude_unless:databaseType,' . self::DB_TYPE_POSTGRESQL . '|required|integer', + 'matrixLaravelVersions' => 'exclude_unless:matrixLaravel,1|required', ]; @@ -94,6 +104,12 @@ private function loadDefaults() $this->mysqlVersion = "5.7"; $this->mysqlDatabaseName = "db_test_laravel"; $this->mysqlDatabasePort = 33306; + $this->postgresqlDatabase = "postgresql"; + $this->postgresqlPasswordType = "hardcoded"; + $this->postgresqlPassword = "postgres"; + $this->postgresqlVersion = "latest"; + $this->postgresqlDatabaseName = "db_test_laravel"; + $this->postgresqlDatabasePort = 55432; $this->stepEnvTemplateFile = ".env.example"; $this->stepPhpVersions = ["8.0", "7.4"]; $this->stepNodejs = false; @@ -150,6 +166,29 @@ public function mount() $this->mysqlVersion = $j->mysqlVersion; $this->mysqlDatabaseName = $j->mysqlDatabaseName; $this->mysqlDatabasePort = $j->mysqlDatabasePort; + if (isset($j->postgresqlDatabase)) { + $this->postgresqlDatabase = $j->postgresqlDatabase; + $this->postgresqlPasswordType = + isset($j->postgresqlPasswordType) ? + $j->postgresqlPasswordType : + $this->postgresqlPasswordType; + $this->postgresqlPassword = + isset($j->postgresqlPassword) ? + $j->postgresqlPassword : + $this->postgresqlPassword; + $this->postgresqlVersion = + isset($j->postgresqlVersion) ? + $j->postgresqlVersion : + $this->postgresqlVersion; + $this->postgresqlDatabaseName = + isset($j->postgresqlDatabaseName) ? + $j->postgresqlDatabaseName : + $this->postgresqlDatabaseName; + $this->postgresqlDatabasePort = + isset($j->postgresqlDatabasePort) ? + $j->postgresqlDatabasePort : + $this->postgresqlDatabasePort; + } $this->stepEnvTemplateFile = $j->stepEnvTemplateFile; $this->stepPhpVersions = $j->stepPhpVersions; $this->stepNodejs = $j->stepNodejs; @@ -267,6 +306,12 @@ public function submitForm() "mysqlDatabasePort", "mysqlPassword", "mysqlPasswordType", + "postgresqlDatabase", + "postgresqlVersion", + "postgresqlDatabaseName", + "postgresqlDatabasePort", + "postgresqlPassword", + "postgresqlPasswordType", "name", "on_push", "on_push_branches", diff --git a/app/Http/Livewire/Dashboard/Daily.php b/app/Http/Livewire/Dashboard/Daily.php index 2189fad..0eef510 100644 --- a/app/Http/Livewire/Dashboard/Daily.php +++ b/app/Http/Livewire/Dashboard/Daily.php @@ -13,9 +13,13 @@ class Daily extends Component public function mount() { + $date = DB::raw('DATE(`created_at`) as `date`'); + if (config('database.default') === 'pgsql') { + $date = DB::raw("date_trunc('day', created_at) as date"); + } $this->daily = LogConfiguration::select(array( - DB::raw('DATE(`created_at`) as `date`'), - DB::raw('count(*) as `count`') + $date, + DB::raw('count(*) as count') )) ->groupBy('date') ->orderBy('date', 'DESC') // or ASC diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 3f3fb27..c8614b7 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -34,12 +34,23 @@ public function isSqlite() return false; } + public function isPostgresqlService() + { + if (isset($this->configuration->databaseType)) { + return $this->configuration->databaseType === "postgresql"; + } + return false; + } + public function getDatabaseType() { if ($this->isMysqlService()) { return "Mysql"; } + if ($this->isPostgresqlService()) { + return "Postgresql"; + } if ($this->isSqlite()) { return "Sqlite"; } diff --git a/composer.json b/composer.json index 1464f76..a4cd196 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,3 @@ - { "name": "hifolks/gh-actions-yaml-generator", "type": "project", @@ -33,7 +32,7 @@ "laravel/sail": "^0.0.5", "mockery/mockery": "^1.4.2", "nunomaduro/collision": "^5.0", - "nunomaduro/larastan": "^0.6.13", + "nunomaduro/larastan": "^0.7.1", "phpunit/phpunit": "^9.3.3" }, "config": { diff --git a/composer.lock b/composer.lock index 41c98d1..3a18a6c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "31dd63686a033e94d64736a9c3de5062", + "content-hash": "dce391128eb34e67a297951e74b3a6f9", "packages": [ { "name": "asm89/stack-cors", @@ -1505,16 +1505,16 @@ }, { "name": "livewire/livewire", - "version": "v2.4.1", + "version": "v2.4.2", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "b0cb782674673a67ddfd5910d2fcb5308bb32857" + "reference": "2495387841a3eb03ac62b2c984ccd2574303285b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/b0cb782674673a67ddfd5910d2fcb5308bb32857", - "reference": "b0cb782674673a67ddfd5910d2fcb5308bb32857", + "url": "https://api.github.com/repos/livewire/livewire/zipball/2495387841a3eb03ac62b2c984ccd2574303285b", + "reference": "2495387841a3eb03ac62b2c984ccd2574303285b", "shasum": "" }, "require": { @@ -1565,7 +1565,7 @@ "description": "A front-end framework for Laravel.", "support": { "issues": "https://github.com/livewire/livewire/issues", - "source": "https://github.com/livewire/livewire/tree/v2.4.1" + "source": "https://github.com/livewire/livewire/tree/v2.4.2" }, "funding": [ { @@ -1573,7 +1573,7 @@ "type": "github" } ], - "time": "2021-03-22T14:03:36+00:00" + "time": "2021-04-04T15:46:50+00:00" }, { "name": "monolog/monolog", @@ -6626,16 +6626,16 @@ }, { "name": "nunomaduro/larastan", - "version": "v0.6.13", + "version": "v0.7.1", "source": { "type": "git", "url": "https://github.com/nunomaduro/larastan.git", - "reference": "7a047f7974e6e16d04ee038d86e2c5e6c59e9dfe" + "reference": "bbbe09ec16a565e6423878bd17fc4355fa0d0a4c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/7a047f7974e6e16d04ee038d86e2c5e6c59e9dfe", - "reference": "7a047f7974e6e16d04ee038d86e2c5e6c59e9dfe", + "url": "https://api.github.com/repos/nunomaduro/larastan/zipball/bbbe09ec16a565e6423878bd17fc4355fa0d0a4c", + "reference": "bbbe09ec16a565e6423878bd17fc4355fa0d0a4c", "shasum": "" }, "require": { @@ -6650,7 +6650,7 @@ "illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0", "mockery/mockery": "^0.9 || ^1.0", "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^0.12.65", + "phpstan/phpstan": "0.12.81", "symfony/process": "^4.3 || ^5.0" }, "require-dev": { @@ -6699,7 +6699,7 @@ ], "support": { "issues": "https://github.com/nunomaduro/larastan/issues", - "source": "https://github.com/nunomaduro/larastan/tree/v0.6.13" + "source": "https://github.com/nunomaduro/larastan/tree/v0.7.1" }, "funding": [ { @@ -6719,7 +6719,7 @@ "type": "patreon" } ], - "time": "2021-01-22T12:51:26+00:00" + "time": "2021-03-19T09:41:48+00:00" }, { "name": "phar-io/manifest", @@ -7130,16 +7130,16 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.83", + "version": "0.12.81", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f" + "reference": "0dd5b0ebeff568f7000022ea5f04aa86ad3124b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a967cec6efb46b500dd6d768657336a3ffe699f", - "reference": "4a967cec6efb46b500dd6d768657336a3ffe699f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0dd5b0ebeff568f7000022ea5f04aa86ad3124b8", + "reference": "0dd5b0ebeff568f7000022ea5f04aa86ad3124b8", "shasum": "" }, "require": { @@ -7170,7 +7170,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.83" + "source": "https://github.com/phpstan/phpstan/tree/0.12.81" }, "funding": [ { @@ -7186,7 +7186,7 @@ "type": "tidelift" } ], - "time": "2021-04-03T15:35:45+00:00" + "time": "2021-03-08T22:03:02+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/resources/views/action_yaml.blade.php b/resources/views/action_yaml.blade.php index 90e98b8..2dd1939 100644 --- a/resources/views/action_yaml.blade.php +++ b/resources/views/action_yaml.blade.php @@ -6,6 +6,9 @@ runs-on: ubuntu-latest @if ( $databaseType === "mysql" ) @include('yaml.mysql_service') +@endif +@if ( $databaseType === "postgresql" ) +@include('yaml.postgresql_service') @endif strategy: diff --git a/resources/views/livewire/configurator-form.blade.php b/resources/views/livewire/configurator-form.blade.php index 68bc1e3..37c4c22 100644 --- a/resources/views/livewire/configurator-form.blade.php +++ b/resources/views/livewire/configurator-form.blade.php @@ -79,16 +79,16 @@ -