Marlin/buildroot/share/git/mfpub

114 lines
2.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
#
# mfpub
#
2017-05-05 01:46:39 -04:00
# 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'.
#
MFINFO=$(mfinfo "$@") || exit
IFS=' ' read -a INFO <<< "$MFINFO"
ORG=${INFO[0]}
FORK=${INFO[1]}
REPO=${INFO[2]}
TARG=${INFO[3]}
BRANCH=${INFO[4]}
if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
echo "Wrong repository."
exit
fi
2017-05-10 18:43:39 -04:00
# Check out the named branch (or stay in current)
git checkout $BRANCH
if [[ $BRANCH == "gh-pages" ]]; then
2017-05-05 01:46:39 -04:00
echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
exit
fi
if [[ $BRANCH != "master" ]]; then
2017-05-10 18:43:39 -04:00
echo "Stashing any changes to files..."
echo "Don't forget to update and push 'master'!"
2017-05-05 01:46:39 -04:00
# GOJF Card
git stash
fi
COMMIT=$( git log --format="%H" -n 1 )
# Clean out changes and other junk in the branch
git reset --hard
git clean -d -f
# Push 'master' to the fork and make a proper PR...
if [[ $BRANCH == "master" ]]; then
2017-05-10 18:43:39 -04:00
# Allow working directly with the main fork
echo -n "Pushing to origin/master... "
git push -f origin
2017-05-10 18:43:39 -04:00
echo -n "Pushing to upstream/master... "
git push -f upstream
2017-05-05 01:46:39 -04:00
2017-05-10 18:43:39 -04:00
else
2017-05-05 01:46:39 -04:00
2017-05-10 18:43:39 -04:00
if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then
firstpush
else
echo -n "Pushing to origin/$BRANCH... "
2017-05-05 01:46:39 -04:00
git push -f origin
2017-05-10 18:43:39 -04:00
fi
2017-05-05 01:46:39 -04:00
2017-05-10 18:43:39 -04:00
TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
2017-05-05 01:46:39 -04:00
2017-05-10 18:43:39 -04:00
if [ -z "$TOOL" ]; then
echo "Can't find a tool to open the URL:"
echo $URL
else
echo "Opening a New PR Form..."
"$TOOL" "$URL"
fi
fi
# Uncomment to compress the final html files
# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
# bundle install
2017-05-10 18:43:39 -04:00
echo "Generating MarlinDocumentation..."
2017-05-05 01:46:39 -04:00
# build the site statically and proof it
bundle exec jekyll build --profile --trace --no-watch
bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
2017-05-05 01:46:39 -04:00
# Sync the built site into a temporary folder
TMPFOLDER=$( mktemp -d )
rsync -av _site/ ${TMPFOLDER}/
# Clean out changes and other junk in the branch
git reset --hard
git clean -d -f
2017-05-10 18:43:39 -04:00
# Copy built-site into the gh-pages branch
git checkout gh-pages
rsync -av ${TMPFOLDER}/ ./
# Commit and push the new live site directly
git add --all
git commit --message "Built from ${COMMIT}"
git push upstream
2017-05-05 01:46:39 -04:00
# remove the temporary folder
rm -rf ${TMPFOLDER}
# Go back to the branch we started from
git checkout $BRANCH
2017-05-10 18:43:39 -04:00
if [[ $BRANCH != "master" ]]; then
git stash pop
fi