Skip to content

Commit

Permalink
feat: add support for amend input (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
devenes authored Dec 18, 2022
1 parent 9624971 commit 156f2b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
| message | string | 'chore: autopublish ${date}' | Commit message. |
| branch | string | 'main' | Destination branch to push changes. |
| empty | boolean | false | Allow empty commit. |
| amend | boolean | false | Determines if the commit should be amended. Needs to be used with `force` input to force push the amended commit. |
| force | boolean | false | Determines if force push is used. |
| tags | boolean | false | Determines if `--tags` is used. |
| directory | string | '.' | Directory to change to before pushing. |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ inputs:
empty:
description: 'Allow empty commit'
required: false
amend:
description: 'Determines if the commit should be amended'
required: false
default: 'false'
force:
description: 'Determines if force push is used'
required: false
Expand Down
16 changes: 15 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ INPUT_COAUTHOR_EMAIL=${INPUT_COAUTHOR_EMAIL:-''}
INPUT_COAUTHOR_NAME=${INPUT_COAUTHOR_NAME:-''}
INPUT_MESSAGE=${INPUT_MESSAGE:-"chore: autopublish ${timestamp}"}
INPUT_BRANCH=${INPUT_BRANCH:-master}
INPUT_AMEND=${INPUT_AMEND:-false}
INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_EMPTY=${INPUT_EMPTY:-false}
Expand All @@ -25,6 +26,10 @@ if ${INPUT_EMPTY}; then
_EMPTY='--allow-empty'
fi

if ${INPUT_AMEND}; then
_AMEND='--amend --no-edit'
fi

if ${INPUT_FORCE}; then
_FORCE_OPTION='--force'
fi
Expand All @@ -43,7 +48,16 @@ git config --local user.name "${INPUT_AUTHOR_NAME}"

git add -A

if [ -n "${INPUT_COAUTHOR_EMAIL}" ] && [ -n "${INPUT_COAUTHOR_NAME}" ]; then
if ${INPUT_AMEND}; then
if [ -n "${INPUT_COAUTHOR_EMAIL}" ] && [ -n "${INPUT_COAUTHOR_NAME}" ]; then
git commit ${_AMEND} -m "${INPUT_MESSAGE}
Co-authored-by: ${INPUT_COAUTHOR_NAME} <${INPUT_COAUTHOR_EMAIL}>" || exit 0
else
git commit ${_AMEND} -m "${INPUT_MESSAGE}" $_EMPTY || exit 0
fi

elif [ -n "${INPUT_COAUTHOR_EMAIL}" ] && [ -n "${INPUT_COAUTHOR_NAME}" ]; then
git commit -m "${INPUT_MESSAGE}
Expand Down

0 comments on commit 156f2b1

Please sign in to comment.