Skip to content

Commit

Permalink
feat: add coauthor
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu4k committed Jul 21, 2020
1 parent b8458ef commit d7b8891
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ jobs:
### Inputs
| name | value | default | description |
| ------------ | ------ | --------------------------- | ----------- |
| github_token | string | | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. |
| user_email | string | 'github-actions[bot]@users.noreply.github.com' | Email used to configure user.email in `git config`. |
| user_name | string | 'github-actions[bot]' | Name used to configure user.name in `git config`. |
| branch | string | 'master' | Destination branch to push changes. |
| 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. |
| repository | string | '' | Repository name. Default or empty repository name represents current github repository. If you want to push to other repository, you should make a [personal access token](https://github.com/settings/tokens) and use it as the `github_token` input. |
| name | value | default | description |
| -------------- | ------ | --------------------------- | ----------- |
| github_token | string | | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. |
| author_email | string | 'github-actions[bot]@users.noreply.github.com' | Email used to configure user.email in `git config`. |
| 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. |
| branch | string | 'master' | Destination branch to push changes. |
| 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. |
| repository | string | '' | Repository name. Default or empty repository name represents current github repository. If you want to push to other repository, you should make a [personal access token](https://github.com/settings/tokens) and use it as the `github_token` input. |

## License

Expand Down
14 changes: 10 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ inputs:
github_token:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
required: true
user_email:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
author_email:
description: 'Email used to configure user.email in `git config`.'
default: 'github-actions[bot]@users.noreply.github.com'
required: false
user_name:
description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
author_name:
description: 'Name used to configure user.name in `git config`.'
default: 'github-actions[bot]'
required: false
coauthor_email:
description: 'Email used to make a co-authored commit.'
required: false
coauthor_name:
description: 'Name used to make a co-authored commit.'
required: false
repository:
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
Expand Down
24 changes: 17 additions & 7 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/sh
set -e

INPUT_USER_EMAIL=${INPUT_USER_EMAIL:-'github-actions[bot]@users.noreply.github.com'}
INPUT_USER_NAME=${INPUT_USER_NAME:-'github-actions[bot]'}
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_BRANCH=${INPUT_BRANCH:-master}
INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
Expand All @@ -24,17 +26,25 @@ if ${INPUT_TAGS}; then
_TAGS='--tags'
fi

cd ${INPUT_DIRECTORY}
cd "${INPUT_DIRECTORY}"

remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"

git config http.sslVerify false
git config --local user.email "${INPUT_USER_EMAIL}"
git config --local user.name "${INPUT_USER_NAME}"
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
git commit -m "chore: autopublish ${timestamp}" || exit 0

git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;
if [ -n "${INPUT_COAUTHOR_EMAIL}" ] && [ -n "${INPUT_COAUTHOR_NAME}" ]; then
git commit -m "chore: autopublish ${timestamp}
Co-authored-by: ${INPUT_COAUTHOR_NAME} <${INPUT_COAUTHOR_EMAIL}>" || exit 0
else
git commit -m "chore: autopublish ${timestamp}" || exit 0
fi

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

0 comments on commit d7b8891

Please sign in to comment.