Blame | Last modification | View Log | RSS feed
#!/usr/bin/env bash## mfpub## Use Jekyll to generate Marlin Documentation, which is then# git-pushed to Github to publish it to the live site.# This publishes the current branch, and doesn't force# changes to be pushed to the 'master' branch. Be sure to push# any permanent changes to 'master'.#[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }MFINFO=$(mfinfo "$@") || exit 1IFS=' ' read -a INFO <<< "$MFINFO"ORG=${INFO[0]}FORK=${INFO[1]}REPO=${INFO[2]}TARG=${INFO[3]}BRANCH=${INFO[4]}if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; thenecho "Wrong repository."exitfi# Check out the named branch (or stay in current)git checkout $BRANCHif [[ $BRANCH == "gh-pages" ]]; thenecho "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."exitfiecho "Stashing any changes to files..."echo "Don't forget to update and push 'master'!"# GOJF Card[[ $(git stash) != "No local "* ]] && HAS_STASH=1COMMIT=$( git log --format="%H" -n 1 )# Clean out changes and other junk in the branchgit clean -d -f# Push 'master' to the fork and make a proper PR...if [[ $BRANCH == "master" ]]; then# Don't lose upstream changes!git fetch upstream# Rebase onto latest masterif git rebase upstream/master; then# Allow working directly with the main forkechoecho -n "Pushing to origin/master... "git push -f originechoecho -n "Pushing to upstream/master... "git push -f upstreamelseecho "Merge conflicts? Stopping here."exitfielseif [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; thenfirstpushelseechoecho -n "Pushing to origin/$BRANCH... "git push -f originfiTOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"if [ -z "$TOOL" ]; thenecho "Can't find a tool to open the URL:"echo $URLelseecho "Opening a New PR Form...""$TOOL" "$URL"fifi# Uncomment to compress the final html files# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb# bundle installechoecho "Generating MarlinDocumentation..."# build the site statically and proof itbundle exec jekyll build --profile --trace --no-watchbundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"# Sync the built site into a temporary folderTMPFOLDER=$( mktemp -d )rsync -av _site/ ${TMPFOLDER}/# Clean out changes and other junk in the branchgit reset --hardgit clean -d -f# Copy built-site into the gh-pages branchgit checkout gh-pagesrsync -av ${TMPFOLDER}/ ./# Commit and push the new live site directlygit add --allgit commit --message "Built from ${COMMIT}"git push upstream# remove the temporary folderrm -rf ${TMPFOLDER}# Go back to the branch we started fromgit checkout $BRANCH[[ $HAS_STASH == 1 ]] && git stash pop