diff --git a/README.md b/README.md index f71b9e7..6d62b50 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: "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` 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..f68f66c 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 "$DESTINATION_FORCE_PUSH" && "$DESTINATION_FORCE_PUSH" = true ]]; then + git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" -f +else + git push destination "${SOURCE_BRANCH}:${DESTINATION_BRANCH}" +fi