sca.yml 3.6 KB

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