Skip to content

Commit

Permalink
Add example in documentation to run action only for changed files (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToshY authored Aug 27, 2023
1 parent 64313a6 commit 35eeaa2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,39 @@ jobs:

**You can copy/paste the `.github/` folder (under `examples/`) to your project and that's all!**

## Usage with only changed files

It is also possible to run PHP-CS-Fixer just on your changed files. To achieve this, you can use the [`tj-actions/changed-files`](https://github.com/tj-actions/changed-files) action to retrieve the changed files and subsequently use the result to create extra arguments with `---path-mode=intersection`.

```
on: [push, pull_request]
name: Main
jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v38

- name: Get extra arguments for PHP-CS-Fixer
id: phpcs-intersection
run: |
CHANGED_FILES=$(echo "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" | tr ' ' '\n')
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
echo "PHPCS_EXTRA_ARGS<<EOF" >> $GITHUB_ENV
echo "$EXTRA_ARGS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php -v --dry-run --stop-on-violation --using-cache=no ${{ env.PHPCS_EXTRA_ARGS }}"
```
## Docker
A Docker image is built automatically and located here:
Expand Down

0 comments on commit 35eeaa2

Please sign in to comment.