From 1e123f0b9c487013d4a980ee6fc2240b328f5d18 Mon Sep 17 00:00:00 2001 From: benderl Date: Thu, 4 Apr 2024 16:08:29 +0200 Subject: [PATCH] Filter versions (#1511) * filter tags * filter yc branches * formatting * add HEAD tag --- runs/update_available_versions.sh | 72 ++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/runs/update_available_versions.sh b/runs/update_available_versions.sh index 7cf8bd733c..cefcccd8f1 100755 --- a/runs/update_available_versions.sh +++ b/runs/update_available_versions.sh @@ -2,12 +2,34 @@ OPENWBBASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) LOGFILE="${OPENWBBASEDIR}/data/log/update.log" GITREMOTE="origin" +YOURCHARGEPREFIX="yc/" if [ "$(id -u -n)" != "openwb" ]; then echo "this script has to be run as user openwb" exit 1 fi +validateTag() { + branch=$1 + tag=$2 + + case $branch in + "release" | "Release") + if [[ $tag =~ ([Rr][Cc])|([Bb]eta)|([Aa]lpha) ]] || [[ $tag =~ 1.99 ]]; then + return 1 + fi + ;; + "beta" | "Beta") + if [[ $tag =~ [Aa]lpha ]] || [[ $tag =~ 1.99 ]]; then + return 1 + fi + ;; + *) + return 0 + ;; + esac +} + { echo "#### updating available version info ####" @@ -18,7 +40,7 @@ fi echo "$currentCommit" >"$OPENWBBASEDIR/web/lastcommit" # fetch data from git - echo "fetching latest data from $GITREMOTE..." + echo "fetching latest data from '$GITREMOTE'..." git -C "$OPENWBBASEDIR" fetch --verbose --prune --tags --prune-tags --force "$GITREMOTE" && echo "done" # update branches from $GITREMOTE @@ -32,20 +54,38 @@ fi unset 'branches[$index]' else branches[index]="${branches[$index]//*$GITREMOTE\//}" # remove leading whitespace and $GITREMOTE/ - echo -n "checking commit for $GITREMOTE/${branches[$index]}..." - availableBranches[${branches[$index]}]=$(git -C "$OPENWBBASEDIR" log --pretty='format:%ci [%h]' -n1 "$GITREMOTE/${branches[$index]}") - echo "${availableBranches[${branches[$index]}]}" - echo "tags in branch:" - read -r -d '' -a tags < <(git -C "$OPENWBBASEDIR" tag -n --format "%(refname:short): %(subject)" --merged "$GITREMOTE/${branches[$index]}") - echo "${tags[*]}" - tagsJson[${branches[$index]}]=$( - for key in "${!tags[@]}"; do - echo "${tags[${key}]//: */}" - echo "${tags[${key}]}" - done | - jq -n -R -c 'reduce inputs as $key ({}; . + { ($key): (input) })' - ) - echo "${branches[$index]}: ${tagsJson[${branches[$index]}]}" + if [[ ${branches[$index]} == *"$YOURCHARGEPREFIX"* ]]; then + echo "skipping branch '${branches[$index]}'" + unset 'branches[$index]' + else + echo -n "checking commit for '$GITREMOTE/${branches[$index]}'..." + availableBranches[${branches[$index]}]=$(git -C "$OPENWBBASEDIR" log --pretty='format:%ci [%h]' -n1 "$GITREMOTE/${branches[$index]}") + echo "${availableBranches[${branches[$index]}]}" + echo "tags in branch:" + read -r -d '' -a tags < <(git -C "$OPENWBBASEDIR" tag -n --format "%(refname:short): %(subject)" --merged "$GITREMOTE/${branches[$index]}") + echo "${tags[*]}" + tagsJson[${branches[$index]}]=$( + for key in "${!tags[@]}"; do + if validateTag "${branches[$index]}" "${tags[${key}]//: */}"; then + echo "${tags[${key}]//: */}" + echo "${tags[${key}]}" + else + # invalid tag for this branch, skip + continue + fi + # special handling for last element in $tags + if (( key == ${#tags[@]}-1 )); then + # add tag *HEAD* if branch is not "Beta" or "Release" + if [[ ${branches[$index]} != "Beta" ]] && [[ ${branches[$index]} != "Release" ]]; then + echo "*HEAD*" + echo "Aktuellster Stand" + fi + fi + done | + jq -n -R -c 'reduce inputs as $key ({}; . + { ($key): (input) })' + ) + echo "${branches[$index]}: ${tagsJson[${branches[$index]}]}" + fi fi done branchJson=$( @@ -66,7 +106,7 @@ fi # update $currentBranch commit currentBranchCommit=$(git -C "$OPENWBBASEDIR" log --pretty='format:%ci [%h]' -n1 "$GITREMOTE/$currentBranch") - echo "last commit to $currentBranch branch: $currentBranchCommit" + echo "last commit in '$currentBranch' branch: $currentBranchCommit" mosquitto_pub -p 1886 -t "openWB/system/current_branch_commit" -r -m "\"$currentBranchCommit\"" # list missing commits