Skip to content

Commit

Permalink
Fix PHPStan job
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Dec 21, 2024
1 parent 92124db commit 29d8ca7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
34 changes: 19 additions & 15 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,45 @@ jobs:

- name: Run PHPCSFixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff

# Run PHPStan against the module and a PrestaShop release
phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
matrix:
presta-versions: ['9.0.x']
presta-version: [ '9.0.x' ]
# The 8.4 compatibility is not available yet, this should be uncommented whe the phpstan docker is ready
# php-version: [ '8.1', '8.2', '8.3', '8.4' ]
php-version: [ '8.1', '8.2', '8.3' ]
steps:
- name: Pull PrestaShop files (Tag ${{ matrix.presta-versions }})
env:
DISABLE_MAKE: 1
run: docker run -tid --rm -v ps-volume:/var/www/html -v $PWD:/web/module --name temp-ps prestashop/prestashop:${{ matrix.presta-versions }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }})

- name: Checkout
uses: actions/checkout@v4

# Add vendor folder in cache to make next builds faster
- name: Cache vendor folder
uses: actions/cache@v4
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@v4
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name: Wait for container to be loaded
run: |
until docker exec temp-ps ls /var/www/html/vendor/autoload.php 2> /dev/null; do
echo Waiting for docker initialization...
sleep 5
done
- name : Run PHPStan
run: |
docker exec -e _PS_ROOT_DIR_=/var/www/html --workdir=/web/module temp-ps php /var/www/html/vendor/bin/phpstan analyse -c /web/module/tests/phpstan/phpstan-${{ matrix.presta-versions }}.neon --error-format=github
# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
- name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-version }}-${{ matrix.php-version }}))
run: ./tests/phpstan.sh ${{ matrix.presta-version }} ${{ matrix.php-version }}

phpunit:
name: PHPUnit ${{ matrix.presta-versions }}
Expand Down
45 changes: 45 additions & 0 deletions tests/phpstan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
set -e

if [ $# -le 0 ]; then
echo "No version provided. Use:"
echo "tests/phpstan/phpstan.sh [PrestaShop_version]"
exit 1
fi

PS_VERSION=$1
PHP_VERSION=$2
BASEDIR=$(dirname "$0")
MODULEDIR=$(cd $BASEDIR/.. && pwd)

if [ ! -f $MODULEDIR/tests/phpstan/phpstan-$PS_VERSION.neon ]; then
echo "Configuration file for PrestaShop $PS_VERSION does not exist."
echo "Please try another version."
exit 2
fi

# Docker images prestashop/prestashop are used to get source files
echo "Pull PrestaShop files (Tag ${PS_VERSION})"

docker rm -f temp-ps || true
docker run -tid --rm -v ps-volume:/var/www/html -e DISABLE_MAKE=1 --name temp-ps prestashop/prestashop:$PS_VERSION-$PHP_VERSION

# Wait for docker initialization (it may be longer for containers based on branches since they must install dependencies)
until docker exec temp-ps ls /var/www/html/vendor/autoload.php 2> /dev/null; do
echo Waiting for docker initialization...
sleep 5
done

# Clear previous instance of the module in the PrestaShop volume
echo "Clear previous module and copy current one"
docker exec -t temp-ps rm -rf /var/www/html/modules/ps_mbo

echo "Run PHPStan using phpstan-${PS_VERSION}.neon file"
docker run --rm --volumes-from temp-ps \
-v $PWD:/var/www/html/modules/ps_mbo \
-e _PS_ROOT_DIR_=/var/www/html \
-e DISABLE_MAKE=1 \
--workdir=/var/www/html/modules/ps_mbo ghcr.io/phpstan/phpstan:1.10.45-php${PHP_VERSION} \
analyse \
--error-format=github \
--configuration=/var/www/html/modules/ps_mbo/tests/phpstan/phpstan-${PS_VERSION}.neon

0 comments on commit 29d8ca7

Please sign in to comment.