Files
prettier_action/action.yml
Claude a5f1df5578 Add use_repo_config parameter to automatically detect prettier configuration
This addresses GitHub issue #41 by adding an optional `use_repo_config` parameter
that allows the action to automatically detect and use the repository's prettier
configuration files and .prettierignore.

Changes:
- Added `use_repo_config` input parameter (default: false for backward compatibility)
- Implemented config file detection in entrypoint.sh for all prettier config formats
- Automatically changes file pattern to current directory when using repo config
- Provides helpful messages about found config files and warnings when none exist
- Updated README with new parameter documentation and Example 5

Benefits:
- Users no longer need to manually specify --config or --ignore-path
- Eliminates confusion about whether config files are being used
- Maintains backward compatibility (opt-in via parameter)
- Supports all prettier configuration file formats

Related: #41
2025-11-17 15:40:12 +00:00

118 lines
4.5 KiB
YAML

name: Prettier Action
description: Automatically runs prettier on all your changes.
author: Conrad Großer <grosserconrad@gmail.com>
inputs:
commit_message:
description: Commit message, will be ignored if used with same_commit
required: false
default: "Prettified Code!"
commit_description:
description: Extended commit message, will be ignored if used with same_commit
required: false
default: ""
same_commit:
description: Update the current commit instead of creating a new one
required: false
default: false
add_options:
description: Git add options
required: false
commit_options:
description: Commit options
required: false
push_options:
description: Git push options
required: false
file_pattern:
description: File pattern used for `git add`, can't be used with only_changed or only_changed_pr!
required: false
default: "*"
prettier_options:
description: Options for the `prettier` command
required: false
default: "--write **/*.js"
dry:
description: Running the script in dry mode just shows whether there are files that should be prettified or not
required: false
default: false
no_commit:
description: Can be used to avoid committing the changes (can be combined with dry mode, useful when another workflow steps commits after this commit anyways)
required: false
default: false
prettier_version:
description: Specific version of prettier (by default just use the latest version)
required: false
default: "latest"
working_directory:
description: Specify a directory to cd into before installing prettier and running it
required: false
default: ${{ github.action_path }}
only_changed:
description: Only prettify files changed in the last commit, can't be used with file_pattern!
required: false
default: false
only_changed_pr:
description: Only prettify files changed in the current PR. If specified with only_changed, only_changed will take precedent. Can't be used with file_pattern!
required: false
default: false
prettier_plugins:
description: Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other`
required: false
default: ""
github_token:
description: GitHub Token or PAT token used to authenticate against a repository
required: false
default: ${{ github.token }}
clean_node_folder:
description: Remove the node_modules folder before committing changes
required: false
default: true
git_identity:
description: Which identity is used for git name/email when committing changes. Needs to be one of "actions" or "author".
required: false
default: "actions"
allow_other_plugins:
description: Allow other plugins to be installed. By default, we are checking if the plugins are actually prettier plugins.
required: false
default: false
use_repo_config:
description: Use the repository's prettier configuration files (.prettierrc, prettier.config.js, etc.) and .prettierignore automatically. When enabled, prettier will search for config files in the repository.
required: false
default: false
runs:
using: "composite"
steps:
- name: Prettify code!
shell: bash
run: >-
PATH=$GITHUB_ACTION_PATH/node_modules/.bin:$PATH
${{ github.action_path }}/entrypoint.sh
env:
INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }}
INPUT_COMMIT_DESCRIPTION: ${{ inputs.commit_description }}
INPUT_SAME_COMMIT: ${{ inputs.same_commit }}
INPUT_ADD_OPTIONS: ${{ inputs.add_options }}
INPUT_COMMIT_OPTIONS: ${{ inputs.commit_options }}
INPUT_PUSH_OPTIONS: ${{ inputs.push_options }}
INPUT_FILE_PATTERN: ${{ inputs.file_pattern }}
INPUT_PRETTIER_OPTIONS: ${{ inputs.prettier_options }}
INPUT_DRY: ${{ inputs.dry }}
INPUT_NO_COMMIT: ${{ inputs.no_commit }}
INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }}
INPUT_ONLY_CHANGED: ${{ inputs.only_changed }}
INPUT_ONLY_CHANGED_PR: ${{ inputs.only_changed_pr }}
INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }}
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_CLEAN_NODE_FOLDER: ${{ inputs.clean_node_folder }}
INPUT_GIT_IDENTITY: ${{ inputs.git_identity }}
INPUT_ALLOW_OTHER_PLUGINS: ${{ inputs.allow_other_plugins }}
INPUT_USE_REPO_CONFIG: ${{ inputs.use_repo_config }}
branding:
icon: "award"
color: "green"