From 6038fdfeb863b03c9c451ae039347fbeb1b7a3e4 Mon Sep 17 00:00:00 2001 From: andy Augustin Date: Tue, 21 Mar 2023 18:33:53 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20:rocket:=20(#328=20#316)=20add=20params?= =?UTF-8?q?=20for=20git=20user.name,=20user.email=20a=E2=80=A6=20(#330)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: :rocket: (#328 #316) add params for git user.name, user.email and git remote pull params * doc: :memo: fix linter issue * fix: :bug: fix default variable * fix: :bug: fix cmd args from string * fix: :bug: fix cmd args from string * fix: :bug: fix cmd args from string * fix: :bug: fix cmd args from string * doc: :memo: version bump v0.8.0 --- .github/workflows/actions_template_sync.yml | 2 +- CITATION.cff | 2 +- README.md | 11 +++++++---- action.yml | 9 +++++++++ src/entrypoint.sh | 6 ++++-- src/sync_template.sh | 5 +++-- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/actions_template_sync.yml b/.github/workflows/actions_template_sync.yml index a320121a..19c2ecba 100644 --- a/.github/workflows/actions_template_sync.yml +++ b/.github/workflows/actions_template_sync.yml @@ -16,7 +16,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.3 + uses: AndreasAugustin/actions-template-sync@v0.8.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: AndreasAugustin/template diff --git a/CITATION.cff b/CITATION.cff index ecfb934e..2c6dc413 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -23,4 +23,4 @@ keywords: - github - repo-sync license: MIT -version: v0.7.3 +version: v0.8.0 diff --git a/README.md b/README.md index 47df7621..72d1ed79 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.3 + uses: AndreasAugustin/actions-template-sync@v0.8.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: @@ -118,7 +118,7 @@ jobs: private_key: ${{ secrets.PRIVATE_KEY }} - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.3 + uses: AndreasAugustin/actions-template-sync@v0.8.0 with: github_token: ${{ steps.generate_token.outputs.token }} source_repo_path: @@ -146,7 +146,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: actions-template-sync - uses: AndreasAugustin/actions-template-sync@v0.7.3 + uses: AndreasAugustin/actions-template-sync@v0.8.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # , should be within secrets @@ -198,7 +198,7 @@ jobs: uses: actions/checkout@v3 - name: Test action step PAT - uses: AndreasAugustin/actions-template-sync@v0.7.3 + uses: AndreasAugustin/actions-template-sync@v0.8.0 with: github_token: ${{ secrets.SOURCE_REPO_PAT }} source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # , should be within secrets @@ -220,6 +220,9 @@ jobs: | is_dry_run | `[optional]` set to `true` if you do not want to push the changes and not want to create a PR | `false` | | | is_allow_hooks | `[optional]` set to `true` if you want to enable lifecycle hooks. Use this with caution! | `false` | `false` | | is_not_source_github | `[optional]` set to `true` if the source git provider is not GitHub | `false` | `false` | +| git_user_name | `[optional]` set the committer git user.name | `false` | `${GITHUB_ACTOR}` | +| git_user_email | `[optional]` set the committer git user.email | `false` | `github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}` | +| git_remote_pull_params |`[optional]` set remote pull parameters | `false` | `--allow-unrelated-histories --squash --strategy=recursive -X theirs` | ### Example diff --git a/action.yml b/action.yml index 11bcbdf0..e0bb5319 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,12 @@ inputs: is_not_source_github: description: '[optional] set to true if the source repository is not a github related repository. Useful e.q. if the source is GitLab' default: 'false' + git_user_name: + description: '[optional] set the committer git user.name for the merge commit' + git_user_email: + description: '[optional] set the committer git user.email for the merge commit' + git_remote_pull_params: + description: '[optional] set the pull parameters for the remote repository' runs: using: 'docker' image: 'src/Dockerfile' @@ -55,3 +61,6 @@ runs: IS_DRY_RUN: ${{ inputs.is_dry_run }} IS_ALLOW_HOOKS: ${{ inputs.is_allow_hooks }} IS_NOT_SOURCE_GITHUB: ${{ inputs.is_not_source_github }} + GIT_USER_NAME: ${{ inputs.git_user_name }} + GIT_USER_EMAIL: ${{ inputs.git_user_email }} + GIT_REMOTE_PULL_PARAMS: ${{ inputs.git_remote_pull_params }} diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 4208d10c..c5c34869 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -18,6 +18,8 @@ fi DEFAULT_REPO_HOSTNAME="github.com" SOURCE_REPO_HOSTNAME="${HOSTNAME:-${DEFAULT_REPO_HOSTNAME}}" +GIT_USER_NAME="${GIT_USER_NAME:-${GITHUB_ACTOR}}" +GIT_USER_EMAIL="${GIT_USER_EMAIL:-github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}}" # In case of ssh template repository this will be overwritten SOURCE_REPO_PREFIX="https://${SOURCE_REPO_HOSTNAME}/" @@ -52,8 +54,8 @@ function git_init() { echo "::group::git init" info "set git global configuration" - git config --global user.email "github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}" - git config --global user.name "${GITHUB_ACTOR}" + git config --global user.email "${GIT_USER_EMAIL}" + git config --global user.name "${GIT_USER_NAME}" git config --global pull.rebase false git config --global --add safe.directory /github/workspace git lfs install diff --git a/src/sync_template.sh b/src/sync_template.sh index e98c32fb..feb9e132 100644 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -32,6 +32,8 @@ if [[ -n "${SRC_SSH_PRIVATEKEY_ABS_PATH}" ]]; then export GIT_SSH_COMMAND="ssh -i ${SRC_SSH_PRIVATEKEY_ABS_PATH}" fi +GIT_REMOTE_PULL_PARAMS="${GIT_REMOTE_PULL_PARAMS:---allow-unrelated-histories --squash --strategy=recursive -X theirs}" + cmd_from_yml_file "install" TEMPLATE_SYNC_IGNORE_FILE_PATH=".templatesyncignore" @@ -68,8 +70,7 @@ debug "create new branch from default branch with name ${NEW_BRANCH}" git checkout -b "${NEW_BRANCH}" debug "pull changes from template" -# TODO(anau) eventually make squash optional -git pull "${SOURCE_REPO}" --allow-unrelated-histories --squash --strategy=recursive -X theirs +eval "git pull ${SOURCE_REPO} ${GIT_REMOTE_PULL_PARAMS}" echo "::endgroup::" # Check if the Ignore File exists inside .github folder or if it doesn't exist at all