aboutsummaryrefslogtreecommitdiff
path: root/scripts/git-hooks/post-receive
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-01-19 13:14:38 +0300
committerFrederick Muriuki Muriithi2022-01-24 10:25:27 +0300
commit56eb0eb6ba121c1e65ca078e29a053d64fa12a0a (patch)
tree46cf0c19a4290e4d8b4a5e61095e846828f74316 /scripts/git-hooks/post-receive
parent0af9e6a90fa2a65bcd2c1c6d9c6e47b9f099ec85 (diff)
downloadgenenetwork3-56eb0eb6ba121c1e65ca078e29a053d64fa12a0a.tar.gz
Build script to trigger CI/CD
Diffstat (limited to 'scripts/git-hooks/post-receive')
-rwxr-xr-xscripts/git-hooks/post-receive47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/git-hooks/post-receive b/scripts/git-hooks/post-receive
new file mode 100755
index 0000000..071fa6c
--- /dev/null
+++ b/scripts/git-hooks/post-receive
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+version="0.01"
+job_name="genenetwork3"
+
+RESET_IFS="${IFS}"
+IFS='/'
+read -ra PWD_ARRAY < <(pwd)
+IFS="${RESET_IFS}"
+
+PWD_ARRAY_LEN="${#PWD_ARRAY[@]}"
+GIT_REPO_NAME="${PWD_ARRAY[$((PWD_ARRAY_LEN - 1))]}"
+GIT_REPO_NAME="${GIT_REPO_NAME/.git}"
+GIT_USER_OR_GROUP="${PWD_ARRAY[$((PWD_ARRAY_LEN - 2))]}"
+GIT_HOST="$(hostname -f)"
+
+if [ "${GIT_HOST}" == *"uthsc.edu"* ];
+then
+ GIT_HOST="git.genenetwork.org";
+fi
+
+GIT_REPO_URL="git@${GIT_HOST}:${GIT_USER_OR_GROUP}/${GIT_REPO_NAME}.git"
+
+repo_name_auto="${GIT_REPO_URL,,}"
+repo_name_auto="${repo_name_auto/git@}"
+repo_name_auto="${repo_name_auto/.git}"
+repo_name_auto=$(echo -n "${repo_name_auto}" | tr -c '[:alnum:]' '-')
+
+# Read each line of refs
+while read -r line;
+do
+ # assign to separate variables
+ read -r old_commit new_commit ref_name < <(echo "${line}")
+
+ # retrieve author and committer names and emails
+ mapfile -t autcom_name_email < <(git log --format="%an%n%ae%n%cn%n%ce" "${new_commit}^!")
+
+ GIT_AUTHOR="${autcom_name_email[0]}"
+ GIT_AUTHOR_EMAIL="${autcom_name_email[1]}"
+ GIT_COMMITTER="${autcom_name_email[2]}"
+ GIT_COMMITTER_EMAIL="${autcom_name_email[3]}"
+
+ msg="[Laminar git hook ${version}] Queued Laminar CI build (${job_name} -> ${repo_name_auto})"
+ echo "${msg}";
+
+ LAMINAR_REASON="Push from ${GIT_AUTHOR} to ${GIT_REPO_URL}" laminarc queue "${job_name}" GIT_AUTHOR="${GIT_AUTHOR}" GIT_REPO_URL="${GIT_REPO_URL}" GIT_COMMIT_REF="${new_commit}" GIT_REF_NAME="${ref_name}" GIT_REPO_NAME="${repo_name_auto}";
+done