Login via discord #76
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: | |
build-app: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:8.0 | |
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 | |
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 8.4 | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.4' | |
extensions: zip, pcntl, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, imagick, redis, xdebug | |
coverage: xdebug | |
- name: Run composer install | |
run: composer install -n --prefer-dist | |
- name: Prepare Laravel Application | |
run: | | |
php artisan migrate --env=ci | |
php artisan key:generate --env=ci | |
php artisan typescript:transform --env=ci | |
php artisan ziggy:generate --env=ci | |
- name: Use Node.js 22 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: 'npm' | |
- run: npm ci | |
- run: npm run build --if-present | |
- name: Tar files | |
run: tar -cvf app.tar . | |
- name: Upload application | |
uses: actions/upload-artifact@v4 | |
with: | |
include-hidden-files: true | |
name: app | |
path: app.tar | |
run-tests: | |
needs: build-app | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:8.0 | |
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 | |
steps: | |
- name: Download app | |
uses: actions/download-artifact@v4 | |
with: | |
name: app | |
- name: Untar files | |
run: tar -xvf app.tar | |
- name: Setup PHP 8.4 | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.4' | |
extensions: zip, pcntl, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, imagick, redis, xdebug | |
coverage: xdebug | |
- name: Execute tests | |
id: tests | |
continue-on-error: true | |
run: | | |
php artisan test --env=ci --parallel --coverage-cobertura=coverage/all/cobertura.xml | |
- name: Upload coverage | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage | |
path: coverage/all/cobertura.xml | |
- name: Tests failed | |
if: steps.tests.outcome != 'success' | |
run: exit 1 | |
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 | |
- name: Run diff-cover | |
id: diff-cover | |
continue-on-error: true | |
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 | |
- name: 80% coverage check failed | |
if: steps.diff-cover.outcome != 'success' | |
run: exit 1 | |
comment-coverage: | |
runs-on: ubuntu-latest | |
needs: check-coverage | |
if: always() && github.event.pull_request.number != null | |
permissions: | |
pull-requests: write | |
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 | |
eslint: | |
needs: build-app | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download app | |
uses: actions/download-artifact@v4 | |
with: | |
name: app | |
- name: Untar files | |
run: tar -xvf app.tar | |
- name: Use Node.js 22 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: 'npm' | |
- name: Eslint | |
run: npm run lint | |
php-lint: | |
needs: build-app | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download app | |
uses: actions/download-artifact@v4 | |
with: | |
name: app | |
- name: Untar files | |
run: tar -xvf app.tar | |
- name: Setup PHP 8.4 | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.4' | |
extensions: zip, pcntl, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, imagick, redis, xdebug | |
coverage: xdebug | |
- name: Run Pint | |
run: composer run lint | |
stan: | |
needs: build-app | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download app | |
uses: actions/download-artifact@v4 | |
with: | |
name: app | |
- name: Untar files | |
run: tar -xvf app.tar | |
- name: Setup PHP 8.4 | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.4' | |
extensions: zip, pcntl, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, imagick, redis, xdebug | |
coverage: xdebug | |
- name: Run Stan | |
run: composer run stan | |
cleanup-artifacts-pr: | |
runs-on: ubuntu-latest | |
if: always() && github.event.pull_request.number != null | |
needs: [ run-tests, check-coverage, comment-coverage, eslint, php-lint, stan ] | |
steps: | |
- uses: geekyeggo/delete-artifact@v5 | |
with: | |
name: | | |
app | |
coverage | |
coverage_report | |
cleanup-artifacts-branch: | |
runs-on: ubuntu-latest | |
if: always() && github.event.pull_request.number == null | |
needs: [ run-tests, check-coverage, eslint, php-lint, stan ] | |
steps: | |
- uses: geekyeggo/delete-artifact@v5 | |
with: | |
name: | | |
app | |
coverage | |
coverage_report | |