sca.yml 4.5 KB

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