From ffc7800c017b5e7a8dea858baed0e029b5d16972 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 3 Dec 2024 15:30:25 +0100 Subject: [PATCH] Static checks now rebuilds container if run.sh is modified Ticket: ENT-10993 Changelog: None Signed-off-by: Lars Erik Wik --- tests/static-check/run.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index ba434a655e..a9a9021f74 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -25,7 +25,30 @@ function create_image() { set -x -# TODO: check how old the image is and recreate if it's too old +# Get the version of CFEngine from configure +VERSION=`./configure --version | head -n1 | grep -Eo '[0-9]+\.[0-9]+'` +VERSION="${VERSION}.x" + +# Check if we can find this file upstream +STATUS=`curl -o /dev/null --silent -Iw '%{http_code}' "https://raw.githubusercontent.com/cfengine/core/refs/heads/${VERSION}/tests/static-check/run.sh"` +if [[ $STATUS = "404" ]] +then + # If a branch with that version does not exist, then it's probably master + VERSION="master" + STATUS=`curl -o /dev/null --silent -Iw '%{http_code}' "https://raw.githubusercontent.com/cfengine/core/refs/heads/${VERSION}/tests/static-check/run.sh"` +fi + +# Compare digest of this file with upstream. If it has changed, then we rebuild the container +if [[ $STATUS = "200" ]] +then + SUM_A=`curl "https://raw.githubusercontent.com/cfengine/core/refs/heads/${VERSION}/tests/static-check/run.sh" | sha256sum | awk '{print $1}'` + SUM_B=`sha256sum "$0" | awk '{print $1}'` + if [[ $SUM_A != $SUM_B ]] + then + c=$(create_image) + fi +fi + if buildah inspect cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION >/dev/null 2>&1; then c=$(buildah from cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION) else