mirror of
https://github.com/cpina/github-action-push-to-another-repository.git
synced 2024-12-21 23:56:09 -07:00
Create branch if needed option
This commit is contained in:
parent
0a14457bb2
commit
33585ea95a
|
@ -48,6 +48,12 @@ inputs:
|
|||
description: '[Optional] The directory to wipe and replace in the target repository'
|
||||
default: ''
|
||||
required: false
|
||||
create-target-branch-if-needed:
|
||||
type: boolean
|
||||
description: >-
|
||||
[Optional] create target branch if not exist. Defaults to `false`
|
||||
default: false
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: docker
|
||||
|
@ -64,6 +70,7 @@ runs:
|
|||
- '${{ inputs.target-branch }}'
|
||||
- '${{ inputs.commit-message }}'
|
||||
- '${{ inputs.target-directory }}'
|
||||
- '${{ inputs.create-target-branch-if-needed }}'
|
||||
branding:
|
||||
icon: git-commit
|
||||
color: green
|
||||
|
|
|
@ -15,6 +15,7 @@ DESTINATION_REPOSITORY_USERNAME="${8}"
|
|||
TARGET_BRANCH="${9}"
|
||||
COMMIT_MESSAGE="${10}"
|
||||
TARGET_DIRECTORY="${11}"
|
||||
CREATE_TARGET_BRANCH_IF_NEEDED="${12}"
|
||||
|
||||
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
|
||||
then
|
||||
|
@ -70,6 +71,12 @@ git config --global user.name "$USER_NAME"
|
|||
|
||||
{
|
||||
git clone --single-branch --depth 1 --branch "$TARGET_BRANCH" "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
|
||||
} || {
|
||||
if [ "$CREATE_TARGET_BRANCH_IF_NEEDED" = 'true' ] ; then
|
||||
git clone --single-branch --depth 1 "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
|
||||
else
|
||||
false
|
||||
fi
|
||||
} || {
|
||||
echo "::error::Could not clone the destination repository. Command:"
|
||||
echo "::error::git clone --single-branch --branch $TARGET_BRANCH $GIT_CMD_REPOSITORY $CLONE_DIR"
|
||||
|
@ -137,6 +144,11 @@ echo "[+] Set directory is safe ($CLONE_DIR)"
|
|||
# TODO: review before releasing it as a version
|
||||
git config --global --add safe.directory "$CLONE_DIR"
|
||||
|
||||
|
||||
if [ "$CREATE_TARGET_BRANCH_IF_NEEDED" = 'true' ] ; then
|
||||
git checkout -b "$TARGET_BRANCH"
|
||||
fi
|
||||
|
||||
echo "[+] Adding git commit"
|
||||
git add .
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user