GitHub Laravel 的操作迁移和播种问题
GitHub Actions migration and seeding issue with Laravel
我正在尝试使用 GitHub 操作实现 CI/CD 结构,以在我的 Laravel 文件夹上自动 运行 测试。要成功执行我的测试,必须有一个功能性 MySQL 数据库,该数据库必须被播种。
到目前为止,播种没有成功。我收到以下错误:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')
这是我的 laravel.yml:
name: Laravel CI
on:
push:
branches: [ test ]
jobs:
laravel-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./laravel
services:
mysql:
image: mysql:latest
ports:
- 3306
env:
MYSQL_USER: laravel_user
MYSQL_PASSWORD: laravel_pass
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: testingdatabase
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.0'
extensions: mysql
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install dependencies
run: composer update --no-interaction --no-progress --prefer-dist --optimize-autoloader --ignore-platform-reqs
- name: Generate key
run: php artisan key:generate
- name: Configuration caching for speed
run: php artisan config:cache
- name: Route caching for speed
run: php artisan route:cache
- name: Installing npm dependencies
run: npm install
- name: Running npm prod
run: npm run prod
- name: Migrate & seed database
run: php artisan migrate --seed
- name: Setting up file storage
run: php artisan storage:link
- name: Serve application
run: php artisan serve &
- name: Run Feature tests
run: vender/bin/phpunit
如何才能成功 运行 我的迁移和播种?
问题是我只在 mysql 服务中声明了环境变量,而我也应该在尝试迁移和播种我的数据库时声明它们:
on:
push:
paths:
- './laravel'
name: Laravel CI
jobs:
phpunit:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./laravel
services:
mysql:
image: mysql:5.7
env:
MYSQL_USER: user
MYSQL_PASSWORD: secret
MYSQL_DATABASE: testdatabase
MYSQL_ROOT_PASSWORD: root
DB_PORT: ${{ job.services.mysql.ports[3306] }}
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Verify MySQL connection
run: |
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uuser -psecret -e "SHOW DATABASES"
- name: Install dependencies
run: |
php --version
composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
chmod -R 777 storage bootstrap/cache
- name: Boot Laravel application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
php artisan --version
- name: Execute PHPUnit tests
env:
DB_CONNECTION: mysql
DB_DATABASE: testdatabase
DB_PORT: 33306
DB_USER: root
DB_PASSWORD: secret
run: |
php artisan migrate:fresh --seed
./vendor/bin/phpunit
我正在尝试使用 GitHub 操作实现 CI/CD 结构,以在我的 Laravel 文件夹上自动 运行 测试。要成功执行我的测试,必须有一个功能性 MySQL 数据库,该数据库必须被播种。
到目前为止,播种没有成功。我收到以下错误:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')
这是我的 laravel.yml:
name: Laravel CI
on:
push:
branches: [ test ]
jobs:
laravel-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./laravel
services:
mysql:
image: mysql:latest
ports:
- 3306
env:
MYSQL_USER: laravel_user
MYSQL_PASSWORD: laravel_pass
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: testingdatabase
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.0'
extensions: mysql
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install dependencies
run: composer update --no-interaction --no-progress --prefer-dist --optimize-autoloader --ignore-platform-reqs
- name: Generate key
run: php artisan key:generate
- name: Configuration caching for speed
run: php artisan config:cache
- name: Route caching for speed
run: php artisan route:cache
- name: Installing npm dependencies
run: npm install
- name: Running npm prod
run: npm run prod
- name: Migrate & seed database
run: php artisan migrate --seed
- name: Setting up file storage
run: php artisan storage:link
- name: Serve application
run: php artisan serve &
- name: Run Feature tests
run: vender/bin/phpunit
如何才能成功 运行 我的迁移和播种?
问题是我只在 mysql 服务中声明了环境变量,而我也应该在尝试迁移和播种我的数据库时声明它们:
on:
push:
paths:
- './laravel'
name: Laravel CI
jobs:
phpunit:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./laravel
services:
mysql:
image: mysql:5.7
env:
MYSQL_USER: user
MYSQL_PASSWORD: secret
MYSQL_DATABASE: testdatabase
MYSQL_ROOT_PASSWORD: root
DB_PORT: ${{ job.services.mysql.ports[3306] }}
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Verify MySQL connection
run: |
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uuser -psecret -e "SHOW DATABASES"
- name: Install dependencies
run: |
php --version
composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
chmod -R 777 storage bootstrap/cache
- name: Boot Laravel application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan key:generate
php artisan --version
- name: Execute PHPUnit tests
env:
DB_CONNECTION: mysql
DB_DATABASE: testdatabase
DB_PORT: 33306
DB_USER: root
DB_PASSWORD: secret
run: |
php artisan migrate:fresh --seed
./vendor/bin/phpunit