|
| 1 | +# yamllint disable rule:line-length |
| 2 | + |
| 3 | +name: Static Code Analysis |
| 4 | + |
| 5 | +on: |
| 6 | + - pull_request |
| 7 | + - push |
| 8 | + |
| 9 | +jobs: |
| 10 | + tests: |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + operating-system: |
| 14 | + - ubuntu-latest |
| 15 | + php-version: |
| 16 | + - 7.4 |
| 17 | + |
| 18 | + name: Static Code Analysis |
| 19 | + |
| 20 | + runs-on: ${{ matrix.operating-system }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v2 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Setup PHP |
| 29 | + uses: shivammathur/setup-php@v2 |
| 30 | + with: |
| 31 | + php-version: ${{ matrix.php-version }} |
| 32 | + |
| 33 | + - name: Get Composer cache directory |
| 34 | + id: composer-cache |
| 35 | + run: echo "::set-output name=dir::$(composer config cache-dir)" |
| 36 | + |
| 37 | + - name: Cache dependencies |
| 38 | + uses: actions/cache@v2 |
| 39 | + with: |
| 40 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 41 | + key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }} |
| 42 | + restore-keys: | |
| 43 | + composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}- |
| 44 | + composer-${{ runner.os }}-${{ matrix.php-version }}- |
| 45 | + composer-${{ runner.os }}- |
| 46 | + composer- |
| 47 | +
|
| 48 | + - name: Install dependencies |
| 49 | + uses: nick-invision/retry@v2 |
| 50 | + with: |
| 51 | + timeout_minutes: 5 |
| 52 | + max_attempts: 5 |
| 53 | + retry_wait_seconds: 30 |
| 54 | + command: | |
| 55 | + composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }} |
| 56 | +
|
| 57 | + - name: Report versions |
| 58 | + run: | |
| 59 | + composer info -D |
| 60 | +
|
| 61 | + - name: Install dev-tools |
| 62 | + uses: nick-invision/retry@v2 |
| 63 | + with: |
| 64 | + timeout_minutes: 5 |
| 65 | + max_attempts: 5 |
| 66 | + retry_wait_seconds: 30 |
| 67 | + command: | |
| 68 | + ./dev-tools/install.sh |
| 69 | +
|
| 70 | + - name: Run checks |
| 71 | + run: | |
| 72 | + ./dev-tools/check_file_permissions.sh |
| 73 | + ./dev-tools/check_trailing_spaces.sh |
| 74 | + ./dev-tools/vendor/bin/phpstan analyse |
| 75 | + ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json) |
| 76 | + composer normalize --dry-run --working-dir=./dev-tools ../composer.json |
| 77 | + ./dev-tools/check_shell_scripts.sh |
| 78 | +
|
| 79 | + - name: Find changed files (for pull request) |
| 80 | + if: ${{ github.event_name == 'pull_request' }} |
| 81 | + run: | |
| 82 | + git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true |
| 83 | + echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV |
| 84 | + git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true >> $GITHUB_ENV |
| 85 | + echo 'EOF' >> $GITHUB_ENV |
| 86 | +
|
| 87 | + - name: Find changed files (for push) |
| 88 | + if: ${{ github.event_name != 'pull_request' }} |
| 89 | + run: | |
| 90 | + git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true |
| 91 | + echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV |
| 92 | + git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true >> $GITHUB_ENV |
| 93 | + echo 'EOF' >> $GITHUB_ENV |
| 94 | +
|
| 95 | + - name: Validate changed files |
| 96 | + if: ${{ github.env.CHANGED_PHP_FILES }} |
| 97 | + run: | |
| 98 | + ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml |
| 99 | +
|
| 100 | + - name: Check for unknown files (to be removed in 3.0) |
| 101 | + run: | |
| 102 | + # @TODO remove at 3.0 |
| 103 | + git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php | |
| 104 | + grep -v tests/Test/AbstractFixerTestCase.php | |
| 105 | + grep -v tests/Test/AbstractIntegrationCaseFactory.php | |
| 106 | + grep -v tests/Test/AbstractIntegrationTestCase.php | |
| 107 | + grep -v tests/Test/Assert/AssertTokensTrait.php | |
| 108 | + grep -v tests/Test/IntegrationCase.php | |
| 109 | + grep -v tests/Test/IntegrationCaseFactory.php | |
| 110 | + grep -v tests/Test/IntegrationCaseFactoryInterface.php | |
| 111 | + grep -v tests/Test/InternalIntegrationCaseFactory.php | |
| 112 | + grep -v tests/Test/IsIdenticalConstraint.php | |
| 113 | + grep -v tests/TestCase.php \ |
| 114 | + && (echo "UNKNOWN FILES DETECTED" && exit 1) || echo "NO UNKNOWN FILES" |
0 commit comments