Skip to content

Commit

Permalink
Create branch if needed option
Browse files Browse the repository at this point in the history
  • Loading branch information
damiencornu committed Apr 25, 2023
1 parent 0a14457 commit 33585ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
12 changes: 12 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 .

Expand Down

0 comments on commit 33585ea

Please sign in to comment.