Skip to content

Commit 84a70e0

Browse files
committed
[actions] phpcsfixer on changes files with git diff
1 parent e922e60 commit 84a70e0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/workflows/phpcs.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
2325

2426
- name: Setup PHP
2527
uses: shivammathur/setup-php@v2
@@ -29,7 +31,19 @@ jobs:
2931
- name: Install Composer dependencies
3032
uses: ramsey/composer-install@v3
3133

34+
- name: Get changed files
35+
id: changed-files
36+
run: |
37+
if ${{ github.event_name == 'pull_request' }}; then
38+
echo "all_changed_and_modified_files=$(git diff --name-only --diff-filter=ACMRTUXB -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
39+
else
40+
echo "all_changed_and_modified_files=$(git diff --name-only --diff-filter=ACMRTUXB ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
41+
fi
42+
3243
- name: PHP CS Fixer
33-
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --diff --using-cache=no
44+
run: |
45+
CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
46+
if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php-cs-fixer(\\.dist)?\\.php|composer\\.lock)$"; then EXTRA_ARGS=$(printf -- '--path-mode=intersection\n--\n%s' "${CHANGED_FILES}"); else EXTRA_ARGS=''; fi
47+
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --diff --using-cache=no ${EXTRA_ARGS}
3448
env:
3549
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.php-versions == '8.4' && '1' || '' }}

0 commit comments

Comments
 (0)