github-action-push-to-anoth.../entrypoint.sh
2020-08-10 08:31:08 -05:00

36 lines
800 B
Bash
Executable File

#!/bin/sh -l
echo "Starts"
FOLDER="$1"
GITHUB_USERNAME="$2"
GITHUB_REPO="$3"
USER_EMAIL="$4"
REPO_USERNAME="$5"
if [ -z "$REPO_USERNAME" ]
then
REPO_USERNAME=$GITHUB_USERNAME
fi
CLONE_DIR=$(mktemp -d)
# Setup git
git config --global user.email "$USER_EMAIL"
git config --global user.name "$GITHUB_USERNAME"
git clone "https://$API_TOKEN_GITHUB@github.com/$REPO_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR"
ls -la "$CLONE_DIR"
# 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"
cp -r "$FOLDER"/* "$CLONE_DIR"
cd "$CLONE_DIR"
git add .
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
git push origin master