Continuous Integration for your Laravel Application with GitHub Actions

Sep 20, 2019

Bitbucket has pipelines and GitLab CI/CD, but GitHub now has something similar with GitHub Actions.

Similar to our previous post (Continuous Integration for your Laravel Application with GitLab CI) we will walk through setting up GitHub Actions for a bare bones Laravel 6 project.

GitHub announced Actions in 2019 and all GitHub users can use 2,000 minutes for free.

Repository Setup

This setup portion is copied from the previous article, if you already have a laravel project setup please skip to the Enabling GitHub Actions portion of this article.

Installing Laravel

There are several different methods of installing Laravel 6, but I’m going to use composer to install a new project.

$ composer create-project --prefer-dist laravel/laravel laravel-ci-example

Once the repo has been created you can verify that the repo already has some sample tests setup.

$ cd laravel-ci-example
$ vendor/bin/phpunit

PHPUnit 8.3.5 by Sebastian Bergmann and contributors.

..                                                                  2 / 2 (100%)

Time: 347 ms, Memory: 22.00 MB

OK (2 tests, 2 assertions)

Adding a GitHub Project

To add a new project to GitHub, sign in and navigate to and follow the necessary steps. Our example project will be located at

Pushing to GitHub

After creating a new project you can follow these steps to push to your newly created GitHub project.

$ cd laravel-ci-example
$ git init
$ git remote add origin [email protected]:{user}/laravel-ci-example.git
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master

Enabling GitHub Actions

Enabling GitHub Actions require setting up your initial workflow:

  1. Visit the actions tab on your repository
  2. Click "Set up a workflow yourself"
  3. Create your first workflow

This workflow will run PHPUnit on our code just like the GitLab example. GitHub will start out your workflow with in the following file /.github/workflows/main.yml.

Since we want to run tests, I updated this to be test.yml with the following contents:

name: Tests

on: [push]

    name: Test Run
    runs-on: ubuntu-latest

    - uses: actions/[email protected]
    - uses: docker://php:latest
    - name: composer install
      run: |
        curl -sS | php
        php composer.phar install
    - name: env setup, test
      run: |
        cp .env.example .env
        php artisan key:generate
        php vendor/bin/phpunit

After editing, just hit the Start commit button and then you can commit this workflow file. To verify the workflow, choose create pull request and that new PR will run this workflow.

In our example case we created this PR and it ran this workflow.

Success! Our tests ran without issue. Now upon every new push a check will run and report the status for that commit.

This post does not do GitHub Actions full justice, it is much more powerful than running a simple test suite. I encourage you to checkout the starter workflows to dig deeper into the possibilities of GitHub Actions.

Thanks for reading.

If you are looking to make a change in your career consider checking out our job listings, subscribing to our newsletter, and following us on Twitter @__phpJobs__.