Skip to content

Commit 3d65fd1

Browse files
committed
Run static code analysis off GitHub Actions
Add changed files check, disable the same checks from Travis CI Remove conflict with HHVM
1 parent 610277b commit 3d65fd1

File tree

3 files changed

+114
-38
lines changed

3 files changed

+114
-38
lines changed

.github/workflows/sca.yaml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# yamllint disable rule:line-length
2+
3+
name: Static Code Analysis
4+
5+
on:
6+
- pull_request
7+
- push
8+
9+
jobs:
10+
tests:
11+
strategy:
12+
matrix:
13+
operating-system:
14+
- ubuntu-latest
15+
php-version:
16+
- 7.4
17+
18+
name: Static Code Analysis
19+
20+
runs-on: ${{ matrix.operating-system }}
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v2
25+
with:
26+
fetch-depth: 0
27+
28+
- name: Setup PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php-version }}
32+
33+
- name: Get Composer cache directory
34+
id: composer-cache
35+
run: echo "::set-output name=dir::$(composer config cache-dir)"
36+
37+
- name: Cache dependencies
38+
uses: actions/cache@v2
39+
with:
40+
path: ${{ steps.composer-cache.outputs.dir }}
41+
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-${{ matrix.composer-flags }}
42+
restore-keys: |
43+
composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('**/composer.*') }}-
44+
composer-${{ runner.os }}-${{ matrix.php-version }}-
45+
composer-${{ runner.os }}-
46+
composer-
47+
48+
- name: Install dependencies
49+
uses: nick-invision/retry@v2
50+
with:
51+
timeout_minutes: 5
52+
max_attempts: 5
53+
retry_wait_seconds: 30
54+
command: |
55+
composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }}
56+
57+
- name: Report versions
58+
run: |
59+
composer info -D
60+
61+
- name: Install dev-tools
62+
uses: nick-invision/retry@v2
63+
with:
64+
timeout_minutes: 5
65+
max_attempts: 5
66+
retry_wait_seconds: 30
67+
command: |
68+
./dev-tools/install.sh
69+
70+
- name: Run checks
71+
run: |
72+
./dev-tools/check_file_permissions.sh
73+
./dev-tools/check_trailing_spaces.sh
74+
./dev-tools/vendor/bin/phpstan analyse
75+
./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json)
76+
composer normalize --dry-run --working-dir=./dev-tools ../composer.json
77+
./dev-tools/check_shell_scripts.sh
78+
79+
- name: Find changed files (for pull request)
80+
if: ${{ github.event_name == 'pull_request' }}
81+
run: |
82+
git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true
83+
echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
84+
git diff origin/$GITHUB_BASE_REF --name-only --diff-filter=ACMRTUXB | grep -E "\.php$" || true >> $GITHUB_ENV
85+
echo 'EOF' >> $GITHUB_ENV
86+
87+
- name: Find changed files (for push)
88+
if: ${{ github.event_name != 'pull_request' }}
89+
run: |
90+
git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true
91+
echo 'CHANGED_PHP_FILES<<EOF' >> $GITHUB_ENV
92+
git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD | grep -E "\.php$" || true >> $GITHUB_ENV
93+
echo 'EOF' >> $GITHUB_ENV
94+
95+
- name: Validate changed files
96+
if: ${{ github.env.CHANGED_PHP_FILES }}
97+
run: |
98+
./dev-tools/vendor/bin/phpmd `echo "$CHANGED_PHP_FILES" | xargs | sed 's/ /,/g'` text phpmd.xml
99+
100+
- name: Check for unknown files (to be removed in 3.0)
101+
run: |
102+
# @TODO remove at 3.0
103+
git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php |
104+
grep -v tests/Test/AbstractFixerTestCase.php |
105+
grep -v tests/Test/AbstractIntegrationCaseFactory.php |
106+
grep -v tests/Test/AbstractIntegrationTestCase.php |
107+
grep -v tests/Test/Assert/AssertTokensTrait.php |
108+
grep -v tests/Test/IntegrationCase.php |
109+
grep -v tests/Test/IntegrationCaseFactory.php |
110+
grep -v tests/Test/IntegrationCaseFactoryInterface.php |
111+
grep -v tests/Test/InternalIntegrationCaseFactory.php |
112+
grep -v tests/Test/IsIdenticalConstraint.php |
113+
grep -v tests/TestCase.php \
114+
&& (echo "UNKNOWN FILES DETECTED" && exit 1) || echo "NO UNKNOWN FILES"

.travis.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,6 @@ before_install:
2222

2323
jobs:
2424
include:
25-
-
26-
stage: Static Code Analysis
27-
php: 7.4
28-
env: COMPOSER_FLAGS="--prefer-stable"
29-
install:
30-
- travis_retry ./dev-tools/install.sh
31-
32-
- travis_retry composer update $DEFAULT_COMPOSER_FLAGS $COMPOSER_FLAGS
33-
- composer info -D | sort
34-
before_script:
35-
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then COMMIT_RANGE=$TRAVIS_COMMIT_RANGE; else COMMIT_RANGE="HEAD~..HEAD"; fi;
36-
- export CHANGED_PHP_FILES=`git diff --name-only --diff-filter=ACMRTUXB $COMMIT_RANGE | grep -E "\.php$"`
37-
script:
38-
# @TODO remove at 3.0
39-
- |
40-
git archive -o /dev/null HEAD -v 2>&1 | grep tests | grep \.php \
41-
| grep -v tests/Test/AbstractFixerTestCase.php \
42-
| grep -v tests/Test/AbstractIntegrationCaseFactory.php \
43-
| grep -v tests/Test/AbstractIntegrationTestCase.php \
44-
| grep -v tests/Test/Assert/AssertTokensTrait.php \
45-
| grep -v tests/Test/IntegrationCase.php \
46-
| grep -v tests/Test/IntegrationCaseFactory.php \
47-
| grep -v tests/Test/IntegrationCaseFactoryInterface.php \
48-
| grep -v tests/Test/InternalIntegrationCaseFactory.php \
49-
| grep -v tests/Test/IsIdenticalConstraint.php \
50-
| grep -v tests/TestCase.php \
51-
&& (echo "UNKNOWN FILES DETECTED" && travis_terminate 1) || echo "NO UNKNOWN FILES"
52-
- ./dev-tools/check_file_permissions.sh || travis_terminate 1
53-
- ./dev-tools/check_trailing_spaces.sh || travis_terminate 1
54-
- dev-tools/vendor/bin/phpstan analyse
55-
- 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
56-
- ./dev-tools/vendor/bin/composer-require-checker check composer.json --config-file $(realpath .composer-require-checker.json) || travis_terminate 1
57-
- composer normalize --dry-run --working-dir=./dev-tools ../composer.json
58-
- ./dev-tools/check_shell_scripts.sh
59-
6025
- &STANDARD_TEST_JOB
6126
stage: Fast Test
6227
php: 7.0

dev-tools/composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
"phpstan/phpstan": "0.12.18",
1313
"phpstan/phpstan-phpunit": "^0.12"
1414
},
15-
"conflict": {
16-
"hhvm": "*"
17-
},
1815
"config": {
1916
"optimize-autoloader": true,
2017
"sort-packages": true

0 commit comments

Comments
 (0)