From aeab4259d8a1a03e2b20ad0d80604036e4955eab Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 21 Jun 2021 23:00:56 -0300 Subject: [PATCH 1/4] Adding missing environment variable INPUT_GITHUB_TOKEN --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 3d0d5f1..3217353 100644 --- a/action.yml +++ b/action.yml @@ -66,6 +66,7 @@ runs: INPUT_PRETTIER_VERSION: ${{ inputs.prettier_version }} INPUT_ONLY_CHANGED: ${{ inputs.only_changed }} INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }} + INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} branding: icon: "award" From c97500dd80e2c0247a2e2dc61e0607a0b319affa Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 21 Jun 2021 23:03:58 -0300 Subject: [PATCH 2/4] Checking if generated files exist before trying to delete them --- entrypoint.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 526d1ee..6c3f433 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -66,8 +66,17 @@ echo "Files:" prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; } # Ignore node modules and other action created files -rm -r node_modules/ || echo "No node_modules/ folder." -git reset --hard package-lock.json || rm package-lock.json || echo "No package-lock.json file." +if [ -d 'node_modules' ]; then + rm -r node_modules/ +else + echo "No node_modules/ folder." +fi + +if [ -f 'package-lock.json' ]; then + git reset --hard package-lock.json || rm package-lock.json +else + echo "No package-lock.json file." +fi # To keep runtime good, just continue if something was changed if _git_changed; then From 8002e3525bd1c3623b481f162a79c54701b46c42 Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 21 Jun 2021 23:04:49 -0300 Subject: [PATCH 3/4] Making variable INPUT_PUSH_OPTIONS not required --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6c3f433..95de31b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -109,7 +109,7 @@ if _git_changed; then git push origin -f else git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"} || echo "No files added to commit" - git push origin $INPUT_PUSH_OPTIONS + git push origin ${INPUT_PUSH_OPTIONS:-} fi echo "Changes pushed successfully." fi From 6c9f8f188e813e7136edd1b05163d8965845e4b8 Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 21 Jun 2021 23:05:35 -0300 Subject: [PATCH 4/4] Displaying prettier error when a glob doesn't match any files --- entrypoint.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 95de31b..d3a358b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,7 @@ # e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set # x would be for showing the commands before they are executed set -eu -shopt -s globstar nullglob +shopt -s globstar # FUNCTIONS # Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh) @@ -63,7 +63,8 @@ fi PRETTIER_RESULT=0 echo "Prettifying files..." echo "Files:" -prettier $INPUT_PRETTIER_OPTIONS || { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; } +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