Skip to content

Added mysql to ci/cd #4

Added mysql to ci/cd

Added mysql to ci/cd #4

Workflow file for this run

name: Quality Checks
on:
push:
branches:
- main
- develop
- feature/*
pull_request:
branches:
- main
- develop
- feature/*
env:
PHP_VERSION: "8.3"
jobs:
setup:
name: Setup Environment
runs-on: ubuntu-latest
outputs:
composer-cache-dir: ${{ env.COMPOSER_CACHE_DIR }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install PHP v${{ env.PHP_VERSION }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
tools: composer:v2
- name: Validate Composer Files
run: composer validate --strict
- name: Get Composer Cache Directory
id: get-composer-cache
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
- name: Cache Composer Dependencies
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ env.PHP_VERSION }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ env.PHP_VERSION }}-composer-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
test-and-lint:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
task: [test, lint]
services:
mysql:
image: mysql:8.3
env:
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.DB_DATABASE }}
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
ports:
- 3306:3306
# Give MySQL time to be ready
options: >-
--health-cmd="mysqladmin ping --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install PHP v${{ env.PHP_VERSION }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}
tools: composer:v2
- name: Validate Composer Files
run: composer validate --strict
- name: Get Composer Cache Directory
id: get-composer-cache
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
- name: Cache Composer Dependencies
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php-${{ env.PHP_VERSION }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ env.PHP_VERSION }}-composer-
- name: Prepare Application
run: cp .env.ci .env
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Setup Database
if: matrix.task == 'test'
run: |
vendor/bin/phinx migrate
vendor/bin/phinx seed:run
- name: Serve application
if: matrix.task == 'test'
run: php -S 127.0.0.1:80
- name: Run Tests
if: matrix.task == 'test'
run: vendor/bin/phpunit
- name: Run Linter
if: matrix.task == 'lint'
run: vendor/bin/php-cs-fixer