Workflows #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Cache Composer dependencies | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/composer-cache | |
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.3' | |
extensions: zip pcntl mysqli pdo_mysql bcmath soap intl gd exif imagick redis | |
coverage: xdebug | |
- name: Run composer install | |
run: composer install -n --prefer-dist | |
- name: Prepare Laravel Application | |
run: | | |
php artisan key:generate | |
php artisan typescript:transform | |
- name: Upload application | |
uses: actions/upload-artifact@v4 | |
with: | |
name: app_files | |
path: . | |
run-tests: | |
runs-on: ubuntu-latest | |
needs: setup | |
services: | |
mysql: | |
image: mysql:8.4 | |
env: | |
MYSQL_DATABASE: hms | |
MYSQL_ROOT_PASSWORD: root | |
ports: | |
- 3306:3306 | |
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
strategy: | |
fail-fast: false | |
steps: | |
- name: Download application | |
uses: actions/download-artifact@v4 | |
with: | |
name: app_files | |
- name: Execute tests | |
uses: php-actions/composer@v6 | |
env: | |
DB_PORT: 3306 | |
DB_CONNECTION: mysql | |
DB_HOST: 127.0.0.1 | |
DB_DATABASE: hms | |
DB_USERNAME: root | |
DB_PASSWORD: root | |
XDEBUG_MODE: coverage | |
APP_KEY: ${{ secrets.TESTING_APP_KEY }} | |
with: | |
php_version: "8.3" | |
command: test | |
php_extensions: zip pcntl mysqli pdo_mysql bcmath soap intl gd exif imagick redis xdebug | |
- name: Upload application | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage | |
path: coverage/all/cobertura.xml | |
check-coverage: | |
runs-on: ubuntu-latest | |
needs: run-tests | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref || github.ref_name }} | |
fetch-depth: 0 | |
- run: git fetch | |
- name: Download coverage | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
cache: 'pip' # caching pip dependencies | |
- run: pip install diff_cover | |
- run: diff-cover cobertura.xml --markdown-report coverage.md --fail-under 80 --compare-branch origin/main | |
- name: Upload report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage_report | |
path: coverage.md | |
comment-coverage: | |
runs-on: ubuntu-latest | |
needs: check-coverage | |
if: ${{ github.event.pull_request.number }} | |
steps: | |
- name: Download report | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage_report | |
- name: Find Comment | |
uses: peter-evans/find-comment@v3 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: Diff Coverage | |
- name: Create or update comment | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body-path: coverage.md | |
edit-mode: replace | |
cleanup-artifacts-pr: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.number != null | |
needs: [setup, run-tests, check-coverage, comment-coverage] | |
steps: | |
- uses: geekyeggo/delete-artifact@v5 | |
with: | |
name: | | |
app_files | |
coverage | |
coverage_report | |
cleanup-artifacts-branch: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.number == null | |
needs: [setup, run-tests, check-coverage] | |
steps: | |
- uses: geekyeggo/delete-artifact@v5 | |
with: | |
name: | | |
app_files | |
coverage | |
coverage_report | |