Create branch if needed option

This commit is contained in:
Damien Cornu 2023-04-25 14:31:00 +02:00
parent 0a14457bb2
commit 33585ea95a
2 changed files with 20 additions and 1 deletions

View File

@ -48,7 +48,13 @@ 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
image: Dockerfile
@ -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

View File

@ -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 .