Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
#!/usr/bin/env bash
2
#
3
# mfpub
4
#
5
# Use Jekyll to generate Marlin Documentation, which is then
6
# git-pushed to Github to publish it to the live site.
7
# This publishes the current branch, and doesn't force
8
# changes to be pushed to the 'master' branch. Be sure to push
9
# any permanent changes to 'master'.
10
#
11
 
12
[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
13
 
14
MFINFO=$(mfinfo "$@") || exit 1
15
IFS=' ' read -a INFO <<< "$MFINFO"
16
ORG=${INFO[0]}
17
FORK=${INFO[1]}
18
REPO=${INFO[2]}
19
TARG=${INFO[3]}
20
BRANCH=${INFO[4]}
21
 
22
if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
23
  echo "Wrong repository."
24
  exit
25
fi
26
 
27
# Check out the named branch (or stay in current)
28
git checkout $BRANCH
29
 
30
if [[ $BRANCH == "gh-pages" ]]; then
31
  echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
32
  exit
33
fi
34
 
35
echo "Stashing any changes to files..."
36
echo "Don't forget to update and push 'master'!"
37
# GOJF Card
38
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
39
 
40
COMMIT=$( git log --format="%H" -n 1 )
41
 
42
# Clean out changes and other junk in the branch
43
git clean -d -f
44
 
45
# Push 'master' to the fork and make a proper PR...
46
if [[ $BRANCH == "master" ]]; then
47
 
48
  # Don't lose upstream changes!
49
  git fetch upstream
50
 
51
  # Rebase onto latest master
52
  if git rebase upstream/master; then
53
 
54
    # Allow working directly with the main fork
55
    echo
56
    echo -n "Pushing to origin/master... "
57
    git push -f origin
58
 
59
    echo
60
    echo -n "Pushing to upstream/master... "
61
    git push -f upstream
62
 
63
  else
64
 
65
    echo "Merge conflicts? Stopping here."
66
    exit
67
 
68
  fi
69
 
70
else
71
 
72
  if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then
73
    firstpush
74
  else
75
    echo
76
    echo -n "Pushing to origin/$BRANCH... "
77
    git push -f origin
78
  fi
79
 
80
  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
81
  URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
82
 
83
  if [ -z "$TOOL" ]; then
84
    echo "Can't find a tool to open the URL:"
85
    echo $URL
86
  else
87
    echo "Opening a New PR Form..."
88
    "$TOOL" "$URL"
89
  fi
90
 
91
fi
92
 
93
# Uncomment to compress the final html files
94
# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
95
# bundle install
96
 
97
echo
98
echo "Generating MarlinDocumentation..."
99
 
100
# build the site statically and proof it
101
bundle exec jekyll build --profile --trace --no-watch
102
bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
103
 
104
# Sync the built site into a temporary folder
105
TMPFOLDER=$( mktemp -d )
106
rsync -av _site/ ${TMPFOLDER}/
107
 
108
# Clean out changes and other junk in the branch
109
git reset --hard
110
git clean -d -f
111
 
112
# Copy built-site into the gh-pages branch
113
git checkout gh-pages
114
rsync -av ${TMPFOLDER}/ ./
115
 
116
# Commit and push the new live site directly
117
git add --all
118
git commit --message "Built from ${COMMIT}"
119
git push upstream
120
 
121
# remove the temporary folder
122
rm -rf ${TMPFOLDER}
123
 
124
# Go back to the branch we started from
125
git checkout $BRANCH
126
 
127
[[ $HAS_STASH == 1 ]] && git stash pop