Skip to content

Commit

Permalink
Filter versions (#1511)
Browse files Browse the repository at this point in the history
* filter tags

* filter yc branches

* formatting

* add HEAD tag
  • Loading branch information
benderl authored Apr 4, 2024
1 parent 7f27cfa commit 1e123f0
Showing 1 changed file with 56 additions and 16 deletions.
72 changes: 56 additions & 16 deletions runs/update_available_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ####"

Expand All @@ -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
Expand All @@ -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=$(
Expand All @@ -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
Expand Down

0 comments on commit 1e123f0

Please sign in to comment.