Skip to content

chore!: use secure version of godsdev/tools library (#69) #654

chore!: use secure version of godsdev/tools library (#69)

chore!: use secure version of godsdev/tools library (#69) #654

---
name: PHP Composer + PHPUnit + PHPStan
on:
push:
branches-ignore:
# notest branches to ignore testing of partial online commits
- "notest/**"
pull_request:
branches-ignore:
# notest branches to ignore testing of partial online commits
- "notest/**"
permissions:
contents: read
jobs:
build:
runs-on: ${{ matrix.operating-system }}
# Limit the running time
timeout-minutes: 10
strategy:
matrix:
operating-system:
- "ubuntu-latest"
# "7.2", "7.3", ... Different errors caught by PHPStan 1.x than PHPStan 2.x which is preferred
php-version: ["7.4"]
# 7.1 is not checked, as due to https://bugs.php.net/bug.php?id=73803
# ZipArchive class has public properties, that are not visible via reflection.
# Therefore using tools like PHPStan generates error: Access to an undefined property ZipArchive::$numFiles. in class\MyAdminProcess
env:
# same as phinx.dist.yml-testing
DB_DATABASE: testing_db
DB_USER: root
DB_PASSWORD: "root"
#DB_HOST: localhost
steps:
- name: "Checkout"
uses: actions/checkout@v6
with:
persist-credentials: true
- name: "Install PHP ${{ matrix.php-version }} Test on ${{ matrix.operating-system }}"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
tools: composer:v2
# phpstan added by tools is the latest one, which may not be supported: e.g. phpstan:2.0.1 fails php:7.2,7.3
# Note: when phpstan is added by tools phpstan call fails for PHP<7.1
# coverage none turns off Xdebug as in PHP 5.6,7.0 it would change (format) var_dump output
coverage: none
env:
# fixes Error: Could not authenticate against github.com
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "MySQL db ${{ env.DB_DATABASE }}"
run: |
sudo /etc/init.d/mysql start
mysql -V
mysql -e "STATUS" -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
mysql -e 'SHOW DATABASES;' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
# https://github.com/actions/cache
# A repository can have up to 5GB of caches. Once the 5GB limit is reached, older caches will be evicted based on when the cache was last accessed.
# Caches that are not accessed within the last week will also be evicted.
- name: Cache composer dependencies
uses: actions/cache@v5
id: vendor-cache
with:
# path to Checkout working directory is /home/runner/work/repo-name/repo-name , so just add /vendor/
path: ${{ github.workspace }}/vendor/
# Use composer.json for key, if composer.lock is not committed.
key: ${{ runner.os }}-PHP${{ matrix.php-version }}-vendor-${{ hashFiles('**/composer.json') }}
# key: ${{ runner.os }}-PHP${{ matrix.php-version }}-vendor-${{ hashFiles('**/composer.lock') }}
#restore-keys: ${{ runner.os }}-PHP${{ matrix.php-version }}-vendor-
- name: Cache dist composer dependencies
uses: actions/cache@v5
id: dist-vendor-cache
with:
# path to Checkout working directory is /home/runner/work/repo-name/repo-name , so just add /vendor/
path: ${{ github.workspace }}/dist/vendor/
# Use composer.json for key, if composer.lock is not committed.
key: ${{ runner.os }}-PHP${{ matrix.php-version }}-dist-vendor-${{ hashFiles('**/dist/composer.json') }}
# key: ${{ runner.os }}-PHP${{ matrix.php-version }}-vendor-${{ hashFiles('**/composer.lock') }}
#restore-keys: ${{ runner.os }}-PHP${{ matrix.php-version }}-dist-vendor-
- name: Validate composer.json and composer.lock
if: ${{ steps.vendor-cache.outputs.cache-hit != 'true' }}
run: composer validate
- name: Install no-dev dependencies
if: ${{ steps.vendor-cache.outputs.cache-hit != 'true' }}
run: composer update --no-dev --prefer-dist --no-progress
- name: Copy local config files
run: |
# to fix `Constant DB_USERNAME not found.` etc not only for phpstan but also for phpunit tests
cp -p dist/conf/config.local.dist.php dist/conf/config.local.php
# local testing database settings
cp -p dist/phinx.dist.yml dist/phinx.yml
- name: Install dev dependencies
if: ${{ steps.vendor-cache.outputs.cache-hit != 'true' }}
run: composer update --prefer-dist --no-progress
# PHPunit is installed anyway, so it doesn't make sense to use tools: phpunit
- name: "PHPUnit tests (without MySQL)"
run: "vendor/bin/phpunit --configuration ./conf/phpunit-github-actions.xml"
#- name: PHPUnit (php-actions)
# uses: php-actions/phpunit@v5
# with:
# # PHP included in ubuntu-latest does not support iconv //TRANSLIT flag as iconv implementation is unknown
# # https://github.com/actions/virtual-environments/blob/ubuntu18/20201026.1/images/linux/Ubuntu1804-README.md
# # therefore PHPUnit group iconvtranslit should be excluded.
# # Also doesn't make sense to test MySQLi related tests until MySQLi environment is ready.
# # Also HTTP requests to self can't work in CLI only environment.
# configuration: phpunit-github-actions.xml
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
# - name: Run test suite
# run: composer run-script test
- name: Validate composer.json + install no-dev (app)
if: ${{ steps.dist-vendor-cache.outputs.cache-hit != 'true' }}
run: |
cd dist
composer validate
composer update --no-dev --prefer-dist --no-progress
# `cd ..` redundant as each run starts in the root
cd ..
- name: Phinx migration - migrate
if: ${{ matrix.php-version >= '7.1' }} #PHP/5.6 has auth problem with MySQL/8
run: |
cd dist
vendor/bin/phinx migrate -e testing
# `cd ..` redundant as each run starts in the root
cd ..
- name: Check dev dependencies (app)
if: ${{ steps.dist-vendor-cache.outputs.cache-hit != 'true' }}
run: |
cd dist
composer update --prefer-dist --no-progress
# `cd ..` redundant as each run starts in the root
cd ..
# PHPunit is installed anyway, so it doesn't make sense to use tools: phpunit
# Note `sudo /etc/init.d/apache2 start` uses `/etc/apache2/sites-enabled/000-default.conf` where DocumentRoot = `/var/www/html` but without PHP
- name: "PHPUnit tests with MySQL"
if: ${{ matrix.php-version >= '7.1' }}
run: ./vendor/bin/phpunit -c ./conf/phpunit-github-mysql.xml
# PHPStan works for PHP/7.1+ so it can't even be in composer.json
- name: "Composer phpstan-webmozart-assert (app)"
if: ${{ matrix.php-version >= '7.1' && steps.dist-vendor-cache.outputs.cache-hit != 'true' }}
run: |
cd dist
# Only phpstan/phpstan-webmozart-assert + phpstan/phpstan added
composer require --dev phpstan/phpstan-webmozart-assert --prefer-dist --no-progress
#todo return when rector ready for phpstan:1.0#composer require --dev rector/rector --prefer-dist --no-progress
cd ..
- name: "PHPStan webmozart-assert (app)"
if: ${{ matrix.php-version >= '7.2' }}
run: |
cd dist
# show version
./vendor/bin/phpstan.phar -V
# make sure the current files are analyzed
./vendor/bin/phpstan clear-result-cache
# analyze
./vendor/bin/phpstan.phar --configuration=conf/phpstan.webmozart-assert.neon analyse --no-interaction --no-progress .
cd ..
- name: "Composer phpstan-webmozart-assert (library + app)"
if: ${{ matrix.php-version >= '7.1' && steps.vendor-cache.outputs.cache-hit != 'true' }}
run: |
# Only phpstan/phpstan-webmozart-assert + phpstan/phpstan added
composer require --dev phpstan/phpstan-webmozart-assert --prefer-dist --no-progress
- name: "PHPStan webmozart-assert (library + app)"
if: ${{ matrix.php-version >= '7.2' }}
run: |
# show version
./vendor/bin/phpstan.phar -V
# make sure the current files are analyzed
./vendor/bin/phpstan clear-result-cache
# analyze
./vendor/bin/phpstan.phar --configuration=conf/phpstan.webmozart-assert.neon analyse --no-interaction --no-progress .
shell: bash