Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to check outdated image references #2199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ govet:
verify-commits:
hack/verify-commits.sh

ci-job: verify-commits gofmt golint govet cnftests-unit
verify-images-updated:
hack/verify-images-updated.sh

ci-job: verify-commits verify-images-updated gofmt golint govet cnftests-unit

ztp-ci-job:
$(MAKE) -C ztp ci-job
Expand Down
56 changes: 56 additions & 0 deletions hack/verify-images-updated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Purpose: This script ensures that specific files containing hardcoded release versions are up to date with the current release and do not reference any previous versions.

# Functionality:
# 1. Determines if the current branch is a release branch (e.g., release-4.x).
# 2. Extracts the previous version (e.g. 4.16 for release-4.17).
# 3. Checks specific files for any occurrences of the previous version.
# 4. If matches are found, it prompts the user to update references to the current release branch and exits with an error code.
# 5. Skips checks for non-release branches or missing files.

branch_name=$(git rev-parse --abbrev-ref HEAD)

release_regex="release-([0-9]+)\.([0-9]+)"

if [[ ! $branch_name =~ $release_regex ]]; then
echo "Branch '$branch_name' is not a release branch. Skipping checks."
exit 0
fi

x="${BASH_REMATCH[1]}"
y="${BASH_REMATCH[2]}"
previous_version="$x.$((y - 1))" # Example: 4.16 for branch release-4.17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the branch was significantly outdated and contained references older than the previous release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be possible, look at my comment to Bart. Since we aligned the master branch to reference 4.19 images and assuming having this script this would be impossible


files_to_check=(
"cnf-tests/Dockerfile.openshift"
"cnf-tests/Dockerfile.konflux"
"cnf-tests/mirror/images.json"
"cnf-tests/testsuites/pkg/images/images.go"
"hack/common.sh"
"hack/run-functests.sh"
)

match_found=false

for file in "${files_to_check[@]}"; do
if [[ ! -f "$file" ]]; then
echo "Warning: File '$file' does not exist. Skipping."
continue
fi
if grep -nw "$file" -e "$previous_version" 2>/dev/null ; then
echo "Reference to $previous_version found in $file."
match_found=true
fi
done

if $match_found; then
echo "----------------------------------------------------------------------------------"
echo "The following files contain references to the previous release version ($previous_version):"
echo "Please update them to the current release branch ($branch_name) to ensure consistency."
echo "This can be done by creating a PR against ($branch_name)."
echo "For more details, refer to the Branching section in the project's readme.md."
exit 1
else
echo "All files are up-to-date. No references to $previous_version were found."
fi