ci: Add SonarCloud #31
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: Test | |
on: | |
push: | |
pull_request: | |
permissions: | |
contents: read | |
jobs: | |
tests: | |
name: Unit Tests on PHP ${{ matrix.php-versions }} with ${{ matrix.deps }} dependencies | |
strategy: | |
matrix: | |
php-versions: | |
- '8.2' | |
- '8.3' | |
deps: | |
- 'highest' | |
- 'lowest' | |
env: | |
extensions: pdo_mysql | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Setup cache Environment | |
id: extcache | |
uses: shivammathur/cache-extensions@v1 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
extensions: ${{ env.extensions }} | |
key: ext-cache-v1 | |
- name: Cache extensions | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.extcache.outputs.dir }} | |
key: ${{ steps.extcache.outputs.key }} | |
restore-keys: ${{ steps.extcache.outputs.key }} | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
extensions: ${{ env.extensions }} | |
coverage: pcov | |
tools: phive | |
env: | |
fail-fast: true | |
- name: Get composer cache directory | |
id: composer-cache | |
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.json') }} | |
restore-keys: ${{ runner.os }}-${{ matrix.deps }}-composer- | |
- name: Install dependencies | |
run: | | |
if [[ "${{ matrix.deps }}" == "lowest" ]]; then | |
composer update --prefer-lowest --no-progress --ansi --prefer-dist | |
else | |
composer update --prefer-stable --no-progress --ansi --prefer-dist | |
fi | |
- name: Install phive tools | |
run: phive install --copy --trust-gpg-keys E82B2FB314E9906E,51C67305FFC2E5C0,12CE0F1D262429A5 | |
- name: Install composer dependencies | |
run: |- | |
for dir in $(find src -type d); do | |
if [ -f "$dir/composer.json" ]; then | |
if [[ "${{ matrix.deps }}" == "lowest" ]]; then | |
composer update --working-dir=$dir --prefer-lowest --no-progress --ansi --prefer-dist || true | |
else | |
composer update --working-dir=$dir --prefer-stable --no-progress --ansi --prefer-dist || true | |
fi | |
fi | |
done | |
- name: Run PHPStan/Psalm/PHP-CS-Fixer | |
run: composer lint | |
- name: Run Coverage | |
run: composer coverage-xml | |
- name: SonarCloud Scan | |
uses: SonarSource/sonarcloud-github-action@master | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |