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: file_pattern:
description: File pattern used for "git add" description: File pattern used for "git add"
required: false required: false
default: '.'
runs: runs:
using: 'docker' using: 'docker'

View File

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