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

[chore] make the collector module version script output a git diff #27898

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
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
36 changes: 9 additions & 27 deletions .github/workflows/scripts/check-collector-module-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ source ./internal/buildscripts/modules

set -eu -o pipefail

mod_files=$(find . -type f -name "go.mod")

# Return the collector main core version
get_collector_version() {
collector_module="$1"
Expand All @@ -31,42 +33,20 @@ get_collector_version() {
check_collector_versions_correct() {
collector_module="$1"
collector_mod_version="$2"
incorrect_version=0
mod_files=$(find . -type f -name "go.mod")
echo "Checking $collector_module is used with $collector_mod_version"

# Loop through all the module files, checking the collector version
for mod_file in $mod_files; do
if grep -q "$collector_module " "$mod_file"; then
mod_line=$(grep -m1 "$collector_module " "$mod_file")
version=$(echo "$mod_line" | cut -d" " -f2)

# To account for a module on its own 'require' line,
# the version field is shifted right by 1. Match
# with or without a trailing space at the end to account
# for the space at the end of some collector modules.
if [ "$version" == "$collector_module" ] || [ "$version " == "$collector_module" ]; then
version=$(echo "$mod_line" | cut -d" " -f3)
fi

if [ "$version" != "$collector_mod_version" ]; then
incorrect_version=$((incorrect_version+1))
echo "Incorrect version \"$version\" of \"$collector_module\" is included in \"$mod_file\". It should be version \"$collector_mod_version\"."
fi
fi
sed -i'' "s|$collector_module [^ ]*|$collector_module $collector_mod_version|g" $mod_file
done

echo "There are $incorrect_version incorrect \"$collector_module\" version(s) in the module files."
if [ "$incorrect_version" -gt 0 ]; then
exit 1
fi
}

MAIN_MOD_FILE="./go.mod"

# Note space at end of string. This is so it filters for the exact string
atoulme marked this conversation as resolved.
Show resolved Hide resolved
# only and does not return string which contains this string as a substring.
BETA_MODULE="go.opentelemetry.io/collector "
BETA_MOD_VERSION=$(get_collector_version "$BETA_MODULE" "$MAIN_MOD_FILE")
BETA_MODULE="go.opentelemetry.io/collector"
BETA_MOD_VERSION=$(get_collector_version "$BETA_MODULE " "$MAIN_MOD_FILE")
atoulme marked this conversation as resolved.
Show resolved Hide resolved
check_collector_versions_correct "$BETA_MODULE" "$BETA_MOD_VERSION"
for mod in ${beta_modules[@]}; do
check_collector_versions_correct "$mod" "$BETA_MOD_VERSION"
Expand All @@ -86,4 +66,6 @@ done
# check_collector_versions_correct "$STABLE_MODULE" "$STABLE_MOD_VERSION"
# for mod in ${stable_modules[@]}; do
# check_collector_versions_correct "$mod" "$STABLE_MOD_VERSION"
# done
# done

git diff --exit-code