From d834148553f77f32f9f0e8263bbe30aedc5d488c Mon Sep 17 00:00:00 2001 From: Jordy Schreuders <3071062+99linesofcode@users.noreply.github.com> Date: Wed, 6 Jul 2022 14:28:34 -0500 Subject: [PATCH] feat: callable github action for testing laravel applications with phpunit --- .github/workflows/.gitkeep | 0 .github/workflows/dependabot.yml | 17 +++++++ .github/workflows/laravel-test.yml | 81 ++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 .github/workflows/.gitkeep create mode 100644 .github/workflows/dependabot.yml create mode 100644 .github/workflows/laravel-test.yml diff --git a/.github/workflows/.gitkeep b/.github/workflows/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..6b84181 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -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 diff --git a/.github/workflows/laravel-test.yml b/.github/workflows/laravel-test.yml new file mode 100644 index 0000000..b038eb4 --- /dev/null +++ b/.github/workflows/laravel-test.yml @@ -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'] }}