push_gh_pages.sh
1 #!/bin/sh 2 3 set -e 4 5 if [ -z "$GH_TOKEN" ] || [ -z "$GH_MAIL" ] || [ -z "$GH_NAME" ] || [ -z "$DOCS_DIR" ] || [ -z "$BUILD_DIR" ]; then 6 echo "Environment configuration missing, exiting... " 7 exit 1 8 fi 9 10 TEMP_DIR="temp_$GITHUB_SHA" 11 REPO=$GITHUB_REPOSITORY 12 HTML_DIR="$BUILD_DIR/html/" 13 14 # Disable Safe Repository checks 15 git config --global --add safe.directory "/github/workspace" 16 git config --global --add safe.directory "/github/workspace/$TEMP_DIR" 17 18 # Clone repo with gh-pages branch 19 echo "Cloning gh-pages..." 20 git clone --branch gh-pages https://$GH_NAME:$GH_TOKEN@github.com/$REPO.git $TEMP_DIR 21 22 # Get commit message 23 message=$(git log -1 --format=%B) 24 echo "Message:" 25 echo $message 26 27 # Copy HTML files 28 echo "Copying files to gh-pages" 29 rsync -av $HTML_DIR $TEMP_DIR --exclude .git 30 31 # Set up credentials for Github Pages 32 cd $TEMP_DIR 33 git config user.name $GH_NAME 34 git config user.email $GH_MAIL 35 36 # Push to Github Pages 37 echo "Pushing to gh-pages" 38 git add . 39 git commit -m "$message" 40 git push origin gh-pages