2020-03-29 08:44:47 -06:00
|
|
|
#!/bin/sh -l
|
|
|
|
|
|
|
|
echo "Starts"
|
2020-03-29 09:07:19 -06:00
|
|
|
FOLDER="$1"
|
|
|
|
GITHUB_USERNAME="$2"
|
|
|
|
GITHUB_REPO="$3"
|
2020-06-08 15:49:19 -06:00
|
|
|
USER_EMAIL="$4"
|
2020-08-07 14:49:54 -06:00
|
|
|
REPO_USERNAME="$5"
|
2020-09-23 01:49:12 -06:00
|
|
|
TARGET_BRANCH="$6"
|
2020-08-07 14:49:54 -06:00
|
|
|
|
2020-08-10 07:31:08 -06:00
|
|
|
if [ -z "$REPO_USERNAME" ]
|
|
|
|
then
|
2020-08-10 07:06:59 -06:00
|
|
|
REPO_USERNAME=$GITHUB_USERNAME
|
2020-08-07 14:49:54 -06:00
|
|
|
fi
|
2020-09-23 01:53:28 -06:00
|
|
|
if [ -z "$TARGET_BRANCH" ]
|
2020-09-23 01:49:12 -06:00
|
|
|
then
|
|
|
|
TARGET_BRANCH="master"
|
|
|
|
fi
|
2020-03-29 09:07:19 -06:00
|
|
|
|
2020-03-29 09:36:01 -06:00
|
|
|
CLONE_DIR=$(mktemp -d)
|
2020-03-29 09:13:00 -06:00
|
|
|
|
2020-08-10 08:02:28 -06:00
|
|
|
echo "Cloning destination git repository"
|
2020-03-29 09:20:35 -06:00
|
|
|
# Setup git
|
2020-06-08 15:49:19 -06:00
|
|
|
git config --global user.email "$USER_EMAIL"
|
2020-03-29 09:07:19 -06:00
|
|
|
git config --global user.name "$GITHUB_USERNAME"
|
2020-09-23 01:49:12 -06:00
|
|
|
git clone --single-branch --branch $TARGET_BRANCH "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR"
|
2020-03-29 09:30:55 -06:00
|
|
|
ls -la "$CLONE_DIR"
|
|
|
|
|
2020-08-10 08:02:28 -06:00
|
|
|
echo "Cleaning destination repository of old files"
|
2020-03-29 09:20:35 -06:00
|
|
|
# Copy files into the git and deletes all git
|
2020-03-29 09:49:16 -06:00
|
|
|
find "$CLONE_DIR" | grep -v "^$CLONE_DIR/\.git" | grep -v "^$CLONE_DIR$" | xargs rm -rf # delete all files (to handle deletions)
|
2020-03-29 09:30:55 -06:00
|
|
|
ls -la "$CLONE_DIR"
|
|
|
|
|
2020-08-10 08:02:28 -06:00
|
|
|
echo "Copying contents to to git repo"
|
2020-03-29 09:30:55 -06:00
|
|
|
cp -r "$FOLDER"/* "$CLONE_DIR"
|
2020-03-29 09:07:19 -06:00
|
|
|
cd "$CLONE_DIR"
|
2020-08-10 08:02:28 -06:00
|
|
|
ls -la
|
2020-03-29 09:07:19 -06:00
|
|
|
|
2020-08-10 08:02:28 -06:00
|
|
|
echo "Adding git commit"
|
2020-03-29 09:07:19 -06:00
|
|
|
git add .
|
2020-08-10 08:02:28 -06:00
|
|
|
git status
|
2020-07-28 20:32:30 -06:00
|
|
|
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
|
2020-08-10 08:02:28 -06:00
|
|
|
|
|
|
|
echo "Pushing git commit"
|
2020-09-23 01:49:12 -06:00
|
|
|
git push origin $TARGET_BRANCH
|