You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2016/03/13 06:00:55 UTC
[3/4] accumulo git commit: Attach post-commit hook
Attach post-commit hook
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3afd48d9
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3afd48d9
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3afd48d9
Branch: refs/heads/gh-pages
Commit: 3afd48d9bb4db2dd8376b8ce6693a71c1e054174
Parents: b4c3d44
Author: Christopher Tubbs <ct...@apache.org>
Authored: Sat Mar 12 23:54:56 2016 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Sat Mar 12 23:54:56 2016 -0500
----------------------------------------------------------------------
_devtools/git-hooks/post-commit | 63 ++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/3afd48d9/_devtools/git-hooks/post-commit
----------------------------------------------------------------------
diff --git a/_devtools/git-hooks/post-commit b/_devtools/git-hooks/post-commit
new file mode 100755
index 0000000..5546aed
--- /dev/null
+++ b/_devtools/git-hooks/post-commit
@@ -0,0 +1,63 @@
+#! /usr/bin/env bash
+
+build_jekyll_site() {
+ # $1 is the expected source branch
+ local source_br; source_br=$1
+ # $2 is the name of the target branch
+ local tgt_br; tgt_br=$2
+ # $3 jekyll config file to build
+ local config; config=$3
+
+ local cur_branch; cur_branch=$(git rev-parse --symbolic-full-name HEAD) || return 1
+
+ # skip execution on other branches
+ [[ $cur_branch == "refs/heads/$source_br" ]] || return 0
+
+ # create message
+ local message; message="Jekyll build from $source_br:$(git rev-parse --verify 'HEAD^{commit}' | cut -c1-7)"$'\n'$'\n'"$(git cat-file commit HEAD | sed '1,/^$/d')"
+
+ # import git utils: needed for die, require_clean_work_tree
+ . "$(git --exec-path)/git-sh-setup" || return 1
+
+ # ensure target branch exists
+ local target_branch; target_branch=$(git rev-parse --symbolic-full-name "$tgt_br" 2>/dev/null) || die "fatal: $tgt_br is not a branch"
+ case "$target_branch" in
+ refs/heads/*)
+ true
+ ;;
+ *)
+ die "fatal: $tgt_br is not a branch"
+ ;;
+ esac
+
+ # don't build what's not checked in
+ require_clean_work_tree
+
+ # check that jekyll config file exists
+ [[ -f $config ]] || die "fatal: $config is not a file or does not exist"
+
+ # build using jekyll 3
+ local regex
+ regex='^jekyll 3[.](0[.][3-9][0-9]*|0[.][1-2][0-9]+|[1-9][0-9]*[.][0-9]+)'
+ local jekyll
+ jekyll=$(jekyll -v 2>/dev/null)
+ [[ $jekyll =~ $regex ]] || die "fatal: requires jekyll >= 3.0.3 to build"
+
+ # prep the working location
+ local workdir; workdir=$(mktemp -d --tmpdir jekyll-XXXXXXXXXX) || die "fatal: unable to allocate a temporary directory"
+ trap "rm -rf '""$workdir""'" 0 1 2 3 15
+
+ # actually generate the site
+ jekyll build --config "$config" --destination "$workdir/_site" || die "fatal: jekyll build failure"
+
+ # prepare and commit to the target branch
+ export GIT_INDEX_FILE="$workdir/index"
+ git --work-tree="$workdir/_site" add . || die "fatal: error adding $workdir/_site"
+ local tree; tree=$(git write-tree) || die "fatal: error writing tree"
+ local commit; commit=$(git commit-tree "$tree" -p "$target_branch" -m "$message") || die "fatal: error writing commit"
+ git update-ref -m "$message" "$target_branch" "$commit" || die "fatal: error updating ref"
+
+ return 0
+}
+
+build_jekyll_site 'gh-pages' 'accumulo.apache.org' '_config-asf.yml'