Add composer validate and normalize checks #43
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: Static Code Analysis | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
pull_request: | |
push: | |
branches: | |
- 1.x | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
jobs: | |
tests: | |
strategy: | |
fail-fast: false | |
matrix: | |
php-version: | |
- 8.2 | |
- 8.3 | |
name: Static Code Analysis | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-version }} | |
coverage: none | |
- name: Get composer cache directory | |
id: cache-dir | |
run: | | |
echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_OUTPUT | |
- name: Get packages' directories | |
id: components | |
run: | | |
echo COMPONENTS=$(find src/Nexus -mindepth 2 -type f -name composer.json | cut -d '/' -f 1-3 | sort -fh) >> $GITHUB_OUTPUT | |
- name: Cache Composer dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.cache-dir.outputs.COMPOSER_CACHE_DIR }} | |
key: ${{ github.workflow }}-PHP_${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }} | |
restore-keys: | | |
${{ github.workflow }}-PHP_${{ matrix.php-version }}- | |
- name: Install dependencies | |
run: | | |
composer update --ansi | |
composer global require ergebnis/composer-normalize | |
- name: Check - Composer validate | |
run: | | |
COMPONENTS=("${{ steps.components.outputs.COMPONENTS }}") | |
COMPONENTS+=('.') | |
validate() { | |
local exit=0 | |
OUTPUT=$(bash -xc "composer validate --strict --ansi --working-dir $1 2>&1") || exit=$? | |
printf "::group::$1" | |
echo $OUTPUT | |
printf "::endgroup::" | |
} | |
export -f validate | |
echo "$COMPONENTS" | xargs -n1 validate {} | |
- name: Check - Composer normalize | |
run: | | |
COMPONENTS=("${{ steps.components.outputs.COMPONENTS }}") | |
COMPONENTS+=('.') | |
normalize() { | |
local exit=0 | |
OUTPUT=$(bash -xc "composer normalize --dry-run --diff --ansi --working-dir $1 2>&1") || exit=$? | |
printf "::group::$1" | |
echo $OUTPUT | |
printf "::endgroup::" | |
exit $? | |
} | |
export -f normalize | |
echo "$COMPONENTS" | xargs -n1 normalize {} | |
- name: Check - file permissions | |
run: bin/check-file-permissions | |
- name: Check - PHP-CS-Fixer | |
run: composer cs:check | |
- name: Check - PHPStan | |
run: composer phpstan:check |