From 6c4182eca976f9418958bcdb9d9b6d72719c7a7d Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Jun 03 2020 15:38:19 +0000 Subject: Add a macro to parse out the dist tag from tagged commits --- diff --git a/macros.get_tag_from_git_repo b/macros.get_tag_from_git_repo new file mode 100644 index 0000000..8d70274 --- /dev/null +++ b/macros.get_tag_from_git_repo @@ -0,0 +1,61 @@ +# +# +# This macro looks for a dist tag in the exact commit you +# checked out by cutting it into bits segmented by '.' +# and matching known values. +# If nothing is found it will fall back to a default +# +# + +# The actual work is done inside of this function +# set the "DEFAULT" and save it +# look through our known suffix lists +######### +# suffix list: +# ae - Ansible Engine +# cf - Cloud Forms +# dsrv - Directory Server +# ev - Enterprise Virtulization +# op - Open Shift +# ost - Open Stack +# rhs - Storage Server +# rt - Real Time (MRG) +# sat - Satellite Server +######### + +%__get_tag_from_git_repo %{expand:%%(DEFAULT="el%{rhel}.centos" \ +result=${DEFAULT} \ +for element in $( git describe --tags --exact-match 2>/dev/null | tr '.' ' ' ); do \ + if [[ "$element" == "el%{rhel}" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}ae" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}cf" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}dsrv" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}ev" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}op" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}ost" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}rhs" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}rt" ]]; then \ + result=$element \ + elif [[ "$element" == "el%{rhel}sat" ]]; then \ + result=$element \ + else \ + for minor in $(seq 0 11); do \ + if [[ "$element" == "el%{rhel}_${minor}" ]]; then \ + result=$element \ + fi \ + done \ + fi \ +done \ +echo "### 'git based' dist-tag set to '.${result}' (default:.${DEFAULT})" >&2 \ +echo .$result )} + +%dist %__get_tag_from_git_repo +