Merge pull request #57 from haoyuqi/dependabot/npm_and_yarn/follow-re… #11
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: Deploy | |
on: | |
push: | |
branches: | |
- 'master' | |
paths-ignore: | |
- 'README.md' | |
- 'LICENSE' | |
jobs: | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [ 15.x, 16.x ] | |
php-version: [ 8.x ] | |
services: | |
mysql: | |
image: mysql:5.7 | |
env: | |
MYSQL_ALLOW_EMPTY_PASSWORD: yes | |
MYSQL_DATABASE: laravel | |
ports: | |
- 3306:3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
redis: | |
image: redis | |
ports: | |
- 6379:6379 | |
options: --name redis | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup Timezone | |
uses: zcong1993/setup-timezone@master | |
with: | |
timezone: Asia/Shanghai | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-version }} | |
extensions: redis | |
tools: composer:v2 | |
- name: Setup Node | |
uses: actions/setup-node@v1 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Copy .env | |
run: php -r "file_exists('.env') || copy('.env.ci', '.env');" | |
- name: Composer Install | |
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist | |
- name: Npm Install And Build | |
run: | | |
npm install --quiet | |
npm run dev | |
- name: Generate Key | |
run: php artisan key:generate | |
- name: Directory Permissions | |
run: chmod -R 777 storage bootstrap/cache | |
- name: Database Migrate | |
run: php artisan migrate | |
- name: Upgrade Chrome Driver | |
run: php artisan dusk:chrome-driver `/opt/google/chrome/chrome --version | cut -d " " -f3 | cut -d "." -f1` | |
- name: Start Chrome Drive | |
run: ./vendor/laravel/dusk/bin/chromedriver-linux & | |
- name: Start Web Server | |
run: php artisan serve --host 127.0.0.1 --port 8000 --no-reload & | |
- name: PHPunit Test | |
run: php artisan test | |
- name: Dusk Test | |
run: php artisan dusk | |
env: | |
APP_URL: "http://127.0.0.1:8000" | |
- name: Upload Screenshots | |
if: failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: screenshots | |
path: tests/Browser/screenshots | |
- name: Upload Console Logs | |
if: failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: console | |
path: tests/Browser/console | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: [ test ] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Laravel Down | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: ${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan down' | |
- name: Clear Code | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: | | |
${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && git reset --hard && git clean -df' | |
${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && rm -rf ./vendor/ ./node_modules/' | |
- name: Git Pull | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: ${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && git pull origin master' | |
- name: Composer Install | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: ${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist --no-dev && composer dump-autoload' | |
- name: Node Install | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: ${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && npm install --quiet && npm run prod' | |
- name: Laravel Migrate | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: ${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan migrate --force' | |
- name: Laravel Horizon Restart | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: | | |
${{ secrets.LARAVEL_HORIZON_CONTAINER }} 'supervisorctl reload' | |
${{ secrets.LARAVEL_HORIZON_CONTAINER }} 'cd ${{ secrets.LARAVEL_HORIZON_CODE_PATH }} && php artisan horizon:terminate' | |
- name: Laravel Cache | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: | | |
${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan config:cache' | |
${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan route:cache' | |
${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan view:cache' | |
${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan event:cache' | |
- name: Laravel Up | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
port: ${{ secrets.PORT }} | |
timeout: 2m | |
script: ${{ secrets.WORKSPACE_CONTAINER }} 'cd ${{ secrets.WORKSPACE_CODE_PATH }} && php artisan up' | |
- name: Deploy Test | |
run: curl -Iks ${{ secrets.WEB_HOMEPAGE }} | head -n 1 | grep 200 |