EscolaLMS/API

View on GitHub
.github/workflows/phpunit-cc.yml

Summary

Maintainability
Test Coverage
name: Tests Code Coverage

on:
  # Trigger the workflow on push or pull request,
  # but only for the main branch
  push:
    branches:
      - develop

jobs:
  phpunit-code-coverage:
#    runs-on: self-hosted
    runs-on: ubuntu-latest
    container:
      image: escolalms/php:8.2-work

    services:
      mysql:
        image: mariadb:10.5
        env:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: test
        ports:
          - 33306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

    steps:
      - name: Instantiate package
        run: apt-get install git -y

      - name: Instantiate package
        uses: actions/checkout@v2

      - name: Copy environment configuration files
        run: |
          cp docker/envs/.env.ci.mysql .env
          cp docker/envs/.env.ci.mysql .env.testing
          cp docker/envs/phpunit.xml.cc phpunit.xml

      - name: Update composer
        run: |
          apt-get install unzip -y
          composer self-update
          composer update

      - name: Prepare Laravel Application
        run: |
          php artisan key:generate
          php artisan migrate:fresh
          php artisan db:seed --class="Database\Seeders\PermissionsSeeder"
          php artisan passport:keys --force
          php artisan passport:client --personal --no-interaction
          cp storage/oauth-private.key vendor/orchestra/testbench-core/laravel/storage/oauth-private.key
          cp storage/oauth-public.key vendor/orchestra/testbench-core/laravel/storage/oauth-public.key
          mkdir vendor/escolalms/lrs/src/../../storage/
          cp storage/*.key vendor/escolalms/lrs/src/../../storage/

      - name: Special Migrations for Tests
        run: php artisan migrate --path=vendor/escolalms/courses/tests/Database/Migrations

      - name: Remove special app exception handler
        run:
          rm -f vendor/escolalms/lrs/tests/Exceptions/Handler.php
          rm -f vendor/escolalms/cmi5/tests/Exceptions/Handler.php

      - name: Add pcov
        run: pecl install pcov && docker-php-ext-enable pcov

      - name: Run tests
        run: XDEBUG_MODE=off php -dpcov.enabled=1 -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover coverage.xml --coverage-text | tee coverage.txt

      - name: Generate Badge
        run: php tests/badge.php

      - uses: actions/upload-artifact@v4
        with:
          name: cc-badge.svg
          path: |
            tests/cc-badge.svg
            tests/cc-tests.svg
            coverage.xml

      # - uses: EndBug/add-and-commit@v7 # You can change this to use a specific version.
      #   with:
      #     add: "tests/*.svg"

      - name: Deploy to external repository
        uses: cpina/github-action-push-to-another-repository@main
        env:
          SSH_DEPLOY_KEY: ${{ secrets.STATS_KEY }}

        with:
          # GitHub Action output files
          source-directory: tests/
          target-directory: api-tests
          destination-github-username: EscolaLMS
          destination-repository-name: .github
          user-email: mateusz@qunabu.com
          # It defaults to `main`
          target-branch: "main"

      - name: Test get variable exported by push-to-another-repository
        run: echo $DESTINATION_CLONED_DIRECTORY