Skip to content

Commit 4b1bd18

Browse files
authored
fix(snyk-report): Improve calculation of latest patch release (#23223)
Signed-off-by: Oliver Gondža <[email protected]>
1 parent 4b86629 commit 4b1bd18

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

hack/snyk-report.sh

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
set -e
44
set -o pipefail
55

6+
function get_latest_minor_version_tags() {
7+
count=$1
8+
9+
git tag -l \
10+
| sed -E 's/(v[0-9]\.[0-9]+).*/\1/' \
11+
| sort -Vu \
12+
| tail -n "$count"
13+
}
14+
15+
function get_latest_patch_versions() {
16+
count=$1
17+
18+
while read -r minor; do
19+
git tag -l | grep "^$minor" | sort -V | tail -n 1
20+
done < <(get_latest_minor_version_tags "$count")
21+
}
22+
623
npm install snyk snyk-to-html --location=global
724

825
# Choose the branch where docs changes will actually be written.
@@ -39,24 +56,14 @@ git checkout master
3956

4057
minor_version=$(git tag -l | sort -V | tail -n 1 | grep -Eo '[0-9]+\.[0-9]+')
4158
patch_num=$(git tag -l | grep "v$minor_version." | grep -o "[a-z[:digit:]-]*$" | sort -V | tail -n 1)
42-
version="v$minor_version.$patch_num"
43-
versions="master "
4459

4560
version_count=3
4661
# When the most recent version is still a release candidate, get reports for 4 versions (so the 3 most recent stable
4762
# releases are included).
4863
if [[ $patch_num == "0-rc"* ]]; then version_count=4; fi
64+
versions="$(get_latest_patch_versions "$version_count")"
4965

50-
for i in $(seq "$version_count"); do
51-
if [ "$version" == "" ]; then break; fi
52-
# Nightmare code to get the most recent patches of the three most recent minor versions.
53-
versions+="$version "
54-
minor_num=$(printf '%s' "$minor_version" | sed -E 's/[0-9]+\.//')
55-
minor_num=$((minor_num-1))
56-
minor_version=$(printf '%s' "$minor_version" | sed -E "s/\.[0-9]+$/.$minor_num/g")
57-
patch_num=$(git tag -l | grep "v$minor_version." | grep -o "[a-z[:digit:]-]*$" | sort -V | tail -n 1)
58-
version="v$minor_version.$patch_num"
59-
done
66+
echo "Analyzing versions: $versions"
6067

6168
for version in $versions; do
6269
printf '\n%s\n\n' "### $version" >> "$argocd_dir/docs/snyk/index.md"

0 commit comments

Comments
 (0)