From ac155d19cb2966989cb770d813701ed391d496ad Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 8 Aug 2024 17:06:22 +0200 Subject: [PATCH] Yoloattempt to try to keep the build-and-lint up and running and share it between the corresponding jobs --- cleanup.sh | 7 +++++++ common.sh | 28 ++++++++++++++-------------- prepare.sh | 18 +++++++++--------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cleanup.sh b/cleanup.sh index 2e229e9..4411c85 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -3,6 +3,13 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source $current_dir/common.sh +if [[ $IMAGE == "build-and-lint" ]] +then + echo "Should cleanup $CUSTOM_ENV_CI_GIT_CLONE_PATH ?" + exit 0 +fi + + info "Stopping container $CONTAINER_NAME" incus stop "$CONTAINER_NAME" diff --git a/common.sh b/common.sh index c42dd5e..364fd9a 100755 --- a/common.sh +++ b/common.sh @@ -19,21 +19,21 @@ CURRENT_BRANCH="${CUSTOM_ENV_CI_COMMIT_REF_NAME:-$DEFAULT_BRANCH}" # CUSTOM_ENV_ IMAGE="${CUSTOM_ENV_CI_JOB_IMAGE:-after-install}" -LAST_CHANGELOG_ENTRY=$(curl $CUSTOM_ENV_CI_PROJECT_URL/-/raw/$CURRENT_BRANCH/debian/changelog --silent | head -n 1) # yunohost (4.2) unstable; urgency=low -DEBIAN_VERSION_NUMBER=$(echo $LAST_CHANGELOG_ENTRY | cut -d' ' -f2 | tr -d '(' | tr -d ')' | cut -d'.' -f1) # 11, 12 -if [[ "$DEBIAN_VERSION_NUMBER" == "11" ]] +[[ -n "$CUSTOM_ENV_CI_YNH_DEBIAN" ]] || { echo "Undefined ynh debian var?"; exit 1; } +DEBIAN=$CUSTOM_ENV_CI_YNH_DEBIAN + +if [[ "$DEBIAN" == "bullseye" ]] then - BASE_IMAGE="ynh-$IMAGE-bullseye-amd64-stable-base" -elif [[ "$DEBIAN_VERSION_NUMBER" == "12" ]] -then - BASE_IMAGE="ynh-$IMAGE-bookworm-amd64-testing-base" -elif [[ "$DEBIAN_VERSION_NUMBER" == "13" ]] -then - # Upcoming somedayâ„¢ - BASE_IMAGE="ynh-$IMAGE-trixie-amd64-unstable-base" + RELEASE="stable" else - echo "Uhoh, unknown debian version $DEBIAN_VERSION_NUMBER" - exit 1 + RELEASE="testing" fi -CONTAINER_NAME="job-$CUSTOM_ENV_CI_JOB_ID-$CUSTOM_ENV_CI_JOB_NAME_SLUG" +BASE_IMAGE="ynh-$IMAGE-bullseye-amd64-$RELEASE-base" + +if [[ $IMAGE == "build-and-lint" ]] +then + CONTAINER_NAME="$DEBIAN-build-and-lint" +else + CONTAINER_NAME="job-$CUSTOM_ENV_CI_JOB_ID-$CUSTOM_ENV_CI_JOB_NAME_SLUG" +fi diff --git a/prepare.sh b/prepare.sh index 11426b4..265bb8c 100755 --- a/prepare.sh +++ b/prepare.sh @@ -98,9 +98,8 @@ trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR ############################################################################### -info "Starting $CONTAINER_NAME from $BASE_IMAGE ..." - if ! incus info "$CONTAINER_NAME" >/dev/null 2>/dev/null ; then + info "Starting $CONTAINER_NAME from $BASE_IMAGE ..." # Force the usage of the fingerprint because otherwise for some reason lxd won't use the newer version # available even though it's aware it exists -_- @@ -108,17 +107,18 @@ if ! incus info "$CONTAINER_NAME" >/dev/null 2>/dev/null ; then # NB: this image comes from the 'common' image repository shared with the appci, ynh-dev etc incus launch yunohost:$BASE_HASH $CONTAINER_NAME + sleep 2 fi -# Stop the container if it's running -if [ "$(incus info $CONTAINER_NAME | grep Status | awk '{print tolower($2)}')" == "running" ]; then - incus stop "$CONTAINER_NAME" --timeout 30 || incus stop "$CONTAINER_NAME" --force +# Start the container if it's not running +if [ "$(incus info $CONTAINER_NAME | grep Status | awk '{print tolower($2)}')" != "running" ]; then + incus start $CONTAINER_NAME fi -# Unset the mac address to ensure the copy will get a new one and will be able to get new IP -incus start $CONTAINER_NAME - -sleep 2 +if [[ $IMAGE == "build-and-lint" ]] +then + exit 0 +fi incus exec $CONTAINER_NAME dhclient eth0