blob: 43aef3415b72150cd90a6eb78c7349b077f7baf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#!/bin/bash
SCRIPT_DIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
JOB_DIR="${SCRIPT_DIR}/jobs"
WORKSPACE_DIR="${SCRIPT_DIR}/workspaces"
check_for_remote_changes() {
local DIR=$1
local BRANCH=$2
pushd "${DIR}" > /dev/null || { echo "Directory ${DIR} not found!"; return 1; }
# Fetch the latest changes from the remote
git fetch
# Get the local and remote commit hashes for the branch
LOCAL=$(git rev-parse "${BRANCH}")
REMOTE=$(git rev-parse "origin/${BRANCH}")
# Check if local and remote are different
if [ "${LOCAL}" != "${REMOTE}" ]; then
echo $(date +"%Y-%m-%d %H:%M:%S") "Remote changes detected in ${DIR}"
popd > /dev/null
return 0
else
echo $(date +"%Y-%m-%d %H:%M:%S") "No remote changes in ${DIR}"
popd > /dev/null
return 1
fi
}
trigger() {
REPO=""
BRANCH="live"
COMMAND="make publish"
source "${1}"
DIR="$(echo ${REPO##*/} | sed -e 's/\.git$//')"
FORCE=${2}
# echo REPO=${REPO}
# echo BRANCH=${BRANCH}
# echo COMMAND=${COMMAND}
# echo DIR=${DIR}
# echo FORCE=${FORCE}
if [ ${REPO} ]; then
if ! [ -e "${WORKSPACE_DIR}/${DIR}" ] ; then
git clone -b ${BRANCH} ${REPO} "${WORKSPACE_DIR}/${DIR}"
FORCE=1
fi
if [ "${FORCE}" ] || check_for_remote_changes "${WORKSPACE_DIR}/${DIR}" "${BRANCH}"; then
pushd "${WORKSPACE_DIR}/${DIR}"
git pull origin ${BRANCH} # Pull the latest changes
${COMMAND}
popd
fi
fi
}
mkdir -p "${WORKSPACE_DIR}"
if [ $# -gt 0 ] ; then
for i in $@ ; do
trigger "${JOB_DIR}/$i" 1
done
else
for i in ${JOB_DIR}/* ; do
trigger "$i"
done
fi
|