Last active
August 1, 2016 03:38
-
-
Save DanielHeath/7fc3ab34791eee47b1a1d87fee311a01 to your computer and use it in GitHub Desktop.
Deploying to github pages, from e.g. a webpack static site generator [OSX/LINUX]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o pipefail # If you pipe one command into another, fail the whole lot if any fail | |
set -e # fail if there are any errors in the script | |
set -u # fail if you use an uninitialized variable | |
# Warn about the dire consequences of this action | |
read -r -p "THIS WILL WIPE OUT ANY UNCOMMITTED CHANGES - control-c to stop" yn | |
HEAD=$(git rev-parse HEAD) # Save where you're up to | |
git reset --hard "$HEAD" # Avoid using uncommitted changes to build the site | |
BUILD_DIR=$(mktemp -d) # Create a directory to build into (your webpack config or similar will need to read this env var) | |
GIT_WORK_TREE="$BUILD_DIR" # Tell git where to find the built site | |
export BUILD_DIR # Make BUILD_DIR available to your build script | |
export GIT_WORK_TREE # Make GIT_WORK_TREE available to git | |
npm run build # Replace this with your build script | |
git add -A "$BUILD_DIR" # Add your changes | |
git commit -m "Build for $HEAD" # Commit your changes | |
git push -f origin HEAD:gh-pages # Push your built site to gh-pages | |
git reset --hard "$HEAD" # Return to the original commit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Dan!