This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
test for github code coverage #1
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: PHPUnit Test | |
on: | |
workflow_call: | |
push: | |
pull_request: | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
phpunit_test: | |
name: PHPUnit Test | |
runs-on: biggy-tide | |
container: | |
image: ghcr.io/dpc-sdp/bay/ci-builder:5.x | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Log into registry ghcr.io | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Copy repo | |
run: | | |
cp -R /__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/} /app | |
- name: Install dependencies | |
run: | | |
cd /app | |
composer install --no-interaction --prefer-dist | |
- name: Run PHPUnit tests | |
run: | | |
cd /app | |
phpdbg -qrr vendor/bin/phpunit --coverage-html ./coverage-report | |
- name: Check coverage | |
run: | | |
cd /app | |
coverage=$(grep -Po '(?<=<td class="text-right">)[0-9.]+(?=%</td>)' ./coverage-report/index.html | head -n 1) | |
if (( $(echo "$coverage < 80" | bc -l) )); then | |
echo "Code coverage is below 80%: $coverage%" | |
exit 1 | |
fi | |
- name: Upload coverage report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: /app/coverage-report |