テストを実施した後にDeployerを使ってデプロイを実施する。
.github/workflows/main.yml
name: UnitTest
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
laravel-tests:
name: phpunit test
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0.19
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: "password"
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: "password"
options: --health-cmd "mysqladmin ping -h localhost" --health-interval 20s --health-timeout 10s --health-retries 10
env:
DB_CONNECTION: mysql
DB_HOST: db
DB_PORT: 3306
DB_DATABASE: test_db
DB_USERNAME: user
DB_PASSWORD: "password"
steps:
- uses: actions/checkout@v2
- name: Setup PHP 7.4
run: sudo update-alternatives --set php /usr/bin/php7.4
- name: cache vendor
id: cache
uses: actions/cache@v1
with:
path: ./vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: composer install
shell: bash -xe {0}
if: steps.cache.outputs.cache-hit != 'true'
run: composer install -n --prefer-dist
- name: composer dump autoload
shell: bash -xe {0}
run: composer dump-autoload
- name: generate key
shell: bash -xe {0}
run: php artisan key:generate --env=testing
- name: migrate
shell: bash -xe {0}
env:
DB_HOST: 127.0.0.1
run: php artisan migrate --force
- name: unit test
shell: bash -xe {0}
env:
DB_HOST: 127.0.0.1
run: ./vendor/bin/phpunit
deploy:
name: deploy
runs-on: ubuntu-latest
needs: laravel-tests
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v2
- name: Setup PHP 7.4
run: sudo update-alternatives --set php /usr/bin/php7.4
- name: cache vendor
id: cache
uses: actions/cache@v1
with:
path: ./vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: composer install
if: steps.cache.outputs.cache-hit != 'true'
run: composer install -n --prefer-dist
- name: setup ssh
run: |
mkdir -p /home/runner/.ssh
touch /home/runner/.ssh/id_rsa
echo "${{ secrets.SSH_DEPLOY_KEY }}" > /home/runner/.ssh/id_rsa
chmod 600 /home/runner/.ssh/id_rsa
- name: composer require deployer/deployer
run: composer require deployer/deployer --dev
- name: deploy
run: ./vendor/bin/dep deploy production -vvv