0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【GitHub Actions】LaravelのCI環境構築

Last updated at Posted at 2020-08-29

実現したいこと

GitHub Actionsを用いて、LaravelのCI環境構築をします。

前提

開発環境でPHPUnitのvendor/bin/phpunitコマンドを実行したら問題なくテストが正常に動作するのが前提です。

ワークフローの作成

.github/workflows/ci.yml
name: CI

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  php-nuit:
    runs-on: ubuntu-latest

    services:
      mysql:
        image: mysql:8.0.19
        ports:
          - 3306:3306
        options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10
        env:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: testdatabase

    env:
      DB_CONNECTION: mysql
      DB_HOST: 127.0.0.1
      DB_PORT: 3306
      DB_DATABASE: testdatabase
      DB_USERNAME: root
      DB_PASSWORD: password

    steps:
      - uses: actions/checkout@v2
      - name: Copy .env
        run: cp .env.ci .env
        working-directory: ./server
      - name: composer install
        run: |
          composer install --no-scripts
        working-directory: ./server
      - name: Generate key
        run: php artisan key:generate
        working-directory: ./server
      - name: Directory Permissions
        run: chmod -R 777 storage bootstrap/cache
        working-directory: ./server
      - name: migrate
        run: php artisan migrate
        working-directory: ./server
      - name: php-unit test
        run: ./vendor/bin/phpunit
        working-directory: ./server

今回のテストでは、データベースも絡んでいるため、MySQLを使用しました。また、私のLaravelのディレクトリ構造は下記の添付画像のようになっていたため、コマンドによってはディレクトリを指定するworking-directory: ./serverを記述しています。

スクリーンショット 2020-08-30 6.29.39.png

■参考
https://github.com/yuuta1988/shussekikun/blob/master/.github/workflows/ci.yml

.env.ciの作成

ワークフローで.env.ciを元に.envファイルを複製するので、.env.ciを作成します。

server/.env.ci
APP_NAME=Laravel
APP_ENV=testing
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdatabase
DB_USERNAME=root
DB_PASSWORD=password

■参考
https://github.com/yuuta1988/shussekikun/blob/master/server/.env.ci

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?