Skip to content

Commit 8786312

Browse files
[Chore] add cgo test for macos-12 and macos-13 (#34741)
**Description:** <Describe what has changed.> In order to add CGO support, add compatibility test for old macos versions. Due macos-12 and macos-13 are using amd64 instead of arm64, cross compiling is used. **Link to tracking Issue:** <Issue number if applicable> #33393 **Testing:** <Describe what testing was performed and which tests were added.> Added tests for hostmetrics receiver for macos-12 and macos-13 **Documentation:** <Describe the documentation added.> --------- Co-authored-by: Sean Marciniak <[email protected]>
1 parent f4a4206 commit 8786312

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: build-and-test-darwin
2+
on:
3+
push:
4+
branches: [main]
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+*"
7+
merge_group:
8+
pull_request:
9+
types: [opened, synchronize, reopened, labeled, unlabeled]
10+
branches:
11+
- main
12+
env:
13+
TEST_RESULTS: testbed/tests/results/junit/results.xml
14+
# Make sure to exit early if cache segment download times out after 2 minutes.
15+
# We limit cache download as a whole to 5 minutes.
16+
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2
17+
GOPROXY: https://goproxy1.cncf.selfactuated.dev,direct
18+
19+
# Do not cancel this workflow on main. See https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/16616
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
darwin-build-unittest-binary:
26+
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }}
27+
runs-on: macos-14
28+
timeout-minutes: 120
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-go@v5
32+
with:
33+
go-version: "~1.22.5"
34+
cache: false
35+
- name: Cache Go
36+
id: go-cache
37+
timeout-minutes: 5
38+
uses: actions/cache@v4
39+
with:
40+
path: |
41+
~/go/bin
42+
~/go/pkg/mod
43+
key: go-build-cache-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
44+
- name: Install dependencies
45+
if: steps.go-cache.outputs.cache-hit != 'true'
46+
run: make -j2 gomoddownload
47+
- name: Install Tools
48+
if: steps.go-cache.outputs.cache-hit != 'true'
49+
run: make install-tools
50+
- name: Build test binaries
51+
env:
52+
GOTESTARCH: amd64
53+
run: make gobuildtest GROUP=cgo
54+
- name: Zip test binaries
55+
run: zip -r testbinaries.zip . --include \*builtunitetest.test
56+
- uses: actions/upload-artifact@v4
57+
with:
58+
name: testbinaries
59+
path: ./testbinaries.zip
60+
retention-days: 1
61+
darwin-unittest-matrix:
62+
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }}
63+
needs: [darwin-build-unittest-binary]
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
os: [macos-12, macos-13]
68+
timeout-minutes: 30
69+
runs-on: ${{ matrix.os }}
70+
steps:
71+
- uses: actions/checkout@v4
72+
- uses: actions/setup-go@v5
73+
with:
74+
go-version: "~1.22.5"
75+
cache: false
76+
- name: Install Tools
77+
if: steps.go-cache.outputs.cache-hit != 'true'
78+
run: make install-tools
79+
- uses: actions/download-artifact@v4
80+
with:
81+
name: testbinaries
82+
- name: Unzip binaries to each module
83+
run: unzip testbinaries.zip
84+
- name: Run Unit Tests
85+
run: make -j2 gorunbuilttest GROUP=cgo
86+
darwin-unittest:
87+
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }}
88+
runs-on: macos-latest
89+
needs: [darwin-unittest-matrix]
90+
steps:
91+
- name: Print result
92+
run: echo ${{ needs.darwin-unittest-matrix.result }}
93+
- name: Interpret result
94+
run: |
95+
if [[ success == ${{ needs.darwin-unittest-matrix.result }} ]]
96+
then
97+
echo "All matrix jobs passed!"
98+
else
99+
echo "One or more matrix jobs failed."
100+
false
101+
fi

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CMD_MODS_1 := $(shell find ./cmd/[n-z]* $(FIND_MOD_ARGS) -not -path "./cmd/otel*
5151
CMD_MODS := $(CMD_MODS_0) $(CMD_MODS_1)
5252
OTHER_MODS := $(shell find . $(EX_COMPONENTS) $(EX_INTERNAL) $(EX_PKG) $(EX_CMD) $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) ) $(PWD)
5353
ALL_MODS := $(RECEIVER_MODS) $(PROCESSOR_MODS) $(EXPORTER_MODS) $(EXTENSION_MODS) $(CONNECTOR_MODS) $(INTERNAL_MODS) $(PKG_MODS) $(CMD_MODS) $(OTHER_MODS)
54+
CGO_MODS := ./receiver/hostmetricsreceiver
5455

5556
FIND_INTEGRATION_TEST_MODS={ find . -type f -name "*integration_test.go" & find . -type f -name "*e2e_test.go" -not -path "./testbed/*"; }
5657
INTEGRATION_MODS := $(shell $(FIND_INTEGRATION_TEST_MODS) | xargs $(TO_MOD_DIR) | uniq)
@@ -135,6 +136,14 @@ gotest-with-cover:
135136
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="test-with-cover"
136137
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./$(GROUP)-coverage.txt
137138

139+
.PHONY: gobuildtest
140+
gobuildtest:
141+
$(MAKE) $(FOR_GROUP_TARGET) TARGET="buildtest"
142+
143+
.PHONY: gorunbuilttest
144+
gorunbuilttest:
145+
$(MAKE) $(FOR_GROUP_TARGET) TARGET="runbuilttest"
146+
138147
.PHONY: gointegration-test
139148
gointegration-test:
140149
$(MAKE) $(FOR_GROUP_TARGET) TARGET="mod-integration-test"
@@ -260,6 +269,9 @@ for-other-target: $(OTHER_MODS)
260269
.PHONY: for-integration-target
261270
for-integration-target: $(INTEGRATION_MODS)
262271

272+
.PHONY: for-cgo-target
273+
for-cgo-target: $(CGO_MODS)
274+
263275
# Debugging target, which helps to quickly determine whether for-all-target is working or not.
264276
.PHONY: all-pwd
265277
all-pwd:
@@ -539,6 +551,8 @@ clean:
539551
find . -type f -name 'coverage.out' -delete
540552
find . -type f -name 'integration-coverage.txt' -delete
541553
find . -type f -name 'integration-coverage.html' -delete
554+
@echo "Removing built binary files"
555+
find . -type f -name 'builtunitetest.test' -delete
542556

543557
.PHONY: generate-gh-issue-templates
544558
generate-gh-issue-templates:

Makefile.Common

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ GOTEST_OPT_WITH_INTEGRATION_COVERAGE=$(GOTEST_OPT_WITH_INTEGRATION) -coverprofil
3636
GOCMD?= go
3737
GOOS=$(shell $(GOCMD) env GOOS)
3838
GOARCH=$(shell $(GOCMD) env GOARCH)
39+
GOTESTARCH?=$(GOARCH)
3940

4041
# In order to help reduce toil related to managing tooling for the open telemetry collector
4142
# this section of the makefile looks at only requiring command definitions to be defined
@@ -140,6 +141,18 @@ do-unit-tests-with-cover: $(GOTESTSUM)
140141
$(GOTESTSUM) $(GOTESTSUM_OPT) --packages="./..." -- $(GOTEST_OPT_WITH_COVERAGE)
141142
$(GOCMD) tool cover -html=coverage.txt -o coverage.html
142143

144+
.PHONY: buildtest
145+
buildtest:
146+
ifneq (,$(wildcard ./*.go))
147+
GOARCH=$(GOTESTARCH) CGO_ENABLED=1 $(GOCMD) test -c -o builtunitetest.test
148+
endif
149+
150+
.PHONY: runbuilttest
151+
runbuilttest: $(GOTESTSUM)
152+
ifneq (,$(wildcard ./builtunitetest.test))
153+
$(GOTESTSUM) --raw-command -- $(GOCMD) tool test2json -p "./..." -t ./builtunitetest.test -test.v -test.failfast -test.timeout $(GOTEST_TIMEOUT)
154+
endif
155+
143156
.PHONY: mod-integration-test
144157
mod-integration-test: $(GOTESTSUM)
145158
@echo "running $(GOCMD) integration test ./... in `pwd`"

0 commit comments

Comments
 (0)