From 366f0c6985fe5606ae503dbe6febb873f47600f9 Mon Sep 17 00:00:00 2001 From: zhanghongtong Date: Fri, 5 Mar 2021 17:53:52 +0800 Subject: [PATCH 1/3] feat: add option for where to force push --- README.md | 1 + action.yml | 6 +++++- git-sync.sh | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f71b9e7..6cb726b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ jobs: source_branch: "main" destination_repo: "destination_org/repository" destination_branch: "main" + destination_force_push: "1" # optional, whether to force push to destination ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} # optional source_ssh_private_key: ${{ secrets.SOURCE_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY` destination_ssh_private_key: ${{ secrets.DESTINATION_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY` diff --git a/action.yml b/action.yml index 83fe5ca..7baefdf 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,9 @@ inputs: destination_branch: description: Branch name to sync to required: true + destination_force_push: + description: Whether to force push to destination + required: false ssh_private_key: description: SSH key used to authenticate with source and destination ssh urls provided (optional if public or https url with authentication) required: false @@ -37,4 +40,5 @@ runs: - ${{ inputs.source_repo }} - ${{ inputs.source_branch }} - ${{ inputs.destination_repo }} - - ${{ inputs.destination_branch }} \ No newline at end of file + - ${{ inputs.destination_branch }} + - ${{ inputs.destination_force_push }} diff --git a/git-sync.sh b/git-sync.sh index 05a0e0a..fb7e4ce 100755 --- a/git-sync.sh +++ b/git-sync.sh @@ -6,6 +6,7 @@ SOURCE_REPO=$1 SOURCE_BRANCH=$2 DESTINATION_REPO=$3 DESTINATION_BRANCH=$4 +DESTINATION_FORCE_PUSH=$5 if ! echo $SOURCE_REPO | grep -Eq ':|@|\.git\/?$'; then if [[ -n "$SSH_PRIVATE_KEY" || -n "$SOURCE_SSH_PRIVATE_KEY" ]]; then @@ -48,4 +49,8 @@ if [[ -n "$DESTINATION_SSH_PRIVATE_KEY" ]]; then git config --local core.sshCommand "/usr/bin/ssh -i ~/.ssh/dst_rsa" fi -git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" -f +if [[ -n "$SOURCE_SSH_PRIVATE_KEY" ]]; then + git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" -f +else + git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" +fi From 1caa7baebb773dc3ae96d4e12f03ac7e94dd0875 Mon Sep 17 00:00:00 2001 From: Rory Date: Sun, 2 Oct 2022 17:08:35 +0800 Subject: [PATCH 2/3] Update git-sync.sh Co-authored-by: Roy Ivy III --- git-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-sync.sh b/git-sync.sh index fb7e4ce..f68f66c 100755 --- a/git-sync.sh +++ b/git-sync.sh @@ -49,7 +49,7 @@ if [[ -n "$DESTINATION_SSH_PRIVATE_KEY" ]]; then git config --local core.sshCommand "/usr/bin/ssh -i ~/.ssh/dst_rsa" fi -if [[ -n "$SOURCE_SSH_PRIVATE_KEY" ]]; then +if [[ -n "$DESTINATION_FORCE_PUSH" && "$DESTINATION_FORCE_PUSH" = true ]]; then git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" -f else git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" From ef6ef8b6140251ff40b48c94181399ba1bcd2558 Mon Sep 17 00:00:00 2001 From: Rory Date: Sun, 2 Oct 2022 17:08:44 +0800 Subject: [PATCH 3/3] Update README.md Co-authored-by: Roy Ivy III --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6cb726b..6d62b50 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ jobs: source_branch: "main" destination_repo: "destination_org/repository" destination_branch: "main" - destination_force_push: "1" # optional, whether to force push to destination + destination_force_push: "true" # optional, whether to force push to destination ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} # optional source_ssh_private_key: ${{ secrets.SOURCE_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY` destination_ssh_private_key: ${{ secrets.DESTINATION_SSH_PRIVATE_KEY }} # optional, will override `SSH_PRIVATE_KEY`