95 lines
2.6 KiB
YAML
95 lines
2.6 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main, master, develop]
|
|
pull_request:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
mysql:
|
|
image: mysql:8.0
|
|
env:
|
|
MYSQL_ROOT_PASSWORD: root
|
|
MYSQL_DATABASE: laralog_test
|
|
ports:
|
|
- 3306:3306
|
|
options: >-
|
|
--health-cmd="mysqladmin ping -proot"
|
|
--health-interval=10s
|
|
--health-timeout=5s
|
|
--health-retries=5
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup PHP
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.2'
|
|
extensions: mbstring, dom, pdo_mysql, sqlite3, gd, redis
|
|
coverage: none
|
|
|
|
- name: Cache Composer
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: vendor
|
|
key: composer-${{ hashFiles('composer.lock') }}
|
|
|
|
- name: Install dependencies
|
|
run: composer install --no-interaction --prefer-dist --no-progress
|
|
|
|
- name: Env
|
|
run: |
|
|
cp .env.example .env
|
|
php artisan key:generate
|
|
touch database/database.sqlite
|
|
|
|
- name: Lint
|
|
run: |
|
|
find app plugins config database -name '*.php' -print0 | xargs -0 -n1 php -l
|
|
|
|
- name: Migrate & Seed (sqlite)
|
|
run: php artisan migrate --seed --force
|
|
|
|
- name: Run tests (sqlite)
|
|
run: php artisan test
|
|
|
|
# 生产走 MySQL:可选并行 MySQL 测试
|
|
- name: Run tests (mysql)
|
|
env:
|
|
DB_CONNECTION: mysql
|
|
DB_HOST: 127.0.0.1
|
|
DB_PORT: 3306
|
|
DB_DATABASE: laralog_test
|
|
DB_USERNAME: root
|
|
DB_PASSWORD: root
|
|
run: php artisan test
|
|
|
|
# 生产部署示例(SSH + rsync)。真实环境按需开启并配置 secrets:
|
|
# DEPLOY_HOST / DEPLOY_USER / DEPLOY_PATH / DEPLOY_SSH_KEY
|
|
deploy:
|
|
if: github.ref == 'refs/heads/main'
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
environment: production
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Deploy via SSH
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
username: ${{ secrets.DEPLOY_USER }}
|
|
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
script: |
|
|
cd ${{ secrets.DEPLOY_PATH }}
|
|
git pull origin main
|
|
composer install --no-dev --no-interaction --prefer-dist
|
|
php artisan migrate --force
|
|
php artisan config:cache
|
|
php artisan route:cache
|
|
php artisan view:cache
|
|
php artisan theme:publish
|
|
pm2 restart laralog-workerman laralog-schedule || pm2 start ecosystem.config.js
|