Add is_defined and get_value to improve on code's reusability

This commit is contained in:
gomorizsolt 2019-10-31 11:18:48 +01:00
parent a65a3a47cd
commit b6dcf94303
2 changed files with 15 additions and 9 deletions

View File

@ -16,7 +16,6 @@ inputs:
file_pattern:
description: File pattern used for "git add"
required: false
default: '.'
runs:
using: 'docker'

View File

@ -18,6 +18,18 @@ EOF
git config --global user.name "GitHub Actions"
}
is_defined() {
[ ! -z "${1}" ]
}
get_value() {
if is_defined "${1}"; then
return "${1}"
fi
return "${2}"
}
# This section only runs if there have been file changes
echo "Checking for uncommitted changes in the git working tree."
@ -30,15 +42,10 @@ then
# Switch to branch from current Workflow run
git checkout $INPUT_BRANCH
if [ -z ${INPUT_FILE_PATTERN+x} ];
then
git add .
else
echo "INPUT_FILE_PATTERN value: $INPUT_FILE_PATTERN";
git add $INPUT_FILE_PATTERN
fi
git add get_value "${INPUT_FILE_PATTERN}" '.'
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" get_value "${INPUT_COMMIT_OPTIONS}" ''
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" $INPUT_COMMIT_OPTIONS
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
else