Skip to content

Commit 3f8c981

Browse files
authored
[CI] Make version-if-file.sh more robust (#6272)
1 parent 069ee71 commit 3f8c981

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

scripts/auto-update/version-in-file.sh

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash -e
2+
#
3+
# cSpell:ignore opentelemetrybot
24

35
GH=gh
46
GIT=git
@@ -18,11 +20,17 @@ else
1820
fi
1921

2022
repo=$1; shift;
21-
latest_version=$(gh api -q .tag_name "repos/open-telemetry/$repo/releases/latest")
22-
latest_vers_no_v="${latest_version#v}" # Remove leading 'v'
23+
24+
# `latest_version_full` is expected to end with a "vX.Y.Z". Note that it can
25+
# have a prefix, such as `cmd/builder/v0.119.0`.
26+
latest_version_full=$(gh api -q .tag_name "repos/open-telemetry/$repo/releases/latest")
27+
28+
# Extract only the semver:
29+
latest_semver=$(echo "$latest_version_full" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+.*)$/\1/')
30+
latest_version="v$latest_semver"
2331

2432
echo "REPO: $repo"
25-
echo "LATEST VERSION: $latest_version"
33+
echo "LATEST VERSION: $latest_semver ($latest_version_full)"
2634

2735
function process_file() {
2836
local name="$1"
@@ -39,7 +47,7 @@ function process_file() {
3947
vers="$latest_version"
4048
else
4149
vers_match_regex="^ *$variable_name:"
42-
vers="$latest_vers_no_v"
50+
vers="$latest_semver"
4351
fi
4452
echo "SEARCHING for: '$vers_match_regex' in $file_name"
4553
if ! grep -q "$vers_match_regex" "$file_name"; then
@@ -68,19 +76,21 @@ if git diff --quiet "${file_names[@]}"; then
6876
else
6977
echo
7078
echo "Version update necessary:"
71-
git diff "${file_names[@]}"
79+
git diff --color "${file_names[@]}" | cat - # to disable pager
7280
echo
7381
fi
7482

7583
message="Update $repo version to $latest_version"
7684
body="Update $repo version to \`$latest_version\`.
7785
7886
See https://github.com/open-telemetry/$repo/releases/tag/$latest_version."
87+
branch="opentelemetrybot/auto-update-$repo-$latest_version"
7988

80-
existing_pr_count=$(gh pr list --state all --search "in:title $message" | wc -l)
89+
existing_pr_all=$(gh pr list --state all --head "$branch")
90+
existing_pr_count=$(echo "$existing_pr_all" | wc -l)
8191
if [ "$existing_pr_count" -gt 0 ]; then
82-
echo "PR(s) already exist for '$message'"
83-
gh pr list --state all --search "\"$message\" in:title"
92+
echo "PR(s) already exist for '$message':"
93+
echo $existing_pr_all
8494
echo "So we won't create another. Exiting."
8595
exit 0
8696
fi
@@ -97,8 +107,6 @@ if [[ "$repo" == "opentelemetry-specification"
97107
)
98108
fi
99109

100-
branch="opentelemetrybot/auto-update-$repo-$latest_version"
101-
102110
$GIT checkout -b "$branch"
103111
$GIT commit -a -m "$message"
104112
$GIT push --set-upstream origin "$branch"

0 commit comments

Comments
 (0)