aboutsummaryrefslogtreecommitdiffstats
path: root/roles/git/templates/cgit/post-receive.j2
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-04-18 16:41:27 +0800
committerAaron LI <aly@aaronly.me>2018-04-18 16:44:09 +0800
commit053cd1b7fe10f746792e0d1353fad4ad04e8ebe9 (patch)
tree93137af7af0b073383e0db5ae91cbe301f9bcdd1 /roles/git/templates/cgit/post-receive.j2
parentf448bcbdf07cf988ab50950df95d822f359041db (diff)
downloadansible-dfly-vps-053cd1b7fe10f746792e0d1353fad4ad04e8ebe9.tar.bz2
Add git role: host git repos and share repos via cgit
* Host git repositories * Share git repositories through web interface via cgit * The static resources used by cgit is also managed/deployed by a git repo ^_^
Diffstat (limited to 'roles/git/templates/cgit/post-receive.j2')
-rw-r--r--roles/git/templates/cgit/post-receive.j231
1 files changed, 31 insertions, 0 deletions
diff --git a/roles/git/templates/cgit/post-receive.j2 b/roles/git/templates/cgit/post-receive.j2
new file mode 100644
index 0000000..14b455a
--- /dev/null
+++ b/roles/git/templates/cgit/post-receive.j2
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# post-receive hook for the cgit-static.git repo to checkout the
+# resources upon push, a.k.a., deploy on push.
+#
+# Aaron LI
+# 2018-04-18
+#
+
+GIT_DIR="{{ git.user.home }}/{{ git.cgit.static_repo }}/"
+TARGET="{{ git.cgit.root }}/static/"
+TARGET_BRANCH="master"
+
+while read oldrev newrev refname; do
+ branch=$(git rev-parse --symbolic --abbrev-ref ${refname})
+ if [ -n "${branch}" ] && [ "${branch}" = "${TARGET_BRANCH}" ]; then
+ echo "Deploying cgit static resources ..."
+ git --work-tree=${TARGET} --git-dir=${GIT_DIR} \
+ checkout ${TARGET_BRANCH} -f
+
+ NOW=$(date +"%Y%m%d-%H%M")
+ git tag release_${NOW} ${TARGET_BRANCH}
+
+ echo " +==============================="
+ echo " | DEPLOYMENT COMPLETED"
+ echo " | Target branch: ${TARGET_BRANCH}"
+ echo " | Target folder: ${TARGET}"
+ echo " | Tag name : release_${NOW}"
+ echo " +==============================="
+ fi
+done