Skip to content

Commit

Permalink
feat: add message & empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu4k committed Jul 27, 2020
1 parent d7b8891 commit 4decc28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
| author_name | string | 'github-actions[bot]' | Name used to configure user.name in `git config`. |
| coauthor_email | string | | Email used to make a co-authored commit. |
| coauthor_name | string | | Name used to make a co-authored commit. |
| message | string | 'chore: autopublish ${date}' | Commit message. |
| branch | string | 'master' | Destination branch to push changes. |
| empty | boolean | false | Allow empty 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
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ inputs:
required: false
coauthor_email:
description: 'Email used to make a co-authored commit.'
required: false
required: false
coauthor_name:
description: 'Name used to make a co-authored commit.'
required: false
message:
description: 'Commit message.'
required: false
repository:
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
default: ''
Expand All @@ -27,6 +30,9 @@ inputs:
description: 'Destination branch to push changes'
required: false
default: 'master'
empty:
description: 'Allow empty commit'
required: false
force:
description: 'Determines if force push is used'
required: false
Expand Down
17 changes: 11 additions & 6 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/bin/sh
set -e

timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

INPUT_AUTHOR_EMAIL=${INPUT_AUTHOR_EMAIL:-'github-actions[bot]@users.noreply.github.com'}
INPUT_AUTHOR_NAME=${INPUT_AUTHOR_NAME:-'github-actions[bot]'}
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_FORCE=${INPUT_FORCE:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_EMPTY=${INPUT_EMPTY:-false}
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
_FORCE_OPTION=''
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}

echo "Push to branch $INPUT_BRANCH";
Expand All @@ -18,6 +21,10 @@ echo "Push to branch $INPUT_BRANCH";
exit 1;
};

if ${INPUT_EMPTY}; then
_EMPTY='--allow-empty'
fi

if ${INPUT_FORCE}; then
_FORCE_OPTION='--force'
fi
Expand All @@ -34,17 +41,15 @@ git config http.sslVerify false
git config --local user.email "${INPUT_AUTHOR_EMAIL}"
git config --local user.name "${INPUT_AUTHOR_NAME}"

timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

git add -A

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

git push "${remote_repo}" HEAD:"${INPUT_BRANCH}" --follow-tags $_FORCE_OPTION $_TAGS;

0 comments on commit 4decc28

Please sign in to comment.