Skip to content

Add example in documentation to run action only for changed files #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2023

Conversation

ToshY
Copy link
Contributor

@ToshY ToshY commented Aug 26, 2023

Fixes #12


  1. In order to run the action on just the changed files, we use tj-actions/changed-files to get the diff.
  2. Next we construct a list of (intersection) arguments from the changed files.
    1. This code is derived from the PHP-CS-Fixer documentation, section "Using PHP CS Fixer on CI".
    2. As the $EXTRA_ARGS is a multiline string, we add it to $GITHUB_ENV (If there's a better way for this, please let me know).
  3. We pass the arguments to PHP-CS-Fixer using ${{ env.PHPCS_EXTRA_ARGS }}".

As sidenote, if you do not want or use this action but instead have php-cs-fixer as dev dependency in your application, the steps are somewhat simpler as you can do number 2 and 3 in a single step without the need for saving the variable to the environment.

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

      - name: PHP CS Fixer
        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
          vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --diff --using-cache=no ${EXTRA_ARGS}

@ToshY ToshY marked this pull request as ready for review August 26, 2023 21:08
@OskarStark OskarStark merged commit 35eeaa2 into OskarStark:master Aug 27, 2023
@OskarStark
Copy link
Owner

Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check only changed files in PR
2 participants