mirror of
https://github.com/cpina/github-action-push-to-another-repository.git
synced 2024-10-22 06:06:08 -06:00
5d8dc0fe1a
TARGET_BRANCH cannot have spaces currently but adding double shell for consistent style. GITHUB_USERNAME probably cannot have spaces but just for consistency (and in case that it can have spaces)
46 lines
1.1 KiB
Bash
Executable File
46 lines
1.1 KiB
Bash
Executable File
#!/bin/sh -l
|
|
|
|
echo "Starts"
|
|
FOLDER="$1"
|
|
GITHUB_USERNAME="$2"
|
|
GITHUB_REPO="$3"
|
|
USER_EMAIL="$4"
|
|
REPO_USERNAME="$5"
|
|
TARGET_BRANCH="$6"
|
|
|
|
if [ -z "$REPO_USERNAME" ]
|
|
then
|
|
REPO_USERNAME="$GITHUB_USERNAME"
|
|
fi
|
|
if [ -z "$TARGET_BRANCH" ]
|
|
then
|
|
TARGET_BRANCH="master"
|
|
fi
|
|
|
|
CLONE_DIR=$(mktemp -d)
|
|
|
|
echo "Cloning destination git repository"
|
|
# Setup git
|
|
git config --global user.email "$USER_EMAIL"
|
|
git config --global user.name "$GITHUB_USERNAME"
|
|
git clone --single-branch --branch "$TARGET_BRANCH" "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR"
|
|
ls -la "$CLONE_DIR"
|
|
|
|
echo "Cleaning destination repository of old files"
|
|
# Copy files into the git and deletes all git
|
|
find "$CLONE_DIR" | grep -v "^$CLONE_DIR/\.git" | grep -v "^$CLONE_DIR$" | xargs rm -rf # delete all files (to handle deletions)
|
|
ls -la "$CLONE_DIR"
|
|
|
|
echo "Copying contents to to git repo"
|
|
cp -r "$FOLDER"/* "$CLONE_DIR"
|
|
cd "$CLONE_DIR"
|
|
ls -la
|
|
|
|
echo "Adding git commit"
|
|
git add .
|
|
git status
|
|
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
|
|
|
|
echo "Pushing git commit"
|
|
git push origin "$TARGET_BRANCH"
|