Skip to content

Commit

Permalink
feat: callable github action for testing laravel applications with ph…
Browse files Browse the repository at this point in the history
…punit
  • Loading branch information
99linesofcode committed Jul 6, 2022
1 parent 9437045 commit d834148
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Empty file added .github/workflows/.gitkeep
Empty file.
17 changes: 17 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2
updates:
# Fetch and update latest `github-actions` pkgs
- package-ecosystem: github-actions
directory: '/'
schedule:
interval: daily
time: '00:00'
open-pull-requests-limit: 10
reviewers:
- 99linesofcode
assignees:
- 99linesofcode
commit-message:
prefix: fix
prefix-development: chore
include: scope
81 changes: 81 additions & 0 deletions .github/workflows/laravel-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Laravel Tests

on:
workflow_call:

jobs:
tests:
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
defaults:
run:
working-directory: api
runs-on: ubuntu-latest
# Docs: https://docs.github.com/en/actions/using-containerized-services
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: maya
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

redis:
image: redis:latest
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix:
php: [8.0]
stability: [prefer-stable]

steps:
- name: Checkout
uses: actions/checkout@v3

# Docs: https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, dom, fileinfo, mysql
coverage: none

- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

- name: Prepare the application
run: |
php -r "copy('.env.testing', '.env');"
php artisan key:generate
- name: Clear config
run: php artisan config:clear

- name: Migrations
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}

- name: PHPUnit
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}

0 comments on commit d834148

Please sign in to comment.