aboutsummaryrefslogtreecommitdiff
path: root/simpleci.sh
diff options
context:
space:
mode:
authorPhilipp Geyer2024-06-17 21:22:53 +0200
committerPhilipp Geyer2024-06-17 21:22:53 +0200
commit3d65b6dcf74600ca836881ef0b2580926af3d2cd (patch)
treeca9cdc5c7cb4ee71154f5493431359a74c7d1e03 /simpleci.sh
parent7f4ce2b2ca4ad41d04789a9877f197b6ebfaded9 (diff)
downloadsimpleci-3d65b6dcf74600ca836881ef0b2580926af3d2cd.tar.gz
simpleci-3d65b6dcf74600ca836881ef0b2580926af3d2cd.tar.bz2
simpleci-3d65b6dcf74600ca836881ef0b2580926af3d2cd.zip
fixing script typo
Diffstat (limited to 'simpleci.sh')
-rwxr-xr-xsimpleci.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/simpleci.sh b/simpleci.sh
new file mode 100755
index 0000000..43aef34
--- /dev/null
+++ b/simpleci.sh
@@ -0,0 +1,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