瀏覽代碼

Tentatively factor deploy method into git-hook plugin. TODO follows...

* Deploy :after plugins probably need revision now, and coleslaw-heroku.
* README, HACKING need updates. Plugin-api.md too.
* NEWS needs a carefully worded entry.

Is that what we want?
Brit Butler 11 年之前
父節點
當前提交
567c4473bb
共有 7 個文件被更改,包括 44 次插入27 次删除
  1. 8 5
      examples/example.coleslawrc
  2. 1 1
      examples/example.post-receive
  3. 22 0
      plugins/git-hook.lisp
  4. 8 17
      src/coleslaw.lisp
  5. 1 1
      src/config.lisp
  6. 3 2
      src/packages.lisp
  7. 1 1
      tests/tests.lisp

+ 8 - 5
examples/example.coleslawrc

@@ -2,12 +2,13 @@
2 2
  :deploy-dir "/home/git/blog/"
3 3
  :domain "http://blog.redlinernotes.com"
4 4
  :feeds ("lisp")
5
- :plugins ((mathjax)
6
-           (sitemap)
7
-           (static-pages)
5
+ :plugins ((analytics :tracking-code "foo")
8 6
            (disqus :shortname "my-site-name")
9
-           (analytics :tracking-code "foo"))
10
- :repo "/home/git/tmp/improvedmeans/"
7
+           ; (git-hook)     ;; *Remove comment to enable git push deploys.
8
+           ; (incremental)  ;; *Remove comment enable incremental builds.
9
+           (mathjax)
10
+           (sitemap)
11
+           (static-pages))
11 12
  :routing ((:post           "posts/~a")
12 13
            (:tag-index      "tag/~a")
13 14
            (:month-index    "date/~a")
@@ -22,3 +23,5 @@
22 23
  :staging-dir "/tmp/coleslaw/"
23 24
  :title "Improved Means for Achieving Deteriorated Ends"
24 25
  :theme "hyde")
26
+
27
+;; * Prerequisites described in plugin docs.

+ 1 - 1
examples/example.post-receive

@@ -1,6 +1,5 @@
1 1
 ########## CONFIGURATION VALUES ##########
2 2
 
3
-# TMP_GIT_CLONE _must_ match the :repo argument in your .coleslawrc!
4 3
 TMP_GIT_CLONE=$HOME/tmp/improvedmeans/
5 4
 
6 5
 # Set LISP to your preferred implementation. The following
@@ -30,6 +29,7 @@ while read oldrev newrev refname; do
30 29
         elif [ $LISP = ccl ]; then
31 30
             ccl -e "(ql:quickload 'coleslaw) (coleslaw:main \"$TMP_GIT_CLONE\" \"$oldrev\") (coleslaw::exit)"
32 31
         else
32
+            echo -e "$LISP is not a supported lisp dialect at this time. Exiting.\n"
33 33
             exit 1
34 34
         fi
35 35
     fi

+ 22 - 0
plugins/git-hook.lisp

@@ -0,0 +1,22 @@
1
+(defpackage :coleslaw-git-hook
2
+  (:use :cl)
3
+  (:import-from :coleslaw #:*config*
4
+                          #:deploy-dir
5
+                          #:rel-path
6
+                          #:run-program
7
+                          #:update-symlink))
8
+
9
+(in-package :coleslaw-git-hook)
10
+
11
+(defmethod coleslaw:deploy (staging)
12
+  (let* ((dest (deploy-dir *config*))
13
+         (new-build (rel-path dest "generated/~a" (get-universal-time)))
14
+         (prev (rel-path dest ".prev"))
15
+         (curr (rel-path dest ".curr")))
16
+    (ensure-directories-exist new-build)
17
+    (run-program "mv ~a ~a" staging new-build)
18
+    (when (and (probe-file prev) (truename prev))
19
+      (run-program "rm -r ~a" (truename prev)))
20
+    (when (probe-file curr)
21
+      (update-symlink prev (truename curr)))
22
+    (update-symlink curr new-build)))

+ 8 - 17
src/coleslaw.lisp

@@ -3,12 +3,12 @@
3 3
 (defvar *last-revision* nil
4 4
   "The git revision prior to the last push. For use with GET-UPDATED-FILES.")
5 5
 
6
-(defun main (&optional (repo-dir "") oldrev)
7
-  "Load the user's config file, then compile and deploy the site. Optionally,
8
-REPO-DIR is the location of the blog repo and OLDREV is the revision prior to
9
-the last push."
10
-  (setf *last-revision* oldrev)
6
+(defun main (repo-dir &optional oldrev)
7
+  "Load the user's config file, then compile and deploy the blog stored
8
+in REPO-DIR. Optionally, OLDREV is the revision prior to the last push."
11 9
   (load-config repo-dir)
10
+  (setf (repo *config*) repo-dir
11
+        *last-revision* oldrev)
12 12
   (load-content)
13 13
   (compile-theme (theme *config*))
14 14
   (let ((dir (staging-dir *config*)))
@@ -40,19 +40,10 @@ the last push."
40 40
     (update-symlink "index.html" "1.html")))
41 41
 
42 42
 (defgeneric deploy (staging)
43
-  (:documentation "Deploy the STAGING dir, updating the .prev and .curr symlinks.")
43
+  (:documentation "Deploy the STAGING build to the directory specified in the config.")
44 44
   (:method (staging)
45
-    (let* ((dest (deploy-dir *config*))
46
-           (new-build (rel-path dest "generated/~a" (get-universal-time)))
47
-           (prev (rel-path dest ".prev"))
48
-           (curr (rel-path dest ".curr")))
49
-      (ensure-directories-exist new-build)
50
-      (run-program "mv ~a ~a" staging new-build)
51
-      (when (and (probe-file prev) (truename prev))
52
-        (run-program "rm -r ~a" (truename prev)))
53
-      (when (probe-file curr)
54
-        (update-symlink prev (truename curr)))
55
-      (update-symlink curr new-build))))
45
+    (let ((destination (deploy-dir *config*)))
46
+      (run-program "rsync --delete -avz ~a ~a" staging destination))))
56 47
 
57 48
 (defun update-symlink (path target)
58 49
   "Update the symlink at PATH to point to TARGET."

+ 1 - 1
src/config.lisp

@@ -61,7 +61,7 @@ doesn't exist, use the .coleslawrc in the home directory."
61 61
         repo-config
62 62
         (rel-path (user-homedir-pathname) ".coleslawrc"))))
63 63
 
64
-(defun load-config (&optional repo-dir)
64
+(defun load-config (&optional (repo-dir ""))
65 65
   "Find and load the coleslaw configuration from .coleslawrc. REPO-DIR will be
66 66
 preferred over the home directory if provided."
67 67
   (with-open-file (in (discover-config-path repo-dir) :external-format '(:utf-8))

+ 3 - 2
src/packages.lisp

@@ -22,12 +22,13 @@
22 22
            #:title-of
23 23
            #:author-of
24 24
            #:find-content-by-path
25
-           ;; Plugin API + Theming
25
+           ;; Theming + Plugin API
26
+           #:theme-fn
26 27
            #:plugin-conf-error
27 28
            #:render-text
28 29
            #:add-injection
29 30
            #:get-updated-files
30
-           #:theme-fn
31
+           #:deploy
31 32
            ;; The Document Protocol
32 33
            #:discover
33 34
            #:publish

+ 1 - 1
tests/tests.lisp

@@ -10,4 +10,4 @@
10 10
 
11 11
 (deftest sanity-test
12 12
     "A blog should compile and deploy correctly."
13
-  (is (zerop (coleslaw:main))))
13
+  (is (zerop (coleslaw:main ""))))