From 103a4941c7053033dc1b1b9d6bc473d69471703b Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Mon, 5 Apr 2021 11:26:07 +0200 Subject: [PATCH] Reliability improvements to `recipe .. release` --- abra | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/abra b/abra index 39fd37a..c0ff426 100755 --- a/abra +++ b/abra @@ -448,7 +448,7 @@ require_consent_for_update() { fi } -require_docker_version (){ +require_docker_version() { get_servers MIN_DOCKER_VERSION=19 @@ -541,9 +541,11 @@ require_app (){ error "Could not retrieve app type '$APP', this app type doesn't exist?" fi + cd "$APP_DIR" && checkout_main_or_master + if [[ $(cd "$ABRA_DIR/apps/$APP" && git branch --list | wc -l) == "0" ]]; then debug "Failed to clone default branch, guessing alternative is 'main'" - (cd "$ABRA_DIR/apps/$APP" && git checkout main > /dev/null 2>&1) + (cd "$ABRA_DIR/apps/$APP" && git checkout main) fi success "Fetched app configuration via Git" @@ -611,6 +613,10 @@ require_yq() { vendor_binary "https://github.com/mikefarah/yq" "v4.6.1" "yq_linux_amd64" } +checkout_main_or_master() { + git checkout main > /dev/null 2>&1 || git checkout master > /dev/null 2>&1 +} + # FIXME 3wc: update or remove if [ -z "$ABRA_ENV" ] && [ -f .env ] && type direnv > /dev/null 2>&1 && ! direnv status | grep -q 'Found RC allowed true'; then error "direnv is blocked, run direnv allow" @@ -629,7 +635,7 @@ get_recipe_versions() { recipe="${1?Recipe not set}" - mapfile -t RECIPE_VERSIONS < <($JQ -r ".${recipe}.versions | keys | .[]" "$ABRA_APPS_JSON" | sort) + mapfile -t RECIPE_VERSIONS < <($JQ -r ".\"${recipe}\".versions | keys | .[]" "$ABRA_APPS_JSON" | sort) } ###### Run-time loading @@ -1730,7 +1736,7 @@ sub_app_rollback(){ abra__version_="$version" abra___update="true" - sub_app_deploy + sub_app_deploy } ###### .. app logs @@ -1871,7 +1877,7 @@ sub_recipe_versions() { printf "%s thrilling versions of $abra__recipe_:\n" "${#RECIPE_VERSIONS[@]}" for version in "${RECIPE_VERSIONS[@]}"; do - recipe_version_data=$($JQ -r ".${abra__recipe_}.versions.\"${version}\"" "$ABRA_APPS_JSON") + recipe_version_data=$($JQ -r ".\"${abra__recipe_}\".versions.\"${version}\"" "$ABRA_APPS_JSON") mapfile -t services < <(echo "$recipe_version_data" | $JQ -r ". | keys | .[]" -) printf '%s:\n' "$version" for service in "${services[@]}"; do @@ -1902,7 +1908,7 @@ sub_recipe_release() { recipe="$abra__recipe_" force="$abra___force" - recipe_dir="$ABRA_DIR/apps/$recipe" + recipe_dir="$ABRA_DIR/apps/$recipe" cd "$recipe_dir" || error "Can't find recipe dir '$recipe_dir'" @@ -1914,7 +1920,7 @@ sub_recipe_release() { info "Latest available version: '$latest_version'" else latest_version="" - latest_version_message="" + latest_version_message="Initial tagged release" info "No previous releases found" fi @@ -1923,6 +1929,14 @@ sub_recipe_release() { error "$recipe is already on $current_tag, no release needed" fi + if [ "$(git rev-parse --abbrev-ref --symbolic-full-name HEAD)" = "HEAD" ]; then + warning "It looks like $recipe_dir is in 'detached HEAD' state" + read -rp "Check out main/master branch first? [Y/n] " + if [ "${choice,,}" != "n" ]; then + checkout_main_or_master + fi + fi + mapfile -t extra_compose_files < <(ls -- compose.*.yml 2> /dev/null || true) compose_files=("compose.yml" "${extra_compose_files[@]}") @@ -1948,7 +1962,7 @@ sub_recipe_release() { service_tag="${service_image##*:}" if [ -n "$latest_version" ]; then - latest_data=$($JQ ".$recipe.versions.\"$latest_version\".\"$service\"" "$ABRA_APPS_JSON") + latest_data=$($JQ ".\"$recipe\".versions.\"$latest_version\".\"$service\"" "$ABRA_APPS_JSON") latest_tag="$(echo "$latest_data" | $JQ -r ".tag" -)" fi @@ -1975,6 +1989,7 @@ sub_recipe_release() { done if [ "$new_version" = "false" ]; then + # `app` tag hasn't changed, just bump release if echo "$latest_version" | grep -q '_'; then latest_version_minor="${latest_version##*_}"