Marlin/buildroot/share/git/mfpub

139 lines
3.2 KiB
Plaintext
Raw Normal View History

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