From dd30bd4252b0f199d2c55df861ea95a1acaf0403 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 22 Sep 2019 15:32:18 +0800 Subject: git: Rework the post-preceive hook for cgit-static repo --- roles/git/tasks/main.yml | 31 ++++++++++++++----------------- roles/git/templates/cgit-static-deploy.j2 | 31 +++++++++++++++++++++++++++++++ roles/git/templates/cgit/post-receive.j2 | 31 ------------------------------- 3 files changed, 45 insertions(+), 48 deletions(-) create mode 100644 roles/git/templates/cgit-static-deploy.j2 delete mode 100644 roles/git/templates/cgit/post-receive.j2 (limited to 'roles') diff --git a/roles/git/tasks/main.yml b/roles/git/tasks/main.yml index 6bec804..2dad95b 100644 --- a/roles/git/tasks/main.yml +++ b/roles/git/tasks/main.yml @@ -150,23 +150,6 @@ dest: "{{ git.cgit.root }}/syntax-highlighting.sh" mode: 0755 -- name: cgit - create static repo - become_user: "{{ git.user.name }}" - command: > - ./git-shell-commands/create - {{ git.cgit.static_repo }} - "cgit static resources repo" - args: - chdir: "{{ git.user.home }}" - creates: "{{ git.user.home }}/{{ git.cgit.static_repo }}" - -- name: cgit - add post-receive hook to the static repo - template: - src: cgit/post-receive.j2 - dest: "{{ git.user.home }}/{{ git.cgit.static_repo }}/hooks/post-receive" - owner: "{{ git.user.name }}" - mode: 0755 - - name: uwsgi - setup cgit blockinfile: path: /etc/rc.conf @@ -186,3 +169,17 @@ service: name: uwsgi state: restarted + +- name: (local) cgit - generate deploy hook for cgit-static repo + become: false + template: + src: cgit-static-deploy.j2 + dest: "{{ playbook_dir }}/gitolite-admin/local/hooks/repo-specific/cgit-static-deploy" + mode: 0755 + delegate_to: localhost + +- debug: + msg: + - "NOTE:" + - "Need to set the post-preceive hook for 'cgit-static' repo:" + - "gitolite-admin/local/hooks/repo-specific/cgit-static-deploy" diff --git a/roles/git/templates/cgit-static-deploy.j2 b/roles/git/templates/cgit-static-deploy.j2 new file mode 100644 index 0000000..14b455a --- /dev/null +++ b/roles/git/templates/cgit-static-deploy.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 diff --git a/roles/git/templates/cgit/post-receive.j2 b/roles/git/templates/cgit/post-receive.j2 deleted file mode 100644 index 14b455a..0000000 --- a/roles/git/templates/cgit/post-receive.j2 +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 -- cgit v1.2.2