Improved README and Code

This commit is contained in:
2020-02-19 12:16:39 +01:00
parent 7224bd5fbf
commit 8bd9c88a06
3 changed files with 13 additions and 9 deletions

View File

@@ -1,7 +1,9 @@
#!/bin/sh
# e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set, x is for showing the commands before they are executed
set -eux
# 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
# 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)
_git_setup ( ) {
cat <<- EOF > $HOME/.netrc
@@ -18,10 +20,12 @@ EOF
git config --global user.name "GitHub Action"
}
# Checks if any files are changed
_git_changed() {
[[ -n "$(git status -s)" ]]
}
# Pushes to the according upstream (origin or input branch)
_git_push() {
if [ -z "$INPUT_BRANCH" ]
then
@@ -31,21 +35,23 @@ _git_push() {
fi
}
# PROGRAM
echo "Installing prettier..."
npm install --silent --global prettier
echo "Prettifing files..."
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem while prettifying your files!"
prettier $INPUT_PRETTIER_OPTIONS || echo "Problem while prettifying your files with options $INPUT_PRETTIER_OPTIONS"
# To keep runtime good, just continue if something was changed
if _git_changed;
then
# Calling method to configure the git environemnt
_git_setup
echo "Commiting and pushing changes..."
# Switch to the actual branch
git checkout $INPUT_BRANCH
git checkout $INPUT_BRANCH || echo "Problem checking out the specified branch: $INPUT_BRANCH"
# Add changes to git
git add "${INPUT_FILE_PATTERN}"
git add "${INPUT_FILE_PATTERN}" || echo "Problem adding your files with pattern ${INPUT_FILE_PATTERN}"
# Commit and push changes back
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
_git_push