diff --git a/.github/workflows/scripts/check-collector-module-version.sh b/.github/workflows/scripts/check-collector-module-version.sh index c822fd20dd44b..eba185a253773 100755 --- a/.github/workflows/scripts/check-collector-module-version.sh +++ b/.github/workflows/scripts/check-collector-module-version.sh @@ -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" @@ -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" @@ -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 \ No newline at end of file +# done + +git diff --exit-code