@@ -794,11 +794,32 @@ function shellcheck_new_files() {
794
794
}
795
795
796
796
function latest_version() {
797
- local semver=$( git describe --match " v[0-9]*" --abbrev=0)
798
- local major_minor=$( echo " $semver " | cut -d. -f1-2)
797
+ # This function works "best effort" and works on Prow but not necessarily locally.
798
+ # The problem is finding the latest release. If a release occurs on the same commit which
799
+ # was branched from master, then the tag will be an ancestor to any commit derived from master.
800
+ # That was the original logic. Additionally in a release branch, the tag is always an ancestor.
801
+ # However, if the release commit ends up not the first commit from master, then the tag is not
802
+ # an ancestor of master, so we can't use `git describe` to find the most recent versioned tag. So
803
+ # we just sort all the tags and find the newest versioned one.
804
+ # But when running locally, we cannot(?) know if the current branch is a fork of master or a fork
805
+ # of a release branch. That's where this function will malfunction when the last release did not
806
+ # occur on the first commit -- it will try to run the upgrade tests from an older version instead
807
+ # of the most recent release.
808
+ # Workarounds include:
809
+ # Tag the first commit of the release branch. Say release-0.75 released v0.75.0 from the second commit
810
+ # Then tag the first commit in common between master and release-0.75 with `v0.75`.
811
+ # Always name your local fork master or main.
812
+ if [ $( current_branch) = " master" ] || [ $( current_branch) = " main" ]; then
813
+ # For main branch, simply use git tag without major version, this will work even
814
+ # if the release tag is not in the main
815
+ git tag -l " v[0-9]*" | sort -r --version-sort | head -n1
816
+ else
817
+ local semver=$( git describe --match " v[0-9]*" --abbrev=0)
818
+ local major_minor=$( echo " $semver " | cut -d. -f1-2)
799
819
800
- # Get the latest patch release for the major minor
801
- git tag -l " ${major_minor} *" | sort -r --version-sort | head -n1
820
+ # Get the latest patch release for the major minor
821
+ git tag -l " ${major_minor} *" | sort -r --version-sort | head -n1
822
+ fi
802
823
}
803
824
804
825
# Initializations that depend on previous functions.
0 commit comments