Laravel continuous integration on GitLab CI/CD
A few common build and QA routines, including static analysis and validation of PHP code and Laravel best practices.
A few common build and QA routines, including static analysis and validation of PHP code and Laravel best practices.
General | variables.yml |
Build | assets.yml vendor.yml |
Lint | cs-fixer.yml .php_cs eslint.yml .eslintrc.js for Vue .eslintrc.js for React |
Static Analysis | phan.yml phpcpd.yml phpmd.yml phpmnd.yml |
Tests | phpunit.yml dusk.yml |
Security | security-check.yml |
The example below can be used to run GitLab CI/CD jobs for your Laravel application.
Requirements: all jobs have a dind tag, which is meant to indicate a pre-configured GitLab Runner on your repository that can run Docker-in-Docker jobs.
.gitlab-ci.yml
include: # default variables - https://ci.kool.dev/laravel/gitlab/variables.yml # jobs - https://ci.kool.dev/laravel/gitlab/vendor.yml - https://ci.kool.dev/laravel/gitlab/assets.yml - https://ci.kool.dev/laravel/gitlab/eslint.yml - https://ci.kool.dev/laravel/gitlab/security-check.yml - https://ci.kool.dev/laravel/gitlab/cs-fixer.yml - https://ci.kool.dev/laravel/gitlab/phpmnd.yml - https://ci.kool.dev/laravel/gitlab/phpmd.yml - https://ci.kool.dev/laravel/gitlab/phpcpd.yml - https://ci.kool.dev/laravel/gitlab/phan.yml - https://ci.kool.dev/laravel/gitlab/dusk.yml - https://ci.kool.dev/laravel/gitlab/phpunit.yml # build vendor: extends: .vendor assets: extends: .assets # QA eslint: extends: .eslint php-cs-fixer: extends: .cs-fixer phpmd: extends: .phpmd security-check: extends: .security-check phpmnd: extends: .phpmnd phpcpd: extends: .phpcpd phan: extends: .phan dusk: extends: .dusk phpunit: extends: .phpunit
And in your kool.yml, make sure to add the following QA help tasks to the default Laravel preset. You can run these tasks locally, and they'll be used by the CI jobs above:
# make sure to add phpqa since it will be used by all other commands # the image used here is pinned to a known working version with the # commands configured in this sample kool.yml phpqa: kool docker jakzal/phpqa:php7.4-alpine # helpful to sync up service dependencies - used when we need to wait for services to startup wait-services: kool exec app dockerize -wait tcp://database:3306 -wait tcp://cache:6379 -timeout 30s # quality assurance tools eslint: kool run yarn lint phan: kool run phpqa phan --color -p -l app -iy 5 phpcpd: kool run phpqa phpcpd --fuzzy app phpmd: kool run phpqa phpmd app text phpmd/codesize.xml,phpmd/controversial.xml,phpmd/design.xml,phpmd/naming.xml,unusedcode,phpmd/cleancode.xml phpmnd: kool run phpqa phpmnd app --ignore-funcs=round,sleep,abort,strpad,number_format --exclude=tests --progress --extensions=default_parameter,-return,argument php-security-checker: kool run phpqa local-php-security-checker phpunit: kool exec app ./vendor/bin/phpunit start:chrome: kool docker -- --name="chromedriver" --network=$KOOL_GLOBAL_NETWORK -d --shm-size=256M fireworkweb/chromedriver:latest stop:chrome: docker stop chromedriver dusk: kool run artisan dusk php-cs-fixer: kool run phpqa php-cs-fixer fix --diff --diff-format=udiff --verbose php-cs-fixer-check: kool run php-cs-fixer --dry-run