Skip to content

Commit

Permalink
Merge pull request #5645 from larsewi/static
Browse files Browse the repository at this point in the history
ENT-10993: Static checks now rebuilds container if run.sh is modified
  • Loading branch information
larsewi authored Dec 5, 2024
2 parents 50afb6f + ace19ac commit 74d100b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/static-check/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
set -eE # include E so that create_image() failures bubble up to the surface
trap "echo FAILURE" ERR

SUM_FILE="`basename $0`.sum"

if [ -z "$STATIC_CHECKS_FEDORA_VERSION" ]; then
default_f_ver="40"
echo "No Fedora version for static checks specified, using the default (Fedora $default_f_ver)"
Expand All @@ -19,15 +21,37 @@ function create_image() {
buildah run $c -- dnf -q -y install "@C Development Tools and Libraries" clang cppcheck which diffutils file >/dev/null 2>&1
buildah run $c -- dnf -q -y install pcre-devel pcre2-devel openssl-devel libxml2-devel pam-devel lmdb-devel libacl-devel libyaml-devel curl-devel libvirt-devel >/dev/null 2>&1
buildah run $c -- dnf clean all >/dev/null 2>&1

# Copy checksum of this file into container
sha256sum $0 > $SUM_FILE
buildah copy $c $SUM_FILE >/dev/null
rm $SUM_FILE

buildah commit $c cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION >/dev/null 2>&1
echo $c
}

set -x

# TODO: check how old the image is and recreate if it's too old
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)

# Recreate the image if the checksum of this file has changed
if [[ `buildah run $c ls $SUM_FILE` == $SUM_FILE ]]; then
SUM_A=$(sha256sum $0)
SUM_B=$(buildah run $c cat $SUM_FILE)
if [[ $SUM_A != $SUM_B ]]; then
echo "Recreating image due to mismatching checksum..."
IMAGE_ID=$(buildah inspect $c | jq -r '.FromImageID')
buildah rmi --force $IMAGE_ID >/dev/null
c=$(create_image)
fi
else
echo "Recreating image due to missing checksum..."
IMAGE_ID=$(buildah inspect $c | jq -r '.FromImageID')
buildah rmi --force $IMAGE_ID >/dev/null
c=$(create_image)
fi
else
c=$(create_image)
fi
Expand Down

0 comments on commit 74d100b

Please sign in to comment.