sca.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. name: Static Code Analysis
  2. on:
  3. - pull_request
  4. - push
  5. jobs:
  6. tests:
  7. strategy:
  8. matrix:
  9. operating-system:
  10. - ubuntu-20.04
  11. php-version:
  12. - 7.4
  13. name: Static Code Analysis
  14. runs-on: ${{ matrix.operating-system }}
  15. steps:
  16. - name: Checkout code
  17. uses: actions/checkout@v2
  18. with:
  19. fetch-depth: 0
  20. - name: Setup PHP
  21. uses: shivammathur/setup-php@v2
  22. with:
  23. php-version: ${{ matrix.php-version }}
  24. - name: Get Composer cache directory
  25. id: composer-cache
  26. run: echo "::set-output name=dir::$(composer config cache-dir)"
  27. - name: Cache dependencies
  28. uses: actions/cache@v2
  29. with:
  30. path: ${{ steps.composer-cache.outputs.dir }}
  31. key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
  32. restore-keys: |
  33. composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
  34. composer-${{ runner.os }}-${{ matrix.php-version }}-
  35. composer-${{ runner.os }}-
  36. composer-
  37. - name: Install dependencies
  38. uses: nick-invision/retry@v2
  39. with:
  40. timeout_minutes: 5
  41. max_attempts: 5
  42. retry_wait_seconds: 30
  43. command: composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
  44. - name: Report versions
  45. run: composer info -D
  46. - name: Install dev-tools
  47. uses: nick-invision/retry@v2
  48. with:
  49. timeout_minutes: 5
  50. max_attempts: 5
  51. retry_wait_seconds: 30
  52. command: ./dev-tools/install.sh
  53. - name: Check - file permissions
  54. run: ./dev-tools/check_file_permissions.sh
  55. - name: Check - trailing spaces
  56. run: ./dev-tools/check_trailing_spaces.sh
  57. - name: Check - phpstan
  58. run: ./dev-tools/vendor/bin/phpstan analyse
  59. - name: Check - composer-require-checker
  60. run: ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file .composer-require-checker.json
  61. - name: Check - composer normalize
  62. run: composer normalize --dry-run --working-dir=./dev-tools ../composer.json
  63. - name: Check - shell scripts
  64. run: ./dev-tools/check_shell_scripts.sh
  65. - name: Find changed files (for pull request)
  66. if: ${{ github.event_name == 'pull_request' }}
  67. run: |
  68. git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true
  69. echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
  70. git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true >> $GITHUB_ENV
  71. echo 'EOF' >> $GITHUB_ENV
  72. - name: Find changed files (for push)
  73. if: ${{ github.event_name != 'pull_request' }}
  74. run: |
  75. git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true
  76. echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
  77. git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true >> $GITHUB_ENV
  78. echo 'EOF' >> $GITHUB_ENV
  79. - name: Check - phpmd
  80. if: ${{ github.env.CHANGED_PHP_FILES }}
  81. run: ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml
  82. - name: Check - ensure test files are not present in the archive
  83. run: |
  84. git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php \
  85. && (echo "Test files detected in archive" && exit 1) || echo "No test files detected in archive"