sca.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. name: Static Code Analysis
  2. on:
  3. - pull_request
  4. - push
  5. permissions:
  6. contents: read # to fetch code (actions/checkout)
  7. jobs:
  8. tests:
  9. strategy:
  10. fail-fast: false
  11. matrix:
  12. operating-system:
  13. - ubuntu-20.04
  14. php-version:
  15. - 8.1
  16. name: Static Code Analysis
  17. runs-on: ${{ matrix.operating-system }}
  18. steps:
  19. - name: Checkout code
  20. uses: actions/checkout@v3
  21. with:
  22. fetch-depth: 0
  23. - name: Setup PHP
  24. uses: shivammathur/setup-php@v2
  25. with:
  26. php-version: ${{ matrix.php-version }}
  27. coverage: none # without this Xdebug will be enabled
  28. tools: cs2pr
  29. - name: Get Composer cache directory
  30. id: composer-cache
  31. run: echo "dir=$(composer config cache-dir)" >> $GITHUB_OUTPUT
  32. - name: Cache dependencies
  33. uses: actions/cache@v3
  34. with:
  35. path: ${{ steps.composer-cache.outputs.dir }}
  36. key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
  37. restore-keys: |
  38. composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
  39. composer-${{ runner.os }}-${{ matrix.php-version }}-
  40. composer-${{ runner.os }}-
  41. composer-
  42. - name: Install dependencies
  43. uses: nick-invision/retry@v2
  44. with:
  45. timeout_minutes: 5
  46. max_attempts: 5
  47. retry_wait_seconds: 30
  48. command: composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
  49. - name: Report versions
  50. run: composer info -D
  51. ## We want to have a lock-file used on PR level, so contributors are not bothered by SCA complains unrelated to their changes,
  52. ## and same time we want to be aware that we are complying with bleeding edge of SCA tools as maintainers observing the push hook.
  53. - name: Unlock dev-tools
  54. if: ${{ github.event_name != 'pull_request' }}
  55. run: rm ./dev-tools/composer.lock
  56. - name: Install dev-tools
  57. uses: nick-invision/retry@v2
  58. with:
  59. timeout_minutes: 5
  60. max_attempts: 5
  61. retry_wait_seconds: 30
  62. command: ./dev-tools/install.sh
  63. - name: Check - file permissions
  64. run: ./dev-tools/check_file_permissions.sh
  65. - name: Check - trailing spaces
  66. run: ./dev-tools/check_trailing_spaces.sh
  67. - name: Check - phpstan
  68. run: ./dev-tools/vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr
  69. - name: Check - composer-require-checker
  70. run: ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file .composer-require-checker.json
  71. - name: Check - composer normalize
  72. run: |
  73. composer normalize --dry-run --working-dir=./dev-tools ../composer.json
  74. composer normalize --dry-run --working-dir=./dev-tools composer.json
  75. - name: Check - shell scripts
  76. run: ./dev-tools/check_shell_scripts.sh
  77. - name: Find changed files (for pull request)
  78. if: ${{ github.event_name == 'pull_request' }}
  79. run: |
  80. if git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$"; then
  81. echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
  82. git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" >> $GITHUB_ENV
  83. echo 'EOF' >> $GITHUB_ENV
  84. fi
  85. - name: Find changed files (for push)
  86. if: ${{ github.event_name != 'pull_request' }}
  87. run: |
  88. if git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$"; then
  89. echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
  90. git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" >> $GITHUB_ENV
  91. echo 'EOF' >> $GITHUB_ENV
  92. fi
  93. - name: Check - phpmd
  94. if: ${{ env.CHANGED_PHP_FILES }}
  95. run: |
  96. if [ '${{ github.event_name }}' == 'pull_request' ]; then
  97. ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | grep -v /Fixtures/ | xargs | sed 's/ /,/g'` github phpmd.xml
  98. else
  99. ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | grep -v /Fixtures/ | xargs | sed 's/ /,/g'` ansi phpmd.xml
  100. fi
  101. - name: Check - ensure test files are not present in the archive
  102. run: |
  103. git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php \
  104. && (echo "Test files detected in archive" && exit 1) || echo "No test files detected in archive"