Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] add cgo test for macos-12 and macos-13 #34741

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/build-and-test-darwin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: build-and-test-darwin
on:
push:
branches: [main]
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
merge_group:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
env:
TEST_RESULTS: testbed/tests/results/junit/results.xml
# Make sure to exit early if cache segment download times out after 2 minutes.
# We limit cache download as a whole to 5 minutes.
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2
GOPROXY: https://goproxy1.cncf.selfactuated.dev,direct

# Do not cancel this workflow on main. See https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/16616
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
darwin-build-unittest-binary:
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }}
runs-on: macos-14
timeout-minutes: 120
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "~1.22.5"
cache: false
- name: Cache Go
id: go-cache
timeout-minutes: 5
uses: actions/cache@v4
with:
path: |
~/go/bin
~/go/pkg/mod
key: go-build-cache-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: Install dependencies
if: steps.go-cache.outputs.cache-hit != 'true'
run: make -j2 gomoddownload
- name: Install Tools
if: steps.go-cache.outputs.cache-hit != 'true'
run: make install-tools
- name: Build test binaries
env:
GOTESTARCH: amd64
run: make gobuildtest GROUP=cgo
- name: Zip test binaries
run: zip -r testbinaries.zip . --include \*builtunitetest.test
- uses: actions/upload-artifact@v4
with:
name: testbinaries
path: ./testbinaries.zip
retention-days: 1
darwin-unittest-matrix:
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }}
needs: [darwin-build-unittest-binary]
strategy:
fail-fast: false
matrix:
os: [macos-12, macos-13]
timeout-minutes: 30
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "~1.22.5"
cache: false
- name: Install Tools
if: steps.go-cache.outputs.cache-hit != 'true'
run: make install-tools
- uses: actions/download-artifact@v4
with:
name: testbinaries
- name: Unzip binaries to each module
run: unzip testbinaries.zip
- name: Run Unit Tests
run: make -j2 gorunbuilttest GROUP=cgo
darwin-unittest:
if: ${{ github.actor != 'dependabot[bot]' && (contains(github.event.pull_request.labels.*.name, 'Run Darwin') || github.event_name == 'push' || github.event_name == 'merge_group') }}
runs-on: macos-latest
needs: [darwin-unittest-matrix]
steps:
- name: Print result
run: echo ${{ needs.darwin-unittest-matrix.result }}
- name: Interpret result
run: |
if [[ success == ${{ needs.darwin-unittest-matrix.result }} ]]
then
echo "All matrix jobs passed!"
else
echo "One or more matrix jobs failed."
false
fi
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CMD_MODS_1 := $(shell find ./cmd/[n-z]* $(FIND_MOD_ARGS) -not -path "./cmd/otelc
CMD_MODS := $(CMD_MODS_0) $(CMD_MODS_1)
OTHER_MODS := $(shell find . $(EX_COMPONENTS) $(EX_INTERNAL) $(EX_PKG) $(EX_CMD) $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) ) $(PWD)
ALL_MODS := $(RECEIVER_MODS) $(PROCESSOR_MODS) $(EXPORTER_MODS) $(EXTENSION_MODS) $(CONNECTOR_MODS) $(INTERNAL_MODS) $(PKG_MODS) $(CMD_MODS) $(OTHER_MODS)
CGO_MODS := ./receiver/hostmetricsreceiver

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

.PHONY: gobuildtest
gobuildtest:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="buildtest"

.PHONY: gorunbuilttest
gorunbuilttest:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="runbuilttest"

.PHONY: gointegration-test
gointegration-test:
$(MAKE) $(FOR_GROUP_TARGET) TARGET="mod-integration-test"
Expand Down Expand Up @@ -256,6 +265,9 @@ for-other-target: $(OTHER_MODS)
.PHONY: for-integration-target
for-integration-target: $(INTEGRATION_MODS)

.PHONY: for-cgo-target
for-cgo-target: $(CGO_MODS)

# Debugging target, which helps to quickly determine whether for-all-target is working or not.
.PHONY: all-pwd
all-pwd:
Expand Down Expand Up @@ -536,6 +548,8 @@ clean:
find . -type f -name 'coverage.out' -delete
find . -type f -name 'integration-coverage.txt' -delete
find . -type f -name 'integration-coverage.html' -delete
@echo "Removing built binary files"
find . -type f -name 'builtunitetest.test' -delete

.PHONY: generate-gh-issue-templates
generate-gh-issue-templates:
Expand Down
13 changes: 13 additions & 0 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GOTEST_OPT_WITH_INTEGRATION_COVERAGE=$(GOTEST_OPT_WITH_INTEGRATION) -coverprofil
GOCMD?= go
GOOS=$(shell $(GOCMD) env GOOS)
GOARCH=$(shell $(GOCMD) env GOARCH)
GOTESTARCH?=$(GOARCH)

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

.PHONY: buildtest
buildtest:
ifneq (,$(wildcard ./*.go))
GOARCH=$(GOTESTARCH) CGO_ENABLED=1 $(GOCMD) test -c -o builtunitetest.test
endif

.PHONY: runbuilttest
runbuilttest: $(GOTESTSUM)
ifneq (,$(wildcard ./builtunitetest.test))
$(GOTESTSUM) --raw-command -- $(GOCMD) tool test2json -p "./..." -t ./builtunitetest.test -test.v -test.failfast -test.timeout $(GOTEST_TIMEOUT)
endif

.PHONY: mod-integration-test
mod-integration-test: $(GOTESTSUM)
@echo "running $(GOCMD) integration test ./... in `pwd`"
Expand Down