Merge branch 'dev' into override-token

This commit is contained in:
2021-06-17 00:21:33 +02:00
committed by GitHub
4 changed files with 64 additions and 21 deletions

View File

@@ -1,7 +1,8 @@
#!/bin/sh
#!/bin/bash
# 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
# 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)
@@ -25,14 +26,23 @@ _git_changed() {
[[ -n "$(git status -s)" ]]
}
_git_changes() {
git diff
}
(
# PROGRAM
# Changing to the directory
cd "$GITHUB_ACTION_PATH"
echo "Installing prettier..."
case $INPUT_PRETTIER_VERSION in
false)
npm install --silent --global prettier
npm install --silent prettier
;;
*)
npm install --silent --global prettier@$INPUT_PRETTIER_VERSION
npm install --silent prettier@$INPUT_PRETTIER_VERSION
;;
esac
@@ -48,15 +58,24 @@ if [ -n "$INPUT_PRETTIER_PLUGINS" ]; then
done
npm install --silent --global $INPUT_PRETTIER_PLUGINS
fi
)
echo "Prettifing files..."
PRETTIER_RESULT=0
echo "Prettifying files..."
echo "Files:"
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"
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."
# To keep runtime good, just continue if something was changed
if _git_changed; then
# case when --write is used with dry-run so if something is unpretty there will always have _git_changed
if $INPUT_DRY; then
echo "Prettier found unpretty files!"
echo "Unpretty Files Changes:"
_git_changes
echo "Finishing dry-run. Exiting before committing."
exit 1
else
# Calling method to configure the git environemnt
@@ -81,10 +100,18 @@ 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
git push origin $INPUT_PUSH_OPTIONS
fi
echo "Changes pushed successfully."
fi
else
# case when --check is used so there will never have something to commit but there are unpretty files
if [ "$PRETTIER_RESULT" -eq 1 ]; then
echo "Prettier found unpretty files!"
exit 1
else
echo "Finishing dry-run."
fi
echo "No unpretty files!"
echo "Nothing to commit. Exiting."
fi