Skip to content

Commit

Permalink
[chore] make the collector module version script output a git diff (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#27898)

The current behavior consists in exiting early on the first difference
found.

This approach continues to look at all changes, and only exits after
outputting a git diff of all the changes.
  • Loading branch information
atoulme authored and sigilioso committed Oct 27, 2023
1 parent 4611926 commit 6d075f5
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 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,50 +33,33 @@ 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
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "s|$collector_module [^ ]*|$collector_module $collector_mod_version|g" $mod_file
else
sed -i'' "s|$collector_module [^ ]*|$collector_module $collector_mod_version|g" $mod_file
fi
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"


BETA_MODULE="go.opentelemetry.io/collector"
# Note space at end of string. This is so it filters for the exact string
# 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_MOD_VERSION=$(get_collector_version "$BETA_MODULE " "$MAIN_MOD_FILE")
check_collector_versions_correct "$BETA_MODULE" "$BETA_MOD_VERSION"
for mod in ${beta_modules[@]}; do
check_collector_versions_correct "$mod" "$BETA_MOD_VERSION"
done

# Check RC modules
RC_MODULE="go.opentelemetry.io/collector/pdata "
RC_MOD_VERSION=$(get_collector_version "$RC_MODULE" "$MAIN_MOD_FILE")
RC_MODULE="go.opentelemetry.io/collector/pdata"
RC_MOD_VERSION=$(get_collector_version "$RC_MODULE " "$MAIN_MOD_FILE")
check_collector_versions_correct "$RC_MODULE" "$RC_MOD_VERSION"
for mod in ${rc_modules[@]}; do
check_collector_versions_correct "$mod" "$RC_MOD_VERSION"
Expand All @@ -86,4 +71,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

0 comments on commit 6d075f5

Please sign in to comment.