Skip to content

Commit

Permalink
Run static code analysis off GitHub Actions
Browse files Browse the repository at this point in the history
Add changed files check, disable the same checks from Travis CI

Remove conflict with HHVM
  • Loading branch information
sanmai committed Nov 26, 2020
1 parent 610277b commit 3d65fd1
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 38 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/sca.yaml
@@ -0,0 +1,114 @@
# yamllint disable rule:line-length

name: Static Code Analysis

on:
- pull_request
- push

jobs:
tests:
strategy:
matrix:
operating-system:
- ubuntu-latest
php-version:
- 7.4

name: Static Code Analysis

runs-on: ${{ matrix.operating-system }}

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
restore-keys: |
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
composer-${{ runner.os }}-${{ matrix.php-version }}-
composer-${{ runner.os }}-
composer-
- name: Install dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: |
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
- name: Report versions
run: |
composer info -D
- name: Install dev-tools
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
retry_wait_seconds: 30
command: |
./dev-tools/install.sh
- name: Run checks
run: |
./dev-tools/check_file_permissions.sh
./dev-tools/check_trailing_spaces.sh
./dev-tools/vendor/bin/phpstan analyse
./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json)
composer normalize --dry-run --working-dir=./dev-tools ../composer.json
./dev-tools/check_shell_scripts.sh
- name: Find changed files (for pull request)
if: ${{ github.event_name == 'pull_request' }}
run: |
git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true
echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Find changed files (for push)
if: ${{ github.event_name != 'pull_request' }}
run: |
git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true
echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Validate changed files
if: ${{ github.env.CHANGED_PHP_FILES }}
run: |
./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml
- name: Check for unknown files (to be removed in 3.0)
run: |
# @TODO remove at 3.0
git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php |
grep -v tests/Test/AbstractFixerTestCase.php |
grep -v tests/Test/AbstractIntegrationCaseFactory.php |
grep -v tests/Test/AbstractIntegrationTestCase.php |
grep -v tests/Test/Assert/AssertTokensTrait.php |
grep -v tests/Test/IntegrationCase.php |
grep -v tests/Test/IntegrationCaseFactory.php |
grep -v tests/Test/IntegrationCaseFactoryInterface.php |
grep -v tests/Test/InternalIntegrationCaseFactory.php |
grep -v tests/Test/IsIdenticalConstraint.php |
grep -v tests/TestCase.php \
&& (echo "UNKNOWN FILES DETECTED" && exit 1) || echo "NO UNKNOWN FILES"
35 changes: 0 additions & 35 deletions .travis.yml
Expand Up @@ -22,41 +22,6 @@ before_install:

jobs:
include:
-
stage: Static Code Analysis
php: 7.4
env: COMPOSER_FLAGS="--prefer-stable"
install:
- travis_retry ./dev-tools/install.sh

- travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
- composer info -D | sort
before_script:
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then COMMIT_RANGE=$TRAVIS_COMMIT_RANGE; else COMMIT_RANGE="HEAD~..HEAD"; fi;
- export CHANGED_PHP_FILES=`git diff --name-only --diff-filter=ACMRTUXB $COMMIT_RANGE | grep -E "\.php$"`
script:
# @TODO remove at 3.0
- |
git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php \
| grep -v tests/Test/AbstractFixerTestCase.php \
| grep -v tests/Test/AbstractIntegrationCaseFactory.php \
| grep -v tests/Test/AbstractIntegrationTestCase.php \
| grep -v tests/Test/Assert/AssertTokensTrait.php \
| grep -v tests/Test/IntegrationCase.php \
| grep -v tests/Test/IntegrationCaseFactory.php \
| grep -v tests/Test/IntegrationCaseFactoryInterface.php \
| grep -v tests/Test/InternalIntegrationCaseFactory.php \
| grep -v tests/Test/IsIdenticalConstraint.php \
| grep -v tests/TestCase.php \
&& (echo "UNKNOWN FILES DETECTED" && travis_terminate 1) || echo "NO UNKNOWN FILES"
- ./dev-tools/check_file_permissions.sh || travis_terminate 1
- ./dev-tools/check_trailing_spaces.sh || travis_terminate 1
- dev-tools/vendor/bin/phpstan analyse
- if [ -n "$CHANGED_PHP_FILES" ]; then ./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml || travis_terminate 1; fi
- ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json) || travis_terminate 1
- composer normalize --dry-run --working-dir=./dev-tools ../composer.json
- ./dev-tools/check_shell_scripts.sh

- &STANDARD_TEST_JOB
stage: Fast Test
php: 7.0
Expand Down
3 changes: 0 additions & 3 deletions dev-tools/composer.json
Expand Up @@ -12,9 +12,6 @@
"phpstan/phpstan": "0.12.18",
"phpstan/phpstan-phpunit": "^0.12"
},
"conflict": {
"hhvm": "*"
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
Expand Down

0 comments on commit 3d65fd1

Please sign in to comment.