Update: enterypoint.sh

This commit is contained in:
Eliminater74 2021-08-20 19:23:03 -04:00
parent 12ff072138
commit 67a3a057c8
No known key found for this signature in database
GPG Key ID: 2DB13AFD9AF1A53C

View File

@ -26,7 +26,7 @@ fi
CLONE_DIR=$(mktemp -d) CLONE_DIR=$(mktemp -d)
echo "Cloning destination git repository" 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"
@ -39,18 +39,14 @@ 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"
echo "[+] Deleting files from $DESTINATION_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME"
# Remove contents of target directory and create a new empty one # Remove contents of target directory and create a new empty one
rm -R "$CLONE_DIR/$TARGET_DIRECTORY/" rm -R "$CLONE_DIR/$TARGET_DIRECTORY/"
mkdir "$CLONE_DIR/$TARGET_DIRECTORY" echo "[+] Creating $TARGET_DIRECTORY if doesnt already exist"
mkdir -p "$CLONE_DIR/$TARGET_DIRECTORY"
mv "$TEMP_DIR/.git" "$CLONE_DIR/.git" mv "$TEMP_DIR/.git" "$CLONE_DIR/.git"
#echo "[+] Deleting files from $DESTINATION_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME"
#rm -rfv "$CLONE_DIR/$DESTINATION_DIRECTORY"/*
#echo "[+] Veryfing that the directory that will be pushed is EMPTY"
#ls -la "$CLONE_DIR/$DESTINATION_DIRECTORY"
if [ ! -d "$SOURCE_DIRECTORY" ] if [ ! -d "$SOURCE_DIRECTORY" ]
then then
echo "ERROR: $SOURCE_DIRECTORY does not exist" echo "ERROR: $SOURCE_DIRECTORY does not exist"
@ -66,27 +62,28 @@ then
exit 1 exit 1
fi fi
echo "[+] Copying contents of source repository folder $SOURCE_DIRECTORY to folder $DESTINATION_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME"
echo "Copy contents to target git repository" echo "Copy contents to target git repository"
cp -ra "$SOURCE_DIRECTORY"/. "$CLONE_DIR/$TARGET_DIRECTORY" cp -ra "$SOURCE_DIRECTORY"/. "$CLONE_DIR/$TARGET_DIRECTORY"
cd "$CLONE_DIR" cd "$CLONE_DIR"
echo "Files that will be pushed:" echo "[+] Files that will be pushed"
ls -la ls -la
ORIGIN_COMMIT="https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" ORIGIN_COMMIT="https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
COMMIT_MESSAGE="${COMMIT_MESSAGE/ORIGIN_COMMIT/$ORIGIN_COMMIT}" COMMIT_MESSAGE="${COMMIT_MESSAGE/ORIGIN_COMMIT/$ORIGIN_COMMIT}"
COMMIT_MESSAGE="${COMMIT_MESSAGE/\$GITHUB_REF/$GITHUB_REF}" COMMIT_MESSAGE="${COMMIT_MESSAGE/\$GITHUB_REF/$GITHUB_REF}"
echo "git add:" echo "[+] Adding git commit"
git add . git add .
echo "git status:" echo "[+] git status:"
git status git status
echo "git diff-index:" echo "[+] git diff-index:"
# git diff-index : to avoid doing the git commit failing if there are no changes to be commit # git diff-index : to avoid doing the git commit failing if there are no changes to be commit
git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE" git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE"
echo "git push origin:" echo "[+] Pushing git commit"
# --set-upstream: sets de branch when pushing to a branch that does not exist # --set-upstream: sets de branch when pushing to a branch that does not exist
git push "https://$USER_NAME:$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" --set-upstream "$TARGET_BRANCH" git push "https://$USER_NAME:$API_TOKEN_GITHUB@github.com/$DESTINATION_REPOSITORY_USERNAME/$DESTINATION_REPOSITORY_NAME.git" --set-upstream "$TARGET_BRANCH"