Browse Source

Add 'mfdoc' and 'mfpub' scripts to help with documentation

Scott Lahteine 7 years ago
parent
commit
dd436ceeb7
3 changed files with 141 additions and 2 deletions
  1. 48
    0
      buildroot/share/git/mfdoc
  2. 3
    2
      buildroot/share/git/mfinfo
  3. 90
    0
      buildroot/share/git/mfpub

+ 48
- 0
buildroot/share/git/mfdoc View File

@@ -0,0 +1,48 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfdoc
4
+#
5
+# Start Jekyll in watch mode to work on Marlin Documentation and preview locally
6
+#
7
+
8
+MFINFO=$(mfinfo "$@") || exit
9
+IFS=' ' read -a INFO <<< "$MFINFO"
10
+ORG=${INFO[0]}
11
+REPO=${INFO[2]}
12
+BRANCH=${INFO[4]}
13
+
14
+if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
15
+  echo "Wrong repository."
16
+  exit
17
+fi
18
+
19
+if [[ $BRANCH != "master" ]]; then
20
+  echo "Stashing changes and changing to master."
21
+  git stash
22
+  git checkout master
23
+fi
24
+
25
+opensite() {
26
+  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
27
+  URL="http://127.0.0.1:4000/"
28
+  if [ -z "$TOOL" ]; then
29
+    echo "Can't find a tool to open the URL:"
30
+    echo $URL
31
+  else
32
+    echo "Opening preview site in the browser..."
33
+    "$TOOL" "$URL"
34
+  fi
35
+}
36
+
37
+echo "Previewing MarlinDocumentation..."
38
+
39
+# wait to open the url for about 8s
40
+( sleep 8; opensite ) &
41
+
42
+bundle exec jekyll serve --watch --incremental
43
+
44
+if [[ $BRANCH != "master" ]]; then
45
+  echo "Restoring branch '$BRANCH'"
46
+  git checkout $BRANCH
47
+  git stash pop
48
+fi

+ 3
- 2
buildroot/share/git/mfinfo View File

@@ -25,8 +25,9 @@ if [[ $ORG != MarlinFirmware ]]; then
25 25
 fi
26 26
 
27 27
 case "$REPO" in
28
-  Marlin    ) TARG=RCBugFix ;;
29
-  MarlinDev ) TARG=dev ;;
28
+  Marlin              ) TARG=RCBugFix ;;
29
+  MarlinDev           ) TARG=dev ;;
30
+  MarlinDocumentation ) TARG=master ;;
30 31
 esac
31 32
 
32 33
 FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')

+ 90
- 0
buildroot/share/git/mfpub View File

@@ -0,0 +1,90 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfpub
4
+#
5
+# Use Jekyll to publish Marlin Documentation to the HTML site
6
+#
7
+
8
+MFINFO=$(mfinfo "$@") || exit
9
+IFS=' ' read -a INFO <<< "$MFINFO"
10
+ORG=${INFO[0]}
11
+FORK=${INFO[1]}
12
+REPO=${INFO[2]}
13
+TARG=${INFO[3]}
14
+BRANCH=${INFO[4]}
15
+
16
+if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
17
+  echo "Wrong repository."
18
+  exit
19
+fi
20
+
21
+if [[ $BRANCH == "gh-pages" ]]; then
22
+  echo "Can't build from 'gh-pages.' Only the Jekyll branches."
23
+  bundle exec jekyll serve --watch
24
+  exit
25
+fi
26
+
27
+if [[ $BRANCH != "master" ]]; then
28
+  echo "Don't forget to update and push 'master'!"
29
+fi
30
+
31
+git checkout $BRANCH
32
+
33
+echo "Generating MarlinDocumentation..."
34
+
35
+# GOJF Card
36
+git stash
37
+
38
+TMPFOLDER=$( mktemp -d )
39
+COMMIT=$( git log --format="%H" -n 1 )
40
+
41
+# Clean out changes and other junk in the branch
42
+git reset --hard
43
+git clean -d -f
44
+
45
+# Push 'master' to the fork and make a proper PR...
46
+if [[ $BRANCH == "master" ]]; then
47
+
48
+  if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
49
+
50
+  git push -f origin
51
+
52
+  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
53
+  URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
54
+
55
+  if [ -z "$TOOL" ]; then
56
+    echo "Can't find a tool to open the URL:"
57
+    echo $URL
58
+  else
59
+    echo "Opening a New PR Form..."
60
+    "$TOOL" "$URL"
61
+  fi
62
+
63
+fi
64
+
65
+# Uncomment to compress the final html files
66
+# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
67
+# bundle install
68
+
69
+bundle exec jekyll build --profile --trace --no-watch
70
+bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
71
+
72
+rsync -av _site/ ${TMPFOLDER}/
73
+
74
+# Clean out changes and other junk in the branch
75
+git reset --hard
76
+git clean -d -f
77
+
78
+# Sync built-site with gh-pages
79
+git checkout gh-pages
80
+rsync -av ${TMPFOLDER}/ ./
81
+
82
+# Commit and push the new live site directly
83
+git add --all
84
+git commit --message "Built from ${COMMIT}"
85
+git push upstream
86
+
87
+rm -rf ${TMPFOLDER}
88
+
89
+# Go back to the branch we started from
90
+git checkout $BRANCH

Loading…
Cancel
Save