Continuous Integration with GitHub Actions and Laravel 6

Roberto B
Roberto B
Sep 7 · 7 min read

Setup your first workflow with GitHub Action

Actions tab in your GitHub repository
Set up a workflow from scratch
the new YAML file auto-generated

Configure the YML workflow file for Laravel

Yaml workflow file
The gists with the YML configuration file

Define events

name: Continuous Integration Laravel 6
on:
push:
branches:
- master
- features/*
The Workflow in the GitHub Actions UI

The jobs

jobs:
laravel-tests:
runs-on: ubuntu-latest

The steps

name: Continuous Integration Laravel 6
on:
push:
branches:
- master
- features/*
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Copy ENV Laravel Configuration for CI
run: php -r "file_exists('.env') || copy('.env.ci', '.env');"
- name: Install Dependencies (PHP vendors)
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Create DB and schemas
run: |
mkdir -p database
touch database/database.sqlite
php artisan migrate
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit

First step: git checkout

- uses: actions/checkout@v1

Second Step: copy the right .env file

DB_CONNECTION=sqlite
DB_DATABASE=database/database.sqlite
# DB_CONNECTION=mysql
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=root
# DB_PASSWORD=
    - name: Copy ENV Laravel Configuration for CI
run: php -r "file_exists('.env') || copy('.env.ci', '.env');"

Third step: install dependencies

    - name: Install Dependencies (PHP vendors)
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

Fourth step: setup your Laravel key

    - name: Generate key
run: php artisan key:generate

Fifth step: create your database

    - name: Create DB and schemas
run: |
mkdir -p database
touch database/database.sqlite
php artisan migrate

Last step: execute the tests

    - name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit

Is that all?

The GitHub Actions UI with the execution of the workflow.

Roberto B

Written by

Roberto B

I’m technophile. Vuejs and Laravel enthusiast! #vuejs #laravel. I love #coding

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade