From 6c29ec09bfc04168193fff6cd6b67cc82ac96ae6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Nov 2025 15:13:00 +0000 Subject: [PATCH] Add optional only_show_changed flag to show changed files only This is a non-breaking new feature that addresses issue #129. New input parameter: - only_show_changed (default: false) When true, shows only files that were changed by Prettier instead of all processed files. Useful for large projects where output is overwhelming. Backward compatibility: - When flag is NOT set or is false: behavior stays exactly as before (shows "Files:" header and all prettier output) - When flag is set to true: shows only "Changed files:" with git status output for modified files In projects with ~2,000 files, it's hard to see which were changed. This optional flag makes it easy to identify modified files without affecting existing users who rely on the current output format. Closes #129 Refs prettier/prettier#2611 --- action.yml | 5 +++++ entrypoint.sh | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 5072dcd..720b330 100644 --- a/action.yml +++ b/action.yml @@ -74,6 +74,10 @@ inputs: description: Allow other plugins to be installed. By default, we are checking if the plugins are actually prettier plugins. required: false default: false + only_show_changed: + description: Only show files that were changed by Prettier instead of all processed files. Useful for large projects where output is overwhelming. + required: false + default: false runs: using: "composite" @@ -102,6 +106,7 @@ runs: INPUT_CLEAN_NODE_FOLDER: ${{ inputs.clean_node_folder }} INPUT_GIT_IDENTITY: ${{ inputs.git_identity }} INPUT_ALLOW_OTHER_PLUGINS: ${{ inputs.allow_other_plugins }} + INPUT_ONLY_SHOW_CHANGED: ${{ inputs.only_show_changed }} branding: icon: "award" diff --git a/entrypoint.sh b/entrypoint.sh index ec9b329..32c2aec 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -65,12 +65,27 @@ fi PRETTIER_RESULT=0 echo "Prettifying files..." -echo "Files:" -npx prettier $INPUT_PRETTIER_OPTIONS \ - || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; exit 1; } >> $GITHUB_STEP_SUMMARY +if [ "$INPUT_ONLY_SHOW_CHANGED" = "true" ]; then + # New behavior: don't show all files, only show changed files later + npx prettier $INPUT_PRETTIER_OPTIONS \ + || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; exit 1; } +else + # Original behavior: show all files processed by prettier + echo "Files:" + npx prettier $INPUT_PRETTIER_OPTIONS \ + || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; exit 1; } >> $GITHUB_STEP_SUMMARY +fi echo "Prettier result: $PRETTIER_RESULT" +# Show only the files that were changed by prettier (when flag is enabled) +if [ "$INPUT_ONLY_SHOW_CHANGED" = "true" ] && _git_changed; then + echo "" + echo "Changed files:" + git status --short | tee -a $GITHUB_STEP_SUMMARY + echo "" +fi + # Removing the node_modules folder, so it doesn't get committed if it is not added in gitignore if $INPUT_CLEAN_NODE_FOLDER; then echo "Deleting node_modules/ folder..."