|
| 1 | +name: Format (PHP) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '**.php' |
| 7 | + - 'composer.*' |
| 8 | + - 'phpcs.xml' |
| 9 | + |
| 10 | +jobs: |
| 11 | + format_php: |
| 12 | + name: Format PHP |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 7 |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + ref: ${{ github.head_ref }} |
| 19 | + |
| 20 | + # mtime needs to be restored for PHP-CS-Fixer cache to work correctly |
| 21 | + - name: Restore mtimes |
| 22 | + uses: weirdan/git-restore-mtime-action@master |
| 23 | + |
| 24 | + - name: Setup PHP |
| 25 | + uses: shivammathur/setup-php@v2 |
| 26 | + with: |
| 27 | + php-version: 8.2 |
| 28 | + coverage: none |
| 29 | + tools: cs2pr |
| 30 | + env: |
| 31 | + COMPOSER_TOKEN: ${{ secrets.GH_TOKEN_FOR_COMPOSER_FOR_PRIVATE_REPOS }} |
| 32 | + |
| 33 | + - name: Get Composer cache directory |
| 34 | + id: composer-cache |
| 35 | + run: | |
| 36 | + echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 37 | +
|
| 38 | + - name: Retrieve Composer‘s cache |
| 39 | + uses: actions/cache@v3 |
| 40 | + with: |
| 41 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 42 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-composer- |
| 45 | +
|
| 46 | + - name: Install composer dependencies -- step 1 |
| 47 | + run: 'composer install --working-dir=tools/php-cs-fixer --no-interaction --no-progress --no-scripts' |
| 48 | + |
| 49 | + - name: Install composer dependencies -- step 2 |
| 50 | + run: 'composer install --working-dir=tools/phpcs --no-interaction --no-progress --no-scripts' |
| 51 | + |
| 52 | + - name: Retrieve PHP-CS-Fixer‘s cache |
| 53 | + uses: actions/cache@v3 |
| 54 | + with: |
| 55 | + path: .php-cs-fixer.cache |
| 56 | + key: ${{ runner.os }}-php-cs-fixer-${{ hashFiles('.php-cs-fixer.php', '.phpcs/**/**') }} |
| 57 | + restore-keys: | |
| 58 | + ${{ runner.os }}-php-cs-fixer- |
| 59 | +
|
| 60 | + - name: Retrieve PHPCS‘s cache |
| 61 | + uses: actions/cache@v3 |
| 62 | + with: |
| 63 | + path: .phpcs.cache |
| 64 | + key: ${{ runner.os }}-phpcs-${{ hashFiles('phpcs.xml') }} |
| 65 | + restore-keys: | |
| 66 | + ${{ runner.os }}-phpcs- |
| 67 | +
|
| 68 | + - name: Detect PHP coding style issues |
| 69 | + id: lint_php |
| 70 | + run: composer php:lint |
| 71 | + continue-on-error: true |
| 72 | + |
| 73 | + - name: Fix detected PHP coding style issues (if any) |
| 74 | + if: ${{ steps.lint_php.outcome == 'failure' }} |
| 75 | + id: fix_php |
| 76 | + run: composer php:fix |
| 77 | + continue-on-error: true |
| 78 | + |
| 79 | + - name: Commit PHP code-style fixes (if any) |
| 80 | + if: ${{ steps.lint_php.outcome == 'failure' }} |
| 81 | + uses: EndBug/add-and-commit@v9 |
| 82 | + with: |
| 83 | + message: '#15000 🪄️ Apply coding style fixes to PHP' |
| 84 | + committer_name: GitHub Actions |
| 85 | + committer_email: [email protected] |
| 86 | + add: '*.php' |
| 87 | + pull: '--rebase --autostash' |
| 88 | + |
| 89 | + - name: Lint PHP coding style issues (if previously detected) |
| 90 | + if: ${{ steps.lint_php.outcome == 'failure' }} |
| 91 | + run: composer phpcs -- --report-full --report-checkstyle=./phpcs-report.xml |
| 92 | + |
| 93 | + - name: Show PHPCS results in on GitHub UI |
| 94 | + if: ${{ steps.lint_php.outcome == 'failure' }} |
| 95 | + run: cs2pr ./phpcs-report.xml |
0 commit comments