mirror of
https://github.com/cpina/github-action-push-to-another-repository.git
synced 2025-09-05 08:05:47 -06:00
Merge 91dc6c8e2bacbf3289b969090e2c1db7edb2d329 into 0a14457bb28b04dfa1652e0ffdfda866d2845c73
This commit is contained in:
commit
4284411f1d
@ -48,6 +48,10 @@ 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:
|
||||||
|
description: '[Optional] Boolean indicating whether to create target branch if it does not exist'
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: docker
|
using: docker
|
||||||
@ -64,6 +68,7 @@ runs:
|
|||||||
- '${{ inputs.target-branch }}'
|
- '${{ inputs.target-branch }}'
|
||||||
- '${{ inputs.commit-message }}'
|
- '${{ inputs.commit-message }}'
|
||||||
- '${{ inputs.target-directory }}'
|
- '${{ inputs.target-directory }}'
|
||||||
|
- '${{ inputs.create-target-branch }}'
|
||||||
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="${12}"
|
||||||
|
|
||||||
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
|
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
|
||||||
then
|
then
|
||||||
@ -56,6 +57,7 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
CLONE_DIR=$(mktemp -d)
|
CLONE_DIR=$(mktemp -d)
|
||||||
|
new_target_branch=0
|
||||||
|
|
||||||
echo "[+] Git version"
|
echo "[+] Git version"
|
||||||
git --version
|
git --version
|
||||||
@ -67,17 +69,24 @@ echo "[+] Cloning destination git repository $DESTINATION_REPOSITORY_NAME"
|
|||||||
# Setup git
|
# Setup git
|
||||||
git config --global user.email "$USER_EMAIL"
|
git config --global user.email "$USER_EMAIL"
|
||||||
git config --global user.name "$USER_NAME"
|
git config --global user.name "$USER_NAME"
|
||||||
|
git config --global --add safe.directory /github/workspace
|
||||||
|
|
||||||
{
|
if ! git clone --single-branch --depth 1 --branch "$TARGET_BRANCH" "$GIT_CMD_REPOSITORY" "$CLONE_DIR"; then
|
||||||
git clone --single-branch --depth 1 --branch "$TARGET_BRANCH" "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
|
if ${CREATE_TARGET_BRANCH} && git clone --single-branch --depth 1 "$GIT_CMD_REPOSITORY" "$CLONE_DIR"; then
|
||||||
} || {
|
new_target_branch=1
|
||||||
echo "::error::Could not clone the destination repository. Command:"
|
else
|
||||||
echo "::error::git clone --single-branch --branch $TARGET_BRANCH $GIT_CMD_REPOSITORY $CLONE_DIR"
|
echo "::error::Could not clone the destination repository ('$GIT_CMD_REPOSITORY')."
|
||||||
echo "::error::(Note that if they exist USER_NAME and API_TOKEN is redacted by GitHub)"
|
echo -n "::error::Please verify that the target repository exists and is accesible with your API_TOKEN_GITHUB OR SSH_DEPLOY_KEY"
|
||||||
echo "::error::Please verify that the target repository exist AND that it contains the destination branch name, and is accesible by the API_TOKEN_GITHUB OR SSH_DEPLOY_KEY"
|
if ${CREATE_TARGET_BRANCH}; then
|
||||||
|
echo "."
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo "::error::and that it contains the target branch ('$TARGET_BRANCH')."
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
|
||||||
ls -la "$CLONE_DIR"
|
ls -la "$CLONE_DIR"
|
||||||
|
|
||||||
TEMP_DIR=$(mktemp -d)
|
TEMP_DIR=$(mktemp -d)
|
||||||
@ -137,6 +146,12 @@ 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 [ ${new_target_branch} -ne 0 ]; then
|
||||||
|
echo "[+] Creating target branch ${TARGET_BRANCH}"
|
||||||
|
git branch ${TARGET_BRANCH}
|
||||||
|
git switch ${TARGET_BRANCH}
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[+] Adding git commit"
|
echo "[+] Adding git commit"
|
||||||
git add .
|
git add .
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user