From 8034e0d160b0591a97a8d1618b7062dad2a226ac Mon Sep 17 00:00:00 2001
From: zirain <zirain2009@gmail.com>
Date: Wed, 22 Jan 2025 08:25:08 +0800
Subject: [PATCH] [chore] detect gnu-sed (#37306)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

make `check-collector-module-version.sh` worked on macos with gnu-sed.

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/37304

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

Co-authored-by: Sean Marciniak <30928402+MovieStoreGuy@users.noreply.github.com>
---
 .../workflows/scripts/check-collector-module-version.sh   | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/scripts/check-collector-module-version.sh b/.github/workflows/scripts/check-collector-module-version.sh
index c9e479a08929..e7d350ef2979 100755
--- a/.github/workflows/scripts/check-collector-module-version.sh
+++ b/.github/workflows/scripts/check-collector-module-version.sh
@@ -14,6 +14,12 @@ set -eu -o pipefail
 
 mod_files=$(find . -type f -name "go.mod")
 
+# Check if GNU sed is installed
+GNU_SED_INSTALLED=false
+if sed --version 2>/dev/null | grep -q "GNU sed"; then
+   GNU_SED_INSTALLED=true
+fi
+
 # Return the collector main core version
 get_collector_version() {
    collector_module="$1"
@@ -37,7 +43,7 @@ check_collector_versions_correct() {
 
    # Loop through all the module files, checking the collector version
    for mod_file in $mod_files; do
-      if [ "$(uname)" == "Darwin" ]; then
+      if [ "${GNU_SED_INSTALLED}" = false ]; 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