Skip to content

Commit ef9b166

Browse files
mergify[bot]ycombinatorebeahan
authored
[8.19] (backport #10723) [MacOS unit testing] Add version check (#10751)
* [MacOS unit testing] Add version check (#10723) * Add version check * Temporarily run macOS 13 unit tests on PR so we can test the changes in this PR * Extract OS-specific code * Add debugging statement * More debugging * Use macOS version * Refactoring * Revert "Temporarily run macOS 13 unit tests on PR so we can test the changes in this PR" This reverts commit b0ee45a. (cherry picked from commit c46d456) # Conflicts: # magefile.go * fix conflicts * restore clobbered lines --------- Co-authored-by: Shaunak Kashyap <[email protected]> Co-authored-by: ebeahan <[email protected]>
1 parent 6de7f0a commit ef9b166

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

magefile.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import (
3636

3737
"github.com/elastic/elastic-agent/dev-tools/mage/otel"
3838

39-
"github.com/jedib0t/go-pretty/v6/table"
4039
"github.com/otiai10/copy"
40+
"golang.org/x/sync/errgroup"
4141

4242
"github.com/elastic/elastic-agent/dev-tools/mage"
4343
devtools "github.com/elastic/elastic-agent/dev-tools/mage"
@@ -72,9 +72,9 @@ import (
7272
// mage:import
7373
"github.com/elastic/elastic-agent/dev-tools/mage/target/test"
7474

75+
"github.com/jedib0t/go-pretty/v6/table"
7576
"github.com/magefile/mage/mg"
7677
"github.com/magefile/mage/sh"
77-
"golang.org/x/sync/errgroup"
7878
"gopkg.in/yaml.v3"
7979

8080
"helm.sh/helm/v3/pkg/action"
@@ -399,6 +399,20 @@ func (Build) TestBinaries() error {
399399
fmt.Errorf("cannot build test binaries: %w", err)
400400
}
401401

402+
args := []string{"build", "-v"}
403+
if runtime.GOOS == "darwin" {
404+
osMajorVer, err := getMacOSMajorVersion()
405+
if err != nil {
406+
return fmt.Errorf("cannot determine darwin OS major version: %w", err)
407+
}
408+
409+
if osMajorVer > 13 {
410+
// Workaround for https://github.com/golang/go/issues/67854 until it
411+
// is resolved.
412+
args = append(args, "-ldflags", "-extldflags='-ld_classic'")
413+
}
414+
}
415+
402416
for _, pkg := range testBinaryPkgs {
403417
binary := filepath.Base(pkg)
404418
if runtime.GOOS == "windows" {
@@ -4096,3 +4110,18 @@ func loadYamlFile(path string) (map[string]any, error) {
40964110
}
40974111
return data, nil
40984112
}
4113+
4114+
func getMacOSMajorVersion() (int, error) {
4115+
ver, err := sh.Output("sw_vers", "-productVersion")
4116+
if err != nil {
4117+
return 0, err
4118+
}
4119+
4120+
majorVerStr := strings.Split(ver, ".")[0]
4121+
majorVer, err := strconv.Atoi(majorVerStr)
4122+
if err != nil {
4123+
return 0, fmt.Errorf("unable to parse major version from %q: %w", ver, err)
4124+
}
4125+
4126+
return majorVer, nil
4127+
}

0 commit comments

Comments
 (0)