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.

Revisions

  1. AlexKratky revised this gist Mar 22, 2022. No changes.
  2. AlexKratky created this gist Mar 22, 2022.
    23 changes: 23 additions & 0 deletions deploy_script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/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!"
    66 changes: 66 additions & 0 deletions laravel.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    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