Skip to content

Commit

Permalink
test sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
rigonlucas committed Oct 2, 2024
1 parent b88a653 commit 4373a07
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
70 changes: 59 additions & 11 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,79 @@ on:
branches: [ "master" ]

jobs:
laravel-tests:

test:
runs-on: ubuntu-latest
needs: build

steps:
- uses: shivammathur/setup-php@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- uses: actions/checkout@v4
- name: Disable PHP Error Reporting (notices/warnings)
run: echo 'error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE)' >> php.ini
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
coverage: xdebug

- name: Checkout code
uses: actions/checkout@v4

- name: Cache Composer packages
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"

- name: Generate key
run: php artisan key:generate
- name: Directory Permissions

- name: Set Directory Permissions
run: chmod -R 777 storage bootstrap/cache

- name: Create Database
run: |
mkdir -p database
touch database/database.sqlite
- name: Execute tests (Unit and Feature tests) via PHPUnit/Pest
- name: Run tests with phpunit/phpunit
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: php artisan test --parallel --processes=1
run: vendor/bin/phpunit --coverage-clover=coverage.xml

- name: Store coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml

sonar:
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=${{ secrets.SONAR_PROJECTKEY }}
-Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }}
-Dsonar.php.coverage.reportPaths=coverage.xml
14 changes: 10 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
</testsuite>
</testsuites>
<source>
<include>
<directory>app</directory>
</include>
<!-- <include>-->
<!-- <directory>app/Modules</directory>-->
<!-- <directory>app/Infra</directory>-->
<!-- <directory>app/Jobs</directory>-->
<!-- <directory>app/Http/Controllers</directory>-->
<!-- </include>-->
<exclude>
<directory>tests</directory>
</exclude>
</source>
<php>
<env name="APP_ENV" value="testing"/>
Expand All @@ -33,4 +39,4 @@
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
</phpunit>

0 comments on commit 4373a07

Please sign in to comment.