1
1
Fork 0

v0.1.1 for ci.sh, more error handling

This commit is contained in:
david 2023-12-21 12:01:20 +01:00
parent 2997c6fc48
commit 1b3c18243c
1 changed files with 14 additions and 7 deletions

21
ci.sh
View File

@ -18,11 +18,12 @@
NAME="ci.sh"
DESCRIPTION="A poor man's continuous integration system"
VERSION="0.1.0"
VERSION="0.1.1"
AUTHOR="david@socialnerds.org"
LICENSE="MIT"
WEBSITE="https://git.socialnerds.org/david/scripts"
CHANGELOG=("[2023-12-20][v0.1.0] Initial version")
CHANGELOG=("[2023-12-21][v0.1.1] More error handling"
"[2023-12-20][v0.1.0] Initial version")
##
@ -171,22 +172,28 @@ else
exit 1
fi
# Chech if the script file exists and is executable
if [[ ! -x "$SCRIPTS_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO.sh" ]]; then
lib_print "!No CI script for this repository found [$GIT_HOST/$GIT_USER/$GIT_REPO]"
exit 1
fi
# Create parent directories if missing
if [[ ! -d "$TEMP_DIR/$GIT_HOST/$GIT_USER" ]]; then
mkdir -p "$TEMP_DIR/$GIT_HOST/$GIT_USER"
fi
# Check if repo already exists and if the previous job is still running
if [[ -d "$TEMP_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO" ]]; then
# Check if the previous job is still running
if lib_is_running $(cat "$TEMP_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO.pid" 2> /dev/null); then
lib_print "!CI Job is still running [$GIT_HOST/$GIT_USER/$GIT_REPO]"
lib_ntfy "$NTFY_URL" "!CI job is still running [$GIT_HOST/$GIT_USER/$GIT_REPO]"
lib_checks "$CHECKS_URL" "!CI job is still running [$GIT_HOST/$GIT_USER/$GIT_REPO]"
exit 1 # if we exit with 0 the output would show up in the gitea webinterface
lib_print "!CI job is still running [$GIT_HOST/$GIT_USER/$GIT_REPO]"
exit 1
else
rm -rf "$TEMP_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO"
fi
fi
# Clone the repo and execute the CI script
git clone --quiet "$GIT_URL" "$TEMP_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO"
cd "$TEMP_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO"
nohup "$SCRIPTS_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO.sh" > "$TEMP_DIR/$GIT_HOST/$GIT_USER/$GIT_REPO.log" 2>&1 &