Skip to content

Commit

Permalink
Added Github Action for PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Feb 8, 2022
1 parent 25c5150 commit a6703b6
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 0 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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 => 8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- 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

- name: PHP syntax checker 7.4
uses: prestashop/github-action-php-lint/7.4@master

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master

- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@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/[email protected]

- 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', '1.7.7', '1.7.8', 'latest']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Checkout
uses: actions/[email protected]

# 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 }}
11 changes: 11 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$config = new PrestaShop\CodingStandards\CsFixer\Config();

$config
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('vendor');

return $config;
34 changes: 34 additions & 0 deletions tests/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* 2007-2020 PrestaShop SA and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @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;
28 changes: 28 additions & 0 deletions tests/phpstan.sh
Original file line number Diff line number Diff line change
@@ -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/graphnvd3

# 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/graphnvd3 \
-e _PS_ROOT_DIR_=/var/www/html \
--workdir=/var/www/html/modules/graphnvd3 phpstan/phpstan:0.12 \
analyse \
--configuration=/var/www/html/modules/graphnvd3/tests/phpstan/phpstan-$PS_VERSION.neon
34 changes: 34 additions & 0 deletions tests/phpstan/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
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;
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.1.2.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.2.5.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.3.4.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.4.4.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.5.1.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.6.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.7.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.8.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-latest.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
7 changes: 7 additions & 0 deletions tests/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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
- ../../graphnvd3.php
level: 5

0 comments on commit a6703b6

Please sign in to comment.