Skip to content

Instantly share code, notes, and snippets.

@AlexKratky
Last active April 7, 2022 03:25
Show Gist options
  • Save AlexKratky/5156606a62558d719d0708bc33d4994f to your computer and use it in GitHub Desktop.
Save AlexKratky/5156606a62558d719d0708bc33d4994f to your computer and use it in GitHub Desktop.
Laravel pipeline - composer, code style, php insights, phpstan, database migration, phpunit tests, integration test using Newman (Postman) + PHP built-in server, simple deploy to stage
#!/bin/bash
set -e
echo "โœจ Deploying application..."
echo "๐Ÿ‘‰ Fetching git"
git fetch --all
echo "๐Ÿ‘‰ Pulling git"
git pull
echo "๐Ÿ‘‰ Installing composer"
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
# Run migration if you like to
# php artisan migrate
# reload nginx' php
echo "๐Ÿ‘‰ Reloading php-fpm service to reload OP Cache"
sudo /usr/bin/systemctl reload php8.1-fpm.service
echo "๐Ÿš€ Application deployed!"
name: Laravel
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
laravel-pipeline:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0.28
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: db_test # change db name if you want
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate JWT
run: php artisan jwt:secret
- name: Directory Permissions
run: chmod -R 777 storage
- name: Code style
run: vendor/bin/php-cs-fixer fix --stop-on-violation --dry-run
- name: PHP Insights
run: vendor/bin/phpinsights --no-interaction --min-quality=72 --min-complexity=55 --min-architecture=85 --min-style=87 --config-path="config/insights.php"
- name: Execute static analyse
run: vendor/bin/phpstan analyse
- name: Migrate DB
run: php artisan migrate --force
- name: Seed DB
run: php artisan db:seed
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
- name: Install Node JS ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Install Newman dependency
run: npm install newman
- name: Run the API and Postman's tests
# add --bail to newman to stop on first error
# also check ./postman_collection.json file location
run: |
nohup php -S localhost:8000 -t public/ > phpd.log 2>&1 &
sleep 2
./node_modules/newman/bin/newman.js run ./postman_collection.json
kill -9 `lsof -i:8000 -t`
- name: Deploy to stage
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
script: 'cd /var/www/project && ./deploy_script.sh' # change to your server direcotry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment