From 844ae6d5f5789a8e63d7c930da4bc3e83bb3c6cd Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Fri, 28 May 2021 09:44:20 +0200 Subject: [PATCH] Added workflow PHP --- .github/workflows/php.yml | 80 ++++++++++++++++++++++++++++++ .php_cs.dist | 11 ++++ tests/index.php | 35 +++++++++++++ tests/phpstan.sh | 28 +++++++++++ tests/phpstan/index.php | 35 +++++++++++++ tests/phpstan/phpstan-1.7.1.2.neon | 2 + tests/phpstan/phpstan-1.7.2.5.neon | 2 + tests/phpstan/phpstan-1.7.3.4.neon | 2 + tests/phpstan/phpstan-1.7.4.4.neon | 2 + tests/phpstan/phpstan-1.7.5.1.neon | 2 + tests/phpstan/phpstan-1.7.6.9.neon | 2 + tests/phpstan/phpstan-1.7.7.3.neon | 2 + tests/phpstan/phpstan-latest.neon | 2 + tests/phpstan/phpstan.neon | 12 +++++ 14 files changed, 217 insertions(+) create mode 100644 .github/workflows/php.yml create mode 100644 .php_cs.dist create mode 100644 tests/index.php create mode 100755 tests/phpstan.sh create mode 100644 tests/phpstan/index.php create mode 100644 tests/phpstan/phpstan-1.7.1.2.neon create mode 100644 tests/phpstan/phpstan-1.7.2.5.neon create mode 100644 tests/phpstan/phpstan-1.7.3.4.neon create mode 100644 tests/phpstan/phpstan-1.7.4.4.neon create mode 100644 tests/phpstan/phpstan-1.7.5.1.neon create mode 100644 tests/phpstan/phpstan-1.7.6.9.neon create mode 100644 tests/phpstan/phpstan-1.7.7.3.neon create mode 100644 tests/phpstan/phpstan-latest.neon create mode 100644 tests/phpstan/phpstan.neon diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..ec34ca2 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,80 @@ +name: PHP tests +on: [push, pull_request] +jobs: + # Check there is no syntax errors in the project + php-linter: + name: PHP Syntax check 5.6|7.2|7.3 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2.0.0 + + - name: PHP syntax checker 5.6 + uses: prestashop/github-action-php-lint/5.6@master + + - name: PHP syntax checker 7.2 + uses: prestashop/github-action-php-lint/7.2@master + + - name: PHP syntax checker 7.3 + uses: prestashop/github-action-php-lint/7.3@master + + # Check the PHP code follow the coding standards + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + - name: Checkout + uses: actions/checkout@v2.0.0 + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: vendor + key: php-${{ hashFiles('composer.lock') }} + + - name: Install dependencies + run: composer install + + - name: Run PHP-CS-Fixer + run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no --diff-format udiff + + # Run PHPStan against the module and a PrestaShop release + phpstan: + name: PHPStan + runs-on: ubuntu-latest + strategy: + matrix: + presta-versions: ['1.7.1.2', '1.7.2.5', '1.7.3.4', '1.7.4.4', '1.7.5.1', '1.7.6.9', '1.7.7.3', 'latest'] + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + + - name: Checkout + uses: actions/checkout@v2.0.0 + + # Add vendor folder in cache to make next builds faster + - name: Cache vendor folder + uses: actions/cache@v1 + with: + path: vendor + key: php-${{ hashFiles('composer.lock') }} + + # Add composer local folder in cache to make next builds faster + - name: Cache composer folder + uses: actions/cache@v1 + with: + path: ~/.composer/cache + key: php-composer-cache + + - run: composer install + + # Docker images prestashop/prestashop may be used, even if the shop remains uninstalled + - name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }}) + run: ./tests/phpstan.sh ${{ matrix.presta-versions }} diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..cf345e8 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,11 @@ +setUsingCache(true) + ->getFinder() + ->in(__DIR__) + ->exclude('vendor'); + +return $config; \ No newline at end of file diff --git a/tests/index.php b/tests/index.php new file mode 100644 index 0000000..18af748 --- /dev/null +++ b/tests/index.php @@ -0,0 +1,35 @@ + + * @copyright 2007-2020 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/tests/phpstan.sh b/tests/phpstan.sh new file mode 100755 index 0000000..4a94362 --- /dev/null +++ b/tests/phpstan.sh @@ -0,0 +1,28 @@ +#!/bin/bash +PS_VERSION=$1 + +set -e + +# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled +echo "Pull PrestaShop files (Tag ${PS_VERSION})" + +docker rm -f temp-ps || true +docker volume rm -f ps-volume || true + +docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION + +# Clear previous instance of the module in the PrestaShop volume +echo "Clear previous module" + +docker exec -t temp-ps rm -rf /var/www/html/modules/ps_mainmenu + +# Run a container for PHPStan, having access to the module content and PrestaShop sources. +# This tool is outside the composer.json because of the compatibility with PHP 5.6 +echo "Run PHPStan using phpstan-${PS_VERSION}.neon file" + +docker run --rm --volumes-from temp-ps \ + -v $PWD:/var/www/html/modules/ps_mainmenu \ + -e _PS_ROOT_DIR_=/var/www/html \ + --workdir=/var/www/html/modules/ps_mainmenu phpstan/phpstan:0.12 \ + analyse \ + --configuration=/var/www/html/modules/ps_mainmenu/tests/phpstan/phpstan-$PS_VERSION.neon diff --git a/tests/phpstan/index.php b/tests/phpstan/index.php new file mode 100644 index 0000000..18af748 --- /dev/null +++ b/tests/phpstan/index.php @@ -0,0 +1,35 @@ + + * @copyright 2007-2020 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; diff --git a/tests/phpstan/phpstan-1.7.1.2.neon b/tests/phpstan/phpstan-1.7.1.2.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.1.2.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-1.7.2.5.neon b/tests/phpstan/phpstan-1.7.2.5.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.2.5.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-1.7.3.4.neon b/tests/phpstan/phpstan-1.7.3.4.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.3.4.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-1.7.4.4.neon b/tests/phpstan/phpstan-1.7.4.4.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.4.4.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-1.7.5.1.neon b/tests/phpstan/phpstan-1.7.5.1.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.5.1.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-1.7.6.9.neon b/tests/phpstan/phpstan-1.7.6.9.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.6.9.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-1.7.7.3.neon b/tests/phpstan/phpstan-1.7.7.3.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-1.7.7.3.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan-latest.neon b/tests/phpstan/phpstan-latest.neon new file mode 100644 index 0000000..03d5d1c --- /dev/null +++ b/tests/phpstan/phpstan-latest.neon @@ -0,0 +1,2 @@ +includes: + - %currentWorkingDirectory%/tests/phpstan/phpstan.neon \ No newline at end of file diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon new file mode 100644 index 0000000..af23c41 --- /dev/null +++ b/tests/phpstan/phpstan.neon @@ -0,0 +1,12 @@ +includes: + - %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon + +parameters: + paths: + # From PHPStan 0.12, paths to check are relative to the neon file + - ../../ps_mainmenu.php + - ../../ps_menutoplinks.class.php + - ../../translations/ + - ../../views/ + reportUnmatchedIgnoredErrors: false + level: 5 \ No newline at end of file