You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
3.2 KiB
Plaintext
139 lines
3.2 KiB
Plaintext
8 years ago
|
#!/usr/bin/env bash
|
||
|
#
|
||
|
# mfpub
|
||
|
#
|
||
8 years ago
|
# 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
|
||
5 years ago
|
# changes to be pushed to the 'master' branch. Be sure to
|
||
|
# push any permanent changes to 'master'.
|
||
8 years ago
|
#
|
||
|
|
||
5 years ago
|
[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
|
||
8 years ago
|
|
||
|
MFINFO=$(mfinfo "$@") || exit 1
|
||
8 years ago
|
IFS=' ' read -a INFO <<< "$MFINFO"
|
||
|
ORG=${INFO[0]}
|
||
|
FORK=${INFO[1]}
|
||
|
REPO=${INFO[2]}
|
||
|
TARG=${INFO[3]}
|
||
|
BRANCH=${INFO[4]}
|
||
5 years ago
|
CURR=${INFO[5]}
|
||
8 years ago
|
|
||
|
if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
|
||
|
echo "Wrong repository."
|
||
|
exit
|
||
|
fi
|
||
|
|
||
|
if [[ $BRANCH == "gh-pages" ]]; then
|
||
8 years ago
|
echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
|
||
8 years ago
|
exit
|
||
|
fi
|
||
|
|
||
6 years ago
|
# Check out the named branch (or stay in current)
|
||
|
|
||
5 years ago
|
if [[ $BRANCH != $CURR ]]; then
|
||
|
echo "Stashing any changes to files..."
|
||
|
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
|
||
5 years ago
|
git checkout $BRANCH
|
||
5 years ago
|
fi
|
||
8 years ago
|
|
||
|
COMMIT=$( git log --format="%H" -n 1 )
|
||
|
|
||
|
# Clean out changes and other junk in the branch
|
||
|
git clean -d -f
|
||
|
|
||
5 years ago
|
opensite() {
|
||
|
URL="$1"
|
||
|
OPEN=$(echo $(which gnome-open xdg-open open) | awk '{ print $1 }')
|
||
|
if [ -z "$OPEN" ]; then
|
||
|
echo "Can't find a tool to open the URL:"
|
||
|
echo $URL
|
||
|
else
|
||
|
echo "Opening the site in the browser..."
|
||
|
"$OPEN" "$URL"
|
||
|
fi
|
||
|
}
|
||
|
|
||
8 years ago
|
# Push 'master' to the fork and make a proper PR...
|
||
5 years ago
|
if [[ $BRANCH == $TARG ]]; then
|
||
8 years ago
|
|
||
7 years ago
|
# Don't lose upstream changes!
|
||
7 years ago
|
git fetch upstream
|
||
7 years ago
|
|
||
7 years ago
|
# Rebase onto latest master
|
||
5 years ago
|
if git rebase upstream/$TARG; then
|
||
8 years ago
|
|
||
7 years ago
|
# Allow working directly with the main fork
|
||
|
echo
|
||
5 years ago
|
echo -n "Pushing to origin/$TARG... "
|
||
7 years ago
|
git push -f origin
|
||
|
|
||
|
echo
|
||
5 years ago
|
echo -n "Pushing to upstream/$TARG... "
|
||
7 years ago
|
git push -f upstream
|
||
|
|
||
|
else
|
||
|
|
||
|
echo "Merge conflicts? Stopping here."
|
||
|
exit
|
||
|
|
||
|
fi
|
||
8 years ago
|
|
||
8 years ago
|
else
|
||
8 years ago
|
|
||
6 years ago
|
if [ -z "$(git branch -vv | grep ^\* | grep \\\[origin)" ]; then
|
||
8 years ago
|
firstpush
|
||
|
else
|
||
8 years ago
|
echo
|
||
8 years ago
|
echo -n "Pushing to origin/$BRANCH... "
|
||
8 years ago
|
git push -f origin
|
||
8 years ago
|
fi
|
||
8 years ago
|
|
||
5 years ago
|
opensite "https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
|
||
8 years ago
|
|
||
|
fi
|
||
|
|
||
|
# Uncomment to compress the final html files
|
||
|
# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
|
||
|
# bundle install
|
||
|
|
||
8 years ago
|
echo
|
||
8 years ago
|
echo "Generating MarlinDocumentation..."
|
||
|
|
||
5 years ago
|
rm -rf build
|
||
6 years ago
|
|
||
8 years ago
|
# build the site statically and proof it
|
||
8 years ago
|
bundle exec jekyll build --profile --trace --no-watch
|
||
5 years ago
|
bundle exec htmlproofer ./build --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
|
||
8 years ago
|
|
||
8 years ago
|
# Sync the built site into a temporary folder
|
||
|
TMPFOLDER=$( mktemp -d )
|
||
5 years ago
|
rsync -av build/ ${TMPFOLDER}/
|
||
8 years ago
|
|
||
|
# Clean out changes and other junk in the branch
|
||
|
git reset --hard
|
||
|
git clean -d -f
|
||
|
|
||
8 years ago
|
# Copy built-site into the gh-pages branch
|
||
6 years ago
|
git checkout gh-pages || { echo "Something went wrong!"; exit 1; }
|
||
8 years ago
|
rsync -av ${TMPFOLDER}/ ./
|
||
|
|
||
|
# Commit and push the new live site directly
|
||
|
git add --all
|
||
|
git commit --message "Built from ${COMMIT}"
|
||
5 years ago
|
git push -f origin
|
||
|
git push -f upstream | {
|
||
6 years ago
|
while IFS= read -r line
|
||
|
do
|
||
5 years ago
|
[[ $line =~ "gh-pages -> gh-pages" ]] && opensite "http://marlinfw.org/"
|
||
6 years ago
|
echo "$line"
|
||
|
done
|
||
|
}
|
||
8 years ago
|
|
||
8 years ago
|
# remove the temporary folder
|
||
8 years ago
|
rm -rf ${TMPFOLDER}
|
||
|
|
||
|
# Go back to the branch we started from
|
||
5 years ago
|
[[ $BRANCH != $CURR ]] && git checkout $BRANCH && [[ $HAS_STASH == 1 ]] && git stash pop
|