deploy-ghpages.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. # ideas used from https://gist.github.com/motemen/8595451
  3. # abort the script if there is a non-zero error
  4. set -e
  5. # show where we are on the machine
  6. pwd
  7. remote=$(git config remote.origin.url)
  8. siteSource="$1"
  9. if [ ! -d "$siteSource" ]
  10. then
  11. echo "Usage: $0 <site source dir>"
  12. exit 1
  13. fi
  14. # make a directory to put the gp-pages branch
  15. mkdir gh-pages-branch
  16. cd gh-pages-branch
  17. # now lets setup a new repo so we can update the gh-pages branch
  18. git config --global user.email "$GH_EMAIL" > /dev/null 2>&1
  19. git config --global user.name "$GH_NAME" > /dev/null 2>&1
  20. git init
  21. git remote add --fetch origin "$remote"
  22. # switch into the the gh-pages branch
  23. if git rev-parse --verify origin/gh-pages > /dev/null 2>&1
  24. then
  25. git checkout gh-pages
  26. # delete any old site as we are going to replace it
  27. # Note: this explodes if there aren't any, so moving it here for now
  28. git rm -rf .
  29. else
  30. git checkout --orphan gh-pages
  31. fi
  32. # copy over or recompile the new site
  33. cp -a "../${siteSource}/." .
  34. # stage any changes and new files
  35. git add -A
  36. # now commit, ignoring branch gh-pages doesn't seem to work, so trying skip
  37. git commit --allow-empty -m "Deploy to GitHub pages [ci skip]"
  38. # and push, but send any output to /dev/null to hide anything sensitive
  39. git push --force --quiet origin gh-pages
  40. # go back to where we started and remove the gh-pages git repo we made and used
  41. # for deployment
  42. cd ..
  43. rm -rf gh-pages-branch
  44. echo "Finished Deployment!"