From d7b88913126db478c7daff06ce8a97ae826fd7f5 Mon Sep 17 00:00:00 2001 From: Qu4k Date: Tue, 21 Jul 2020 11:34:24 +0200 Subject: [PATCH] feat: add coauthor --- README.md | 22 ++++++++++++---------- action.yml | 14 ++++++++++---- start.sh | 24 +++++++++++++++++------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 7b3be78..72ad3df 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 840519c..fd74154 100644 --- a/action.yml +++ b/action.yml @@ -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})' diff --git a/start.sh b/start.sh index da5fd66..f5a968b 100644 --- a/start.sh +++ b/start.sh @@ -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} @@ -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; \ No newline at end of file +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; \ No newline at end of file