2017-04-21 04:28:54 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfpub
|
|
|
|
#
|
2017-05-05 07:46:39 +02: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'.
|
2017-04-21 04:28:54 +02:00
|
|
|
#
|
|
|
|
|
2019-01-24 06:05:42 +01:00
|
|
|
[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [branch]" 1>&2 ; exit 1; }
|
2017-07-03 03:43:57 +02:00
|
|
|
|
|
|
|
MFINFO=$(mfinfo "$@") || exit 1
|
2017-04-21 04:28:54 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
if [[ $BRANCH == "gh-pages" ]]; then
|
2017-05-05 07:46:39 +02:00
|
|
|
echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
|
2017-04-21 04:28:54 +02:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2018-09-20 06:56:35 +02:00
|
|
|
# Check out the named branch (or stay in current)
|
|
|
|
git checkout $BRANCH
|
|
|
|
|
2017-05-11 08:21:46 +02:00
|
|
|
echo "Stashing any changes to files..."
|
|
|
|
echo "Don't forget to update and push 'master'!"
|
|
|
|
# GOJF Card
|
2017-11-29 02:01:47 +01:00
|
|
|
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
|
2017-04-21 04:28:54 +02:00
|
|
|
|
|
|
|
COMMIT=$( git log --format="%H" -n 1 )
|
|
|
|
|
|
|
|
# Clean out changes and other junk in the branch
|
|
|
|
git clean -d -f
|
|
|
|
|
|
|
|
# Push 'master' to the fork and make a proper PR...
|
|
|
|
if [[ $BRANCH == "master" ]]; then
|
|
|
|
|
2017-10-30 00:31:27 +01:00
|
|
|
# Don't lose upstream changes!
|
2017-11-29 02:01:47 +01:00
|
|
|
git fetch upstream
|
2017-10-30 00:31:27 +01:00
|
|
|
|
2017-11-29 02:01:47 +01:00
|
|
|
# Rebase onto latest master
|
|
|
|
if git rebase upstream/master; then
|
2017-04-21 04:28:54 +02:00
|
|
|
|
2017-11-29 02:01:47 +01:00
|
|
|
# Allow working directly with the main fork
|
|
|
|
echo
|
|
|
|
echo -n "Pushing to origin/master... "
|
|
|
|
git push -f origin
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo -n "Pushing to upstream/master... "
|
|
|
|
git push -f upstream
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Merge conflicts? Stopping here."
|
|
|
|
exit
|
|
|
|
|
|
|
|
fi
|
2017-05-05 07:46:39 +02:00
|
|
|
|
2017-05-11 00:43:39 +02:00
|
|
|
else
|
2017-05-05 07:46:39 +02:00
|
|
|
|
2018-09-20 06:56:35 +02:00
|
|
|
if [ -z "$(git branch -vv | grep ^\* | grep \\\[origin)" ]; then
|
2017-05-11 00:43:39 +02:00
|
|
|
firstpush
|
|
|
|
else
|
2017-05-11 08:21:46 +02:00
|
|
|
echo
|
2017-05-11 00:43:39 +02:00
|
|
|
echo -n "Pushing to origin/$BRANCH... "
|
2017-05-05 07:46:39 +02:00
|
|
|
git push -f origin
|
2017-05-11 00:43:39 +02:00
|
|
|
fi
|
2017-05-05 07:46:39 +02:00
|
|
|
|
2019-10-02 05:03:59 +02:00
|
|
|
which xdg-open >/dev/null && TOOL=xdg-open
|
|
|
|
which gnome-open >/dev/null && TOOL=gnome-open
|
|
|
|
which open >/dev/null && TOOL=open
|
2017-05-11 00:43:39 +02:00
|
|
|
URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
|
2017-05-05 07:46:39 +02:00
|
|
|
|
2019-10-02 05:03:59 +02:00
|
|
|
if [ -z "$OPEN" ]; then
|
2017-05-11 00:43:39 +02:00
|
|
|
echo "Can't find a tool to open the URL:"
|
|
|
|
echo $URL
|
|
|
|
else
|
|
|
|
echo "Opening a New PR Form..."
|
2019-10-02 05:03:59 +02:00
|
|
|
"$OPEN" "$URL"
|
2017-04-21 04:28:54 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Uncomment to compress the final html files
|
|
|
|
# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
|
|
|
|
# bundle install
|
|
|
|
|
2017-05-11 08:21:46 +02:00
|
|
|
echo
|
2017-05-11 00:43:39 +02:00
|
|
|
echo "Generating MarlinDocumentation..."
|
|
|
|
|
2019-12-29 00:45:10 +01:00
|
|
|
rm -rf build
|
2018-11-13 02:51:57 +01:00
|
|
|
|
2017-05-05 07:46:39 +02:00
|
|
|
# build the site statically and proof it
|
2017-04-21 04:28:54 +02:00
|
|
|
bundle exec jekyll build --profile --trace --no-watch
|
2019-12-29 00:45:10 +01:00
|
|
|
bundle exec htmlproofer ./build --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
|
2017-04-21 04:28:54 +02:00
|
|
|
|
2017-05-05 07:46:39 +02:00
|
|
|
# Sync the built site into a temporary folder
|
|
|
|
TMPFOLDER=$( mktemp -d )
|
2019-12-29 00:45:10 +01:00
|
|
|
rsync -av build/ ${TMPFOLDER}/
|
2017-04-21 04:28:54 +02:00
|
|
|
|
|
|
|
# Clean out changes and other junk in the branch
|
|
|
|
git reset --hard
|
|
|
|
git clean -d -f
|
|
|
|
|
2017-05-11 00:43:39 +02:00
|
|
|
# Copy built-site into the gh-pages branch
|
2018-11-10 08:31:22 +01:00
|
|
|
git checkout gh-pages || { echo "Something went wrong!"; exit 1; }
|
2017-04-21 04:28:54 +02:00
|
|
|
rsync -av ${TMPFOLDER}/ ./
|
|
|
|
|
2018-12-06 01:56:52 +01:00
|
|
|
opensite() {
|
2019-10-02 05:03:59 +02:00
|
|
|
which xdg-open >/dev/null && TOOL=xdg-open
|
|
|
|
which gnome-open >/dev/null && TOOL=gnome-open
|
|
|
|
which open >/dev/null && TOOL=open
|
2018-12-06 01:56:52 +01:00
|
|
|
URL="http://marlinfw.org/"
|
2019-10-02 05:03:59 +02:00
|
|
|
if [ -z "$OPEN" ]; then
|
2018-12-06 01:56:52 +01:00
|
|
|
echo "Can't find a tool to open the URL:"
|
|
|
|
echo $URL
|
|
|
|
else
|
|
|
|
echo "Opening the site in the browser..."
|
2019-10-02 05:03:59 +02:00
|
|
|
"$OPEN" "$URL"
|
2018-12-06 01:56:52 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-04-21 04:28:54 +02:00
|
|
|
# Commit and push the new live site directly
|
|
|
|
git add --all
|
|
|
|
git commit --message "Built from ${COMMIT}"
|
2018-12-06 01:56:52 +01:00
|
|
|
git push upstream | {
|
|
|
|
while IFS= read -r line
|
|
|
|
do
|
|
|
|
[[ $line =~ "gh-pages -> gh-pages" ]] && opensite
|
|
|
|
echo "$line"
|
|
|
|
done
|
|
|
|
}
|
2017-04-21 04:28:54 +02:00
|
|
|
|
2017-05-05 07:46:39 +02:00
|
|
|
# remove the temporary folder
|
2017-04-21 04:28:54 +02:00
|
|
|
rm -rf ${TMPFOLDER}
|
|
|
|
|
|
|
|
# Go back to the branch we started from
|
|
|
|
git checkout $BRANCH
|
2017-05-11 00:43:39 +02:00
|
|
|
|
2017-11-29 02:01:47 +01:00
|
|
|
[[ $HAS_STASH == 1 ]] && git stash pop
|