Merge 86e4dfff89fa3d6f1e1b0df2973361c21bad3bbe into 7c1bd869f38327ce403753fc2a5769e26cacb5ac

This commit is contained in:
Satyam 2025-02-16 10:48:46 +05:30 committed by GitHub
commit ce61ee201c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 67 additions and 23 deletions

View File

@ -54,6 +54,14 @@ inputs:
[Optional] create target branch if not exist. Defaults to `false` [Optional] create target branch if not exist. Defaults to `false`
default: false default: false
required: false required: false
source-file:
description: '[Optional] Source file to transfer'
required: false
default: ''
target-file:
description: '[Optional] Target file path in destination repository'
required: false
default: ''
runs: runs:
using: docker using: docker
@ -71,6 +79,8 @@ runs:
- '${{ inputs.commit-message }}' - '${{ inputs.commit-message }}'
- '${{ inputs.target-directory }}' - '${{ inputs.target-directory }}'
- '${{ inputs.create-target-branch-if-needed }}' - '${{ inputs.create-target-branch-if-needed }}'
- '${{ inputs.source-file }}'
- '${{ inputs.target-file }}'
branding: branding:
icon: git-commit icon: git-commit
color: green color: green

View File

@ -16,6 +16,8 @@ TARGET_BRANCH="${9}"
COMMIT_MESSAGE="${10}" COMMIT_MESSAGE="${10}"
TARGET_DIRECTORY="${11}" TARGET_DIRECTORY="${11}"
CREATE_TARGET_BRANCH_IF_NEEDED="${12}" CREATE_TARGET_BRANCH_IF_NEEDED="${12}"
SOURCE_FILE="${13}"
TARGET_FILE="${14}"
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ] if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
then then
@ -100,14 +102,18 @@ TEMP_DIR=$(mktemp -d)
# including "." and with the exception of ".git/" # including "." and with the exception of ".git/"
mv "$CLONE_DIR/.git" "$TEMP_DIR/.git" mv "$CLONE_DIR/.git" "$TEMP_DIR/.git"
# $TARGET_DIRECTORY is '' by default # Do this if sourcefile and target file is not set, means we are doing a directory transfer
ABSOLUTE_TARGET_DIRECTORY="$CLONE_DIR/$TARGET_DIRECTORY/" if [ -z "$SOURCE_FILE" ] && [ -z "$TARGET_FILE" ]
then
# $TARGET_DIRECTORY is '' by default
ABSOLUTE_TARGET_DIRECTORY="$CLONE_DIR/$TARGET_DIRECTORY/"
echo "[+] Deleting $ABSOLUTE_TARGET_DIRECTORY" echo "[+] Deleting $ABSOLUTE_TARGET_DIRECTORY"
rm -rf "$ABSOLUTE_TARGET_DIRECTORY" rm -rf "$ABSOLUTE_TARGET_DIRECTORY"
echo "[+] Creating (now empty) $ABSOLUTE_TARGET_DIRECTORY" echo "[+] Creating (now empty) $ABSOLUTE_TARGET_DIRECTORY"
mkdir -p "$ABSOLUTE_TARGET_DIRECTORY" mkdir -p "$ABSOLUTE_TARGET_DIRECTORY"
fi
echo "[+] Listing Current Directory Location" echo "[+] Listing Current Directory Location"
ls -al ls -al
@ -117,26 +123,54 @@ ls -al /
mv "$TEMP_DIR/.git" "$CLONE_DIR/.git" mv "$TEMP_DIR/.git" "$CLONE_DIR/.git"
echo "[+] List contents of $SOURCE_DIRECTORY" # If sourcefile and target file is not set, means we are doing a directory transfer
ls "$SOURCE_DIRECTORY" if [ -z "$SOURCE_FILE" ] && [ -z "$TARGET_FILE" ]
echo "[+] Checking if local $SOURCE_DIRECTORY exist"
if [ ! -d "$SOURCE_DIRECTORY" ]
then then
echo "ERROR: $SOURCE_DIRECTORY does not exist" echo "[+] List contents of $SOURCE_DIRECTORY"
echo "This directory needs to exist when push-to-another-repository is executed" ls "$SOURCE_DIRECTORY"
echo
echo "In the example it is created by ./build.sh: https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L19" echo "[+] Checking if local $SOURCE_DIRECTORY exist"
echo if [ ! -d "$SOURCE_DIRECTORY" ]
echo "If you want to copy a directory that exist in the source repository" then
echo "to the target repository: you need to clone the source repository" echo "ERROR: $SOURCE_DIRECTORY does not exist"
echo "in a previous step in the same build section. For example using" echo "This directory needs to exist when push-to-another-repository is executed"
echo "actions/checkout@v2. See: https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L16" echo
exit 1 echo "In the example it is created by ./build.sh: https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L19"
echo
echo "If you want to copy a directory that exist in the source repository"
echo "to the target repository: you need to clone the source repository"
echo "in a previous step in the same build section. For example using"
echo "actions/checkout@v2. See: https://github.com/cpina/push-to-another-repository-example/blob/main/.github/workflows/ci.yml#L16"
exit 1
fi
echo "[+] Copying contents of source repository folder $SOURCE_DIRECTORY to folder $TARGET_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME"
cp -ra "$SOURCE_DIRECTORY"/. "$CLONE_DIR/$TARGET_DIRECTORY"
fi fi
echo "[+] Copying contents of source repository folder $SOURCE_DIRECTORY to folder $TARGET_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME" # If sourcefile and target file is set, means we are doing a file transfer
cp -ra "$SOURCE_DIRECTORY"/. "$CLONE_DIR/$TARGET_DIRECTORY" if [ -n "$SOURCE_FILE" ] && [ -n "$TARGET_FILE" ]
then
echo "[+] SOURCE_FILE: $SOURCE_FILE"
echo "[+] TARGET_FILE: $TARGET_FILE"
echo "[+] Copying single file from $SOURCE_FILE to $TARGET_FILE"
if [ ! -f "$SOURCE_FILE" ]
then
echo "::error::Source file $SOURCE_FILE does not exist"
exit 1
fi
# Create target directory if it doesn't exist
TARGET_FILE_DIR=$(dirname "$CLONE_DIR/$TARGET_FILE")
mkdir -p "$TARGET_FILE_DIR"
# Copy the file
cp "$SOURCE_FILE" "$CLONE_DIR/$TARGET_FILE"
fi
cd "$CLONE_DIR" cd "$CLONE_DIR"
echo "[+] Files that will be pushed" echo "[+] Files that will be pushed"