From 2826053f0c07cc88f881187fd4c74a161b4f0ca5 Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 23 Jan 2023 12:56:23 +0100 Subject: [PATCH 1/4] Added option clean_node_folder for #108 --- README.md | 1 + action.yml | 5 +++++ entrypoint.sh | 13 ++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1d9b2dd..cfc56a9 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ A GitHub action for styling files with [prettier](https://prettier.io). | commit_description | :x: | - | Custom git extended commit message, will be ignored if used with `same_commit` | | file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! | | prettier_plugins | :x: | - | Install Prettier plugins, i.e. `"@prettier/plugin-php" "@prettier/plugin-other"`. Must be wrapped in quotes since @ is a reserved character in YAML. | +| clean_node_folder | :x: | `true` | Delete the node_modules folder before committing | | only_changed | :x: | `false` | Only prettify changed files, can't be used with file_pattern! This command works only with the checkout action set to fetch depth '0' (see example 2)| | github_token | :x: | `${{ github.token }}` | The default [GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret) or a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) diff --git a/action.yml b/action.yml index c709804..caa1c4d 100644 --- a/action.yml +++ b/action.yml @@ -54,6 +54,10 @@ inputs: 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 runs: using: "composite" @@ -76,6 +80,7 @@ runs: 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 }} branding: icon: "award" diff --git a/entrypoint.sh b/entrypoint.sh index 2d267ed..fc3de7a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -74,11 +74,14 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS \ || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; exit 1; } -# Ignore node modules and other action created files -if [ -d 'node_modules' ]; then - rm -r node_modules/ -else - echo "No node_modules/ folder." +# 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..." + if [ -d 'node_modules' ]; then + rm -r node_modules/ + else + echo "No node_modules/ folder." + fi fi if [ -f 'package-lock.json' ]; then From 9436c53771b4553f5215b5b909a5b2b04b3ba537 Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 23 Jan 2023 14:16:43 +0100 Subject: [PATCH 2/4] Added debug for prettier test result in the log --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index fc3de7a..28affa1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -74,6 +74,8 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS \ || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; exit 1; } +echo "Prettier result: $PRETTIER_RESULT" + # 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..." From 191599deb611be40e98ba88d6015f7a4a0655304 Mon Sep 17 00:00:00 2001 From: Tim Talbert Date: Fri, 17 Feb 2023 17:21:50 -0500 Subject: [PATCH 3/4] Don't use the npm bin command to resolve the bin path --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c709804..dc1e231 100644 --- a/action.yml +++ b/action.yml @@ -61,7 +61,7 @@ runs: - name: Prettify code! shell: bash run: >- - PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH + PATH=$GITHUB_ACTION_PATH/node_modules/.bin:$PATH ${{ github.action_path }}/entrypoint.sh env: INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }} From 6fe86ce41d053f545bde498809d8222434883372 Mon Sep 17 00:00:00 2001 From: Conrad Date: Sun, 19 Feb 2023 16:33:58 +0100 Subject: [PATCH 4/4] Added note for new npm 9 issue --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index cfc56a9..5d5935a 100644 --- a/README.md +++ b/README.md @@ -161,3 +161,12 @@ More documentation for writing a workflow can be found [here](https://help.githu ## Issues Please report all bugs and feature request using the [GitHub issues function](https://github.com/creyD/prettier_action/issues/new). Thanks! + +### Problem with NPM v9 (19.02.2023) + +This issue was discussed in https://github.com/creyD/prettier_action/issues/113. The action until release 4.2 uses the npm bin command, which apparently doesn't work on npm v9. A fix is introduced with v4.3 of this action. If you need an older version of the action working it works until v3.3 and between v3.3 and v4.2 you could use the workaround described in https://github.com/creyD/prettier_action/issues/113 by adding the below to your workflow file: + +``` +- name: Install npm v8 + run: npm i -g npm@8 +```