diff --git a/README.md b/README.md index 78239a7..b1774de 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | - | :-: | :-: | - | | dry | :x: | `false` | Runs the action in dry mode. Files wont get changed and the action fails if there are unprettified files. Recommended to use with prettier_options --check | | prettier_version | :x: | `false` | Specific prettier version (by default use latest) | +| working_directory | :x: | `false` | Specify a directory to cd into before installing prettier and running it | | prettier_options | :x: | `"--write **/*.js"` | Prettier options (by default it applies to the whole repository) | | commit_options | :x: | - | Custom git commit options | | push_options | :x: | - | Custom git push options | diff --git a/action.yml b/action.yml index 691269a..c709804 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: Specific version of prettier (by default just use the latest version) required: false default: false + working_directory: + description: Specify a directory to cd into before installing prettier and running it + required: false + default: false only_changed: description: Only prettify files changed in the last commit, can't be used with file_pattern! required: false @@ -45,13 +49,12 @@ inputs: prettier_plugins: description: Install Prettier plugins, i.e. `@prettier/plugin-php @prettier/plugin-other` required: false - default: '' + default: "" github_token: description: GitHub Token or PAT token used to authenticate against a repository required: false default: ${{ github.token }} - runs: using: "composite" steps: @@ -71,6 +74,7 @@ runs: INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} + INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }} INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} branding: diff --git a/entrypoint.sh b/entrypoint.sh index b0b08ec..88f2df6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,6 +37,14 @@ cd "$GITHUB_ACTION_PATH" echo "Installing prettier..." +case $INPUT_WORKING_DIRECTORY in + false) + ;; + *) + cd $INPUT_WORKING_DIRECTORY + ;; +esac + case $INPUT_PRETTIER_VERSION in false) npm install --silent prettier