mirror of
https://github.com/cpina/github-action-push-to-another-repository.git
synced 2024-12-22 08:06:10 -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'
|
description: '[Optional] The directory to wipe and replace in the target repository'
|
||||||
default: ''
|
default: ''
|
||||||
required: false
|
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:
|
runs:
|
||||||
using: docker
|
using: docker
|
||||||
|
@ -64,6 +70,7 @@ runs:
|
||||||
- '${{ inputs.target-branch }}'
|
- '${{ inputs.target-branch }}'
|
||||||
- '${{ inputs.commit-message }}'
|
- '${{ inputs.commit-message }}'
|
||||||
- '${{ inputs.target-directory }}'
|
- '${{ inputs.target-directory }}'
|
||||||
|
- '${{ inputs.create-target-branch-if-needed }}'
|
||||||
branding:
|
branding:
|
||||||
icon: git-commit
|
icon: git-commit
|
||||||
color: green
|
color: green
|
||||||
|
|
|
@ -15,6 +15,7 @@ DESTINATION_REPOSITORY_USERNAME="${8}"
|
||||||
TARGET_BRANCH="${9}"
|
TARGET_BRANCH="${9}"
|
||||||
COMMIT_MESSAGE="${10}"
|
COMMIT_MESSAGE="${10}"
|
||||||
TARGET_DIRECTORY="${11}"
|
TARGET_DIRECTORY="${11}"
|
||||||
|
CREATE_TARGET_BRANCH_IF_NEEDED="${12}"
|
||||||
|
|
||||||
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
|
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
|
||||||
then
|
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"
|
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::Could not clone the destination repository. Command:"
|
||||||
echo "::error::git clone --single-branch --branch $TARGET_BRANCH $GIT_CMD_REPOSITORY $CLONE_DIR"
|
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
|
# TODO: review before releasing it as a version
|
||||||
git config --global --add safe.directory "$CLONE_DIR"
|
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"
|
echo "[+] Adding git commit"
|
||||||
git add .
|
git add .
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user