From 718c9bf97f19dcc8b3144fa1f52a8ba4ae6b51ff Mon Sep 17 00:00:00 2001 From: Bodo Schulz Date: Fri, 10 Nov 2023 05:48:22 +0100 Subject: [PATCH] update build hooks --- hooks/molecule.rc | 65 +++++++++++++++++++++++++++++++++++++++++++++++ hooks/tox.sh | 30 ++++++++++++++++++++-- tox.ini | 3 +++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/hooks/molecule.rc b/hooks/molecule.rc index a15f7c3..78c8621 100644 --- a/hooks/molecule.rc +++ b/hooks/molecule.rc @@ -7,3 +7,68 @@ then fi TOX_OPTS="-e ${TOX_ANSIBLE}" + +vercomp() { + + [[ $1 == $2 ]] && return 0 + v1=$(echo "$1" | sed -e 's|-|.|g') + v2=$(echo "$2" | sed -e 's|-|.|g') + + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + return 2 + fi + done + return 0 +} + +install_collection() { + local collection="${1}" + + echo "Install the required collection '${collection}'" + ansible-galaxy collection install ${collection} +} + +remove_collection() { + + local collection="${1}" + + namespace="$(echo "${collection}" | cut -d '.' -f1)" + name="$(echo "${collection}" | cut -d '.' -f2)" + + collection="${HOME}/.ansible/collections/ansible_collections/${namespace}/${name}" + + rm \ + --recursive \ + --force \ + "${collection}" +} + +publish() { + + TOKEN="${HOME}/.ansible/galaxy_token" + + if [ -e "${TOKEN}" ] + then + ansible-galaxy import --token=$(cat "${TOKEN}") bodsch # "???" + fi +} diff --git a/hooks/tox.sh b/hooks/tox.sh index 62bb777..c93de29 100755 --- a/hooks/tox.sh +++ b/hooks/tox.sh @@ -12,12 +12,38 @@ then if [ -z "${collections_installed}" ] then - echo "Install the required collection '${collection}'" - ansible-galaxy collection install ${collection} + install_collection ${collection} else collection_version=$(echo "${collections_installed}" | awk -F ' ' '{print $2}') + version="$(grep -v "#" collections.yml | grep -A1 "^ - name: ${collection}" | grep "version: " 2> /dev/null | awk -F ': ' '{print $2}' | sed -e 's|=||' -e 's|>||' -e 's|"||g')" echo "The required collection '${collection}' is installed in version ${collection_version}." + + if [ ! -z "${version}" ] + then + + vercomp "${version}" "${collection_version}" + + case $? in + 0) op='=' ;; + 1) op='>' ;; + 2) op='<' ;; + esac + + if [[ $op = "=" ]] || [[ $op = ">" ]] + then + # echo "FAIL: Expected '$3', Actual '$op', Arg1 '$1', Arg2 '$2'" + echo "re-install for version ${version}" + + remove_collection ${collection} + install_collection ${collection} + else + : + # echo "Pass: '$1 $op $2'" + fi + else + : + fi fi done echo "" diff --git a/tox.ini b/tox.ini index d7cb253..a485358 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,9 @@ deps = ansible_6.1: ansible>=6.1,<6.2 ansible_6.7: ansible>=6.7,<6.8 ansible_7.0: ansible>=7.0,<7.1 + ansible_7.5: ansible>=7.5,<7.6 + ansible_8.0: ansible>=8.0,<8.1 + ansible_8.5: ansible>=8.5,<8.6 #commands_pre = # /usr/bin/find {toxinidir} -type f -not -path '{toxworkdir}/*' -path '*/__pycache__/*' -name '*.py[c|o]' -delete