From 656daa9f97e5be763961d4928005770fa41a9eda Mon Sep 17 00:00:00 2001 From: "Sebastian K. Sorensen" Date: Sun, 10 Jan 2021 16:07:31 +0100 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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