Skip to content

Instantly share code, notes, and snippets.

@hu553in
Last active May 1, 2024 11:02
Show Gist options
  • Save hu553in/52525e99b3c0655a210f2da446be2b1f to your computer and use it in GitHub Desktop.
Save hu553in/52525e99b3c0655a210f2da446be2b1f to your computer and use it in GitHub Desktop.
Bash script for easy deployment of ./build directory to GitHub Pages
#!/bin/bash
GREEN_COLOR="\033[0;32m"
NO_COLOR="\033[0m"
# variables below must be initialized in order to make script working
GITHUB_USERNAME=""
GITHUB_PAGES_REPO=""
START_DIR=$(pwd)
TEMP_DIR=$(mktemp -d)
printf "${GREEN_COLOR}Copying build to ${TEMP_DIR}...${NO_COLOR}\n"
cp -r ./build $TEMP_DIR/
printf "${GREEN_COLOR}Going to ${TEMP_DIR}...${NO_COLOR}\n"
cd $TEMP_DIR
printf "${GREEN_COLOR}Cloning ${GITHUB_USERNAME}/${GITHUB_PAGES_REPO}...${NO_COLOR}\n"
git clone [email protected]:$GITHUB_USERNAME/$GITHUB_PAGES_REPO.git
printf "${GREEN_COLOR}Going to ${GITHUB_PAGES_REPO}...${NO_COLOR}\n"
cd $GITHUB_PAGES_REPO
printf "${GREEN_COLOR}Cleaning repo...${NO_COLOR}\n"
find * -maxdepth 0 -name '.git' -prune -o -exec rm -rf '{}' ';'
printf "${GREEN_COLOR}Copying build contents to ${GITHUB_PAGES_REPO}...${NO_COLOR}\n"
cp ../build/* .
printf "${GREEN_COLOR}Adding files to repo index...${NO_COLOR}\n"
git add .
printf "${GREEN_COLOR}Commiting changes...${NO_COLOR}\n"
git commit -m "$(date)"
printf "${GREEN_COLOR}Pushing changes to remote...${NO_COLOR}\n"
git push origin master
printf "${GREEN_COLOR}Going to ${START_DIR}...${NO_COLOR}\n"
cd $START_DIR
printf "${GREEN_COLOR}Removing ${TEMP_DIR}...${NO_COLOR}\n"
rm -rf $TEMP_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment