a simple approach using shell commands

This commit is contained in:
Masataro Asai 2019-10-27 18:01:02 -04:00
parent 21411d37d9
commit beb627c482
2 changed files with 87 additions and 0 deletions

View file

@ -1,6 +1,38 @@
(eval-when (:compile-toplevel :load-toplevel)
(ql:quickload 'puri :silent t))
(defpackage :coleslaw-gh-pages (defpackage :coleslaw-gh-pages
(:use :cl) (:use :cl)
(:import-from :coleslaw
#:*config*
#:domain
#:deploy
#:staging-dir
#:deploy-dir)
(:export #:enable)) (:export #:enable))
(in-package :coleslaw-gh-pages) (in-package :coleslaw-gh-pages)
(defvar *options* nil)
(defmethod deploy (staging)
(uiop:run-program (list* (namestring
(merge-pathnames "plugins/publish-gh-pages.sh"
coleslaw-conf:*basedir*))
(namestring
(merge-pathnames (staging-dir *config*)))
(namestring
(merge-pathnames (deploy-dir *config*)))
*options*)
:output t
:error-output t))
(defun enable (&key url (branch "gh-pages") (remote "origin") cname)
(check-type url string)
(check-type remote string)
(check-type branch string)
(if (eq t cname)
(progn
(setf cname (puri:uri-host (puri:parse-uri (domain *config*))))
(check-type cname string)
(setf *options* (list url branch remote cname)))
(setf *options* (list url branch remote))))

55
plugins/publish-gh-pages.sh Executable file
View file

@ -0,0 +1,55 @@
#!/bin/bash -x
set -e
staging=$1
deploy=$2
url=$3
branch=$4
remote=$5
cname=$6
if [[ -d $deploy && ! -d $deploy/.git ]]
then
echo "Target directory $deploy exists and is not a git repository. Aborting" >&2
exit 1
fi
if [[ ! -d $deploy ]]
then
git clone --no-checkout --origin $remote $url $deploy
fi
cd $deploy
# safe and most reliable way to check if the branch exist
if git show-ref --verify --quiet refs/heads/$branch
then
# if the branch exists locally
git checkout $branch
elif git show-ref --verify --quiet refs/remotes/$remote/$branch
then
# if the branch does not exist locally but exist in the specified remote ---
# Note, git checkout $branch will search the branch with the same name with
# ALL remotes, and set it as the tracking branch if there is a single such
# remote, but does not allow the user to necessarily specify which.
git checkout -b $branch --track $remote/$branch
else
# if there is no matching branch, make an orphan branch
git checkout --orphan $branch
fi
rsync -avz --delete --exclude .git/ --copy-links $staging $deploy
if [[ ! -z "$cname" ]]
then
echo $cname > CNAME
fi
git add -A # add all changes in the worktree
git add $(git ls-files -o ) # add all untracked files in the worktree
git commit -m "Deployed on $(date)"
git push $remote $branch