Przeglądaj źródła

Update the post-receive script to pass the previous revision to Coleslaw.

Brit Butler 11 lat temu
rodzic
commit
e17d2a27df
5 zmienionych plików z 24 dodań i 33 usunięć
  1. 1 1
      coleslaw.asd
  2. 0 15
      docs/hacking.md
  3. 14 9
      examples/example.post-receive
  4. 4 2
      src/coleslaw.lisp
  5. 5 6
      src/util.lisp

+ 1 - 1
coleslaw.asd

@@ -1,7 +1,7 @@
1 1
 (defsystem #:coleslaw
2 2
   :name "coleslaw"
3 3
   :description "Flexible Lisp Blogware"
4
-  :version "0.9.4-dev"
4
+  :version "0.9.4"
5 5
   :license "BSD"
6 6
   :author "Brit Butler <redline6561@gmail.com>"
7 7
   :pathname "src/"

+ 0 - 15
docs/hacking.md

@@ -240,20 +240,6 @@ avoiding work is better than using more workers. Moreover, being
240 240
 able to determine (and expose) what files just changed enables new
241 241
 functionality such as plugins that cross-post to tumblr.
242 242
 
243
-Git's post-receive hook is supposed to get a list of refs on $STDIN.
244
-A brave soul could update our post-receive script to iterate over
245
-those lines as shown in step 3 of this [blog post][post_receive_blog].
246
-There would be two primary benefits:
247
-
248
-1. We could pass the oldrev (previous revision) of the blog repo
249
-   to `coleslaw:main`. That could be used in conjunction with
250
-   `get-updated-files` to get a list of the files modified in the
251
-   last push. This would enable cross-posting plugins to be developed
252
-   as well as opening the door for incremental compilation.
253
-2. More seriously, **Coleslaw** currently deploys for _any_ branch
254
-   pushed to the bare repo. This change would also ensure that we only
255
-   invoke `coleslaw:main` when a push is made to the master branch.
256
-
257 243
 This is a cool project and the effects are far reaching. Among other
258 244
 things the existing deployment model would not work as it involves
259 245
 rebuilding the entire site. In all likelihood we would want to update
@@ -264,7 +250,6 @@ would have to be regenerated along with any tag or month indexes
264 250
 matching the modified files. If incremental compilation is a goal,
265 251
 simply disabling the indexes may be appropriate for certain users.
266 252
 
267
-[post_receive_blog]: http://codeshal.tumblr.com/post/927943180/git-post-receive-hook-that-submits-code-to-review-board
268 253
 [post_receive_hook]: https://github.com/redline6561/coleslaw/blob/master/examples/example.post-receive
269 254
 [closure_template]: https://github.com/archimag/cl-closure-template
270 255
 [api_docs]: https://github.com/redline6561/coleslaw/blob/master/docs/plugin-api.md

+ 14 - 9
examples/example.post-receive

@@ -20,15 +20,20 @@ fi
20 20
 
21 21
 git clone $GIT_REPO $TMP_GIT_CLONE || exit 1
22 22
 
23
-if [ $LISP = sbcl ]; then
24
-    sbcl --eval "(ql:quickload 'coleslaw)" \
25
-         --eval "(coleslaw:main \"$TMP_GIT_CLONE\")" \
26
-         --eval "(coleslaw::exit)"
27
-elif [ $LISP = ccl ]; then
28
-    echo "(ql:quickload 'coleslaw)(coleslaw:main \"$TMP_GIT_CLONE\")(coleslaw::exit)" | ccl -b
29
-else
30
-    exit 1
31
-fi
23
+while read oldrev newrev refname; do
24
+    if [ $refname = "refs/heads/master" ]; then
25
+        echo -e "\n  Master updated. Running coleslaw...\n"
26
+        if [ $LISP = sbcl ]; then
27
+            sbcl --eval "(ql:quickload 'coleslaw)" \
28
+                 --eval "(coleslaw:main \"$TMP_GIT_CLONE\" \"$oldrev\")" \
29
+                 --eval "(coleslaw::exit)"
30
+        elif [ $LISP = ccl ]; then
31
+            ccl -e "(ql:quickload 'coleslaw) (coleslaw:main \"$TMP_GIT_CLONE\" \"$oldrev\") (coleslaw::exit)"
32
+        else
33
+            exit 1
34
+        fi
35
+    fi
36
+done
32 37
 
33 38
 rm -rf $TMP_GIT_CLONE
34 39
 exit

+ 4 - 2
src/coleslaw.lisp

@@ -1,7 +1,9 @@
1 1
 (in-package :coleslaw)
2 2
 
3
-(defun main (&optional (repo-dir ""))
4
-  "Load the user's config file, then compile and deploy the site."
3
+(defun main (&optional (repo-dir "") oldrev)
4
+  "Load the user's config file, then compile and deploy the site. Optionally,
5
+REPO-DIR is the location of the blog repo and OLDREV is the revision prior to
6
+the last push."
5 7
   (load-config repo-dir)
6 8
   (load-content)
7 9
   (compile-theme (theme *config*))

+ 5 - 6
src/util.lisp

@@ -99,9 +99,8 @@ along with any missing parent directories otherwise."
99 99
 
100 100
 (defun get-updated-files (revision)
101 101
   "Return a plist of (file-status file-name) for files that were changed
102
-in git since REVISION."
103
-  (with-current-directory (repo *config*)
104
-    (flet ((split-on-whitespace (str)
105
-             (cl-ppcre:split "\\s+" str)))
106
-      (let ((cmd (format nil "git diff --name-status ~A HEAD" revision)))
107
-        (mapcar #'split-on-whitespace (inferior-shell:run/lines cmd))))))
102
+in the git repo since REVISION."
103
+  (flet ((split-on-whitespace (str)
104
+           (cl-ppcre:split "\\s+" str)))
105
+    (let ((cmd (format nil "git diff --name-status ~A HEAD" revision)))
106
+      (mapcar #'split-on-whitespace (inferior-shell:run/lines cmd)))))