From 193559158f3e609b9f65a3550ccb9163e68c1515 Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 14:22:14 +0100 Subject: [PATCH 01/12] Attempt to add prettier_plugins --- action.yml | 4 ++++ entrypoint.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 1314f93..63aacb7 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,10 @@ inputs: description: Only prettify files changed in the last commit, can't be used with file_pattern! required: false default: false + prettier_plugins: + description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` + required: false + default: false runs: using: 'docker' diff --git a/entrypoint.sh b/entrypoint.sh index 4db8011..b9fb0c9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,6 +30,9 @@ echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) npm install --silent --global prettier + if $INPUT_PRETTIER_PLUGINS; then + npm install --silent --global $INPUT_PRETTIER_PLUGINS + fi ;; *) npm install --silent --global prettier@$INPUT_PRETTIER_VERSION From 7ea43281214143988d43de05034dc50ee150bdfd Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 14:35:53 +0100 Subject: [PATCH 02/12] Adds a unique name to action --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 63aacb7..c049b74 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Prettier Action +name: Prettier Action Plugins description: Automatically runs prettier on all your changes. author: Conrad Großer From f852cea42f068d8a56b40ab71289778c7b34011c Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 14:52:20 +0100 Subject: [PATCH 03/12] Change check of variable --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index b9fb0c9..8cabb43 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,7 +30,7 @@ echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) npm install --silent --global prettier - if $INPUT_PRETTIER_PLUGINS; then + if [[ -n $INPUT_PRETTIER_PLUGINS ]]; then npm install --silent --global $INPUT_PRETTIER_PLUGINS fi ;; From b7cf1dc4c28fbabbd2e11534d4ea15dbe3a4ccb2 Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 15:32:37 +0100 Subject: [PATCH 04/12] Change action name to regular one --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c049b74..63aacb7 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Prettier Action Plugins +name: Prettier Action description: Automatically runs prettier on all your changes. author: Conrad Großer From a35b5cc1cb8c736496a07cbf95bfd8bb7a3b59fe Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 15:50:05 +0100 Subject: [PATCH 05/12] Change default to empty string instead --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 63aacb7..a0d155c 100644 --- a/action.yml +++ b/action.yml @@ -38,7 +38,7 @@ inputs: prettier_plugins: description: Install Prettier plugins, i.e. `@prettier/prettier-php @prettier/some-other-plugin` required: false - default: false + default: '' runs: using: 'docker' From 0faaf9bad1e9e0da4d30387b5c7ac07fd6839f86 Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 15:57:13 +0100 Subject: [PATCH 06/12] Use POSIX brackets instead --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8cabb43..7d14feb 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,7 +30,7 @@ echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) npm install --silent --global prettier - if [[ -n $INPUT_PRETTIER_PLUGINS ]]; then + if [ -n $INPUT_PRETTIER_PLUGINS ]; then npm install --silent --global $INPUT_PRETTIER_PLUGINS fi ;; From 1015fa1aafb6f212c867f6ebbf9fb6ea99a4326d Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 15:57:48 +0100 Subject: [PATCH 07/12] Use quotes when using [ --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7d14feb..78e004c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,7 +30,7 @@ echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) npm install --silent --global prettier - if [ -n $INPUT_PRETTIER_PLUGINS ]; then + if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then npm install --silent --global $INPUT_PRETTIER_PLUGINS fi ;; From 656daa9f97e5be763961d4928005770fa41a9eda Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 16:07:31 +0100 Subject: [PATCH 08/12] Attempt of checking plugin name with regex --- entrypoint.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8cabb43..32e83d1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -30,15 +30,25 @@ echo "Installing prettier..." case $INPUT_PRETTIER_VERSION in false) npm install --silent --global prettier - if [[ -n $INPUT_PRETTIER_PLUGINS ]]; then - npm install --silent --global $INPUT_PRETTIER_PLUGINS - fi ;; *) npm install --silent --global prettier@$INPUT_PRETTIER_VERSION ;; esac +# Install plugins +if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then + for plugin in $INPUT_PRETTIER_PLUGINS; do + # check regex against @prettier/xyz + REGEX = '(@prettier\/)+(plugin-[a-z\-]+)' + if ! [ "$plugin" =~ "$REGEX" ] + echo "Specified plugins does not seem to be valid @prettier/x plugins." + exit 1 + fi + done + npm install --silent --global $INPUT_PRETTIER_PLUGINS +fi + echo "Prettifing files..." echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS" From 33b1eff4868f0d24505c861832dddc3cbb306bbf Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 16:41:47 +0100 Subject: [PATCH 09/12] Fix issue with if statement --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 32e83d1..44e8a09 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,7 +41,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then for plugin in $INPUT_PRETTIER_PLUGINS; do # check regex against @prettier/xyz REGEX = '(@prettier\/)+(plugin-[a-z\-]+)' - if ! [ "$plugin" =~ "$REGEX" ] + if ! [ "$plugin" =~ "$REGEX" ]; then echo "Specified plugins does not seem to be valid @prettier/x plugins." exit 1 fi From 75b0a4fda50a78d33794fc47d8313cd12f0fef26 Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 17:40:38 +0100 Subject: [PATCH 10/12] Fix regex issue --- entrypoint.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 44e8a09..7543512 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,12 +39,14 @@ esac # Install plugins if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then for plugin in $INPUT_PRETTIER_PLUGINS; do + echo "checking $plugin" # check regex against @prettier/xyz - REGEX = '(@prettier\/)+(plugin-[a-z\-]+)' - if ! [ "$plugin" =~ "$REGEX" ]; then - echo "Specified plugins does not seem to be valid @prettier/x plugins." + REGEX='(@prettier\/)+(plugin-[a-z\-]+)' + if ! [[ "$plugin" =~ "$REGEX" ]]; then + echo "$plugin does not seem to be a valid @prettier/plugin-x plugin." exit 1 fi + echo "$plugin seem to be a valid Prettier plugin" done npm install --silent --global $INPUT_PRETTIER_PLUGINS fi From bb1392436fe89c4d73231664cd4cf28426a3ede1 Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 17:49:20 +0100 Subject: [PATCH 11/12] Change to sh regex --- entrypoint.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7543512..0e87e7b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,8 +41,7 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then for plugin in $INPUT_PRETTIER_PLUGINS; do echo "checking $plugin" # check regex against @prettier/xyz - REGEX='(@prettier\/)+(plugin-[a-z\-]+)' - if ! [[ "$plugin" =~ "$REGEX" ]]; then + if ! echo "$plugin" | grep -Eq '(@prettier\/)+(plugin-[a-z\-]+)'; then echo "$plugin does not seem to be a valid @prettier/plugin-x plugin." exit 1 fi From a20371f2d26c54b69c0d16634151ba398ba52a6d Mon Sep 17 00:00:00 2001 From: Conrad Date: Sun, 10 Jan 2021 21:04:03 +0100 Subject: [PATCH 12/12] Slightly adjusted the printed messages --- entrypoint.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0e87e7b..023e697 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,13 +39,12 @@ esac # Install plugins if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then for plugin in $INPUT_PRETTIER_PLUGINS; do - echo "checking $plugin" + echo "Checking plugin: $plugin" # check regex against @prettier/xyz if ! echo "$plugin" | grep -Eq '(@prettier\/)+(plugin-[a-z\-]+)'; then - echo "$plugin does not seem to be a valid @prettier/plugin-x plugin." + echo "$plugin does not seem to be a valid @prettier/plugin-x plugin. Exiting." exit 1 fi - echo "$plugin seem to be a valid Prettier plugin" done npm install --silent --global $INPUT_PRETTIER_PLUGINS fi