Skip to content

Commit

Permalink
ci: add more status information including timestamp for cron
Browse files Browse the repository at this point in the history
  • Loading branch information
rimelek committed Jul 17, 2022
1 parent 93802bf commit 2924c51
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ci/build.cron.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
write_info "Get the latest version"

LATEST_VERSION="$(getLatestStableOrPreVersion "$CI_BRANCH")"
if [[ -z "$LATEST_VERSION" ]]; then
write_info "There is no stable version nor pre-release $CI_BRANCH"
exit 0
fi
write_info "LATEST_VERSION=$LATEST_VERSION"

write_info "Set cache image tag to $LATEST_VERSION"
VERSION_CACHE="$LATEST_VERSION"

write_info "Try to pull image cache image: $CI_IMAGE_NAME:$VERSION_CACHE"
docker pull "$CI_IMAGE_NAME:$VERSION_CACHE" || true

write_info "Prepare build directory"
BUILD_DIR="$PROJECT_ROOT/var/.build"
if [[ -d "$BUILD_DIR" ]]; then
rm -rf "$BUILD_DIR"
fi
if [[ "${CI_REPOSITORY_URL-x}" == "x" ]]; then

write_info "Check if the the repository URL is not defined or empty"
if [[ "${CI_REPOSITORY_URL-x}" == "x" ]] || [[ -z "$CI_REPOSITORY_URL" ]]; then
write_info "Repository URL is not defined."
write_info "Get repository URL from the repository: $CI_REPOSITORY_ALIAS"
CI_REPOSITORY_URL="$(git remote get-url "$CI_REPOSITORY_ALIAS")"
fi

write_info "Cloning from $CI_REPOSITORY_URL"
write_info "Cloning from $CI_REPOSITORY_URL to $BUILD_DIR"
git clone --branch "v$LATEST_VERSION" "$CI_REPOSITORY_URL" "$BUILD_DIR"
cd "$BUILD_DIR"

Expand Down
16 changes: 16 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,28 @@ reqVarNonEmpty CI_BRANCH
reqVarNonEmpty GIT_HASH
reqVarNonEmpty CI_EVENT_TYPE

write_info "Event type: $CI_EVENT_TYPE"

if [[ "$CI_EVENT_TYPE" == "cron" ]]; then
write_info "Run cron job"
write_time_info

write_info "Check if the build was triggered by pushing to a branch."
if [[ "$(isBranch)" == "true" ]]; then

write_info "Check if the name of the branch is a minor version like 2.1 and not 2.1.0"
if [[ "$(isMinorBranch)" == "true" ]]; then
write_info "Start building..."
source "$PROJECT_ROOT/ci/build.cron.sh"
write_info "The build was finished successfully."
else
write_info "The name of the branch is not a minor version: $CI_BRANCH"
fi
else
write_info "The build was not triggerd by pushing to a branch"
fi
else
write_info "Start building triggered by pushing to a branch: $CI_BRANCH"
source "$PROJECT_ROOT/ci/build.push.sh"
write_info "The build was finished successfully."
fi
13 changes: 13 additions & 0 deletions ci/resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ PATTERN_MINOR_BRANCH='^\([0-9]\+\.[0-9]\+\)\(-dev\)\?$'
PATTERN_STABLE_VERSION='[0-9]\+\.[0-9]\+\.[0-9]\+'
PARENT_IMAGE="httpd:2.4"

function get_current_time() {
date +'%Y-%m-%d %H:%M:%S %Z'
}

function get_current_time_utc() {
TZ=UTC get_current_time
}

function write_status() {
echo "${1:-}" | awk -v "label=$2" '{ gsub(/^/, "-- ["label"] -- "); print $0 }'
}
Expand All @@ -13,6 +21,11 @@ function write_info() {
write_status "$1" "info"
}

function write_time_info() {
write_info "Current local time: $(get_current_time)"
write_info "Current UTC time: $(get_current_time_utc)"
}

function reqVar() {
: "${!1?\$${1} is not set}"
}
Expand Down

0 comments on commit 2924c51

Please sign in to comment.