Created
April 29, 2022 20:48
-
-
Save nexxai/f052da7a59ffee88f3297b0c88dafaa1 to your computer and use it in GitHub Desktop.
Laravel - Full Github Action with CodeCov integration and security checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deployment | |
on: | |
push: | |
branches: [ dev ] | |
pull_request: | |
branches: [ master ] | |
workflow_dispatch: | |
jobs: | |
composer: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
- name: Setup PHP with composer v2 | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.1' | |
tools: composer:v2 | |
- name: Install composer packages | |
run: | | |
php -v | |
composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts | |
- name: 'Compress composer folder' | |
run: tar -czvf composer.tgz vendor/ | |
- name: Upload composer assets | |
uses: actions/upload-artifact@v2 | |
with: | |
name: composer | |
path: composer.tgz | |
retention-days: 3 | |
npm: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
- name: npm install | |
run: | | |
npm --version | |
npm install | |
- name: 'Compress node_modules folder' | |
run: tar -czvf node_modules.tgz node_modules/ | |
- name: Upload node_modules assets | |
uses: actions/upload-artifact@v2 | |
with: | |
name: node_modules | |
path: node_modules.tgz | |
retention-days: 3 | |
build_assets: | |
runs-on: ubuntu-latest | |
needs: [composer, npm] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
- name: Download npm artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: node_modules | |
- name: Unpack artifacts | |
run: | | |
tar xvfz node_modules.tgz | |
- name: npm install | |
run: | | |
npm --version | |
npm run production | |
- name: 'Compress public folder' | |
run: tar -czvf public.tgz public/ | |
- name: Upload public assets | |
uses: actions/upload-artifact@v2 | |
with: | |
name: public | |
path: public.tgz | |
retention-days: 3 | |
phpunit: | |
runs-on: ubuntu-latest | |
needs: [build_assets] | |
services: | |
mariadb: | |
image: mariadb:10.3 | |
env: | |
MYSQL_ROOT_PASSWORD: root | |
ports: | |
- 3306:3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Download npm artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: node_modules | |
- name: Download composer artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: composer | |
- name: Download public artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: public | |
- name: Unpack artifacts | |
run: | | |
tar xvfz node_modules.tgz | |
tar xvfz public.tgz | |
tar xvfz composer.tgz | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.1' | |
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick | |
coverage: xdebug | |
- name: Create temp database | |
run: | | |
mysql --host 127.0.0.1 -uroot -proot -e "CREATE DATABASE IF NOT EXISTS laravel_db" | |
- name: Execute tests | |
run: | | |
cp .env.github .env | |
php -v | |
php artisan migrate --force | |
php artisan key:generate | |
php artisan passport:install | |
./vendor/phpunit/phpunit/phpunit --version | |
phpdbg -qrr ./vendor/phpunit/phpunit/phpunit -v --colors=never --stderr --coverage-clover=coverage.xml | |
export CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} | |
bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload' | |
- name: Upload log artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: logs | |
path: ~/storage/logs | |
retention-days: 3 | |
phpcpd: | |
runs-on: ubuntu-latest | |
needs: [build_assets] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
- name: Install phpcpd | |
run: test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar | |
- name: Run phpcpd | |
run: php phpcpd.phar app/ --min-lines=50 | |
fabpot-security-checker: | |
runs-on: ubuntu-latest | |
needs: [build_assets] | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v2 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
- name: Install security-checker | |
run: | | |
test -d local-php-security-checker || curl -L https://github.com/fabpot/local-php-security-checker/releases/download/v1.2.0/local-php-security-checker_1.2.0_linux_amd64 --output local-php-security-checker | |
chmod +x local-php-security-checker | |
./local-php-security-checker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment