Skip to content

Commit

Permalink
ci(test): enable plugin tests if we can install signal handlers
Browse files Browse the repository at this point in the history
cgo + unix/macos (not alpine)
  • Loading branch information
YOU54F committed Jun 30, 2024
1 parent 1d10f49 commit 88cbb0b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
with:
distribution: 'zulu'
java-version: '17'
- name: "Set RUN_PLUGIN_TESTS if we can install signal handlers (cgo + linux/macos - non musl)"
if: matrix.os != 'windows-latest'
run: |
if [[ "${{ matrix.cgo }}" == 1 ]]; then
echo "RUN_PLUGIN_TESTS=true" >> $GITHUB_ENV
fi
- name: "Set CGO_ENABLED: ${{ matrix.cgo }}"
if: matrix.os == 'windows-latest'
run: |
Expand Down Expand Up @@ -102,21 +108,27 @@ jobs:
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ matrix.arch }}

- name: "Set RUN_PLUGIN_TESTS if we can install signal handlers (cgo + debian)"
run: |
if [[ "${{ matrix.cgo }}" == 1 && "${{ matrix.variant }}" == 'debian' ]]; then
echo "RUN_PLUGIN_TESTS=true" >> $GITHUB_ENV
fi
- name: Test (unit)
run: make docker_test
env:
DOCKER_ARCH: ${{ matrix.arch }}
GO_VERSION: ${{ matrix.go-version }}
IMAGE_VARIANT: ${{ matrix.variant }}
CGO_ENABLED: ${{ matrix.cgo }}
RUN_PLUGIN_TESTS: ${{ env.RUN_PLUGIN_TESTS }}
- name: Test (pact)
run: make docker_pact
env:
DOCKER_ARCH: ${{ matrix.arch }}
GO_VERSION: ${{ matrix.go-version }}
IMAGE_VARIANT: ${{ matrix.variant }}
CGO_ENABLED: ${{ matrix.cgo }}
RUN_PLUGIN_TESTS: ${{ env.RUN_PLUGIN_TESTS }}

# - name: Build ${{ matrix.arch }} dockerfile
# run: |
Expand Down
29 changes: 22 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ ifeq ($(CGO_ENABLED),0)
endif
SKIP_RACE?=false
DOCKER_ARCH?=arm64
RACE?=-race
TEST_TAGS?=
RUN_PLUGIN_TESTS?=
PLUGIN_TAG=
PLUGIN_TAGS=
SKIP_SIGNAL_HANDLERS?=false
ifeq ($(SKIP_RACE),true)
RACE=
endif
ifeq ($(RUN_PLUGIN_TESTS),true)
PLUGIN_TAGS=-tags=plugin
PLUGIN_TAG=,plugin
endif
# Run the ci target from a developer machine with the environment variables
# set as if it was on Travis CI.
# Use this for quick feedback when playing around with your workflows.
Expand Down Expand Up @@ -50,6 +63,8 @@ docker_test: docker_build
-e LOG_LEVEL=INFO \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e RUN_PLUGIN_TESTS=$(RUN_PLUGIN_TESTS) \
-e SKIP_SIGNAL_HANDLERS=$(SKIP_SIGNAL_HANDLERS) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
Expand All @@ -60,6 +75,8 @@ docker_pact: docker_build
-e LOG_LEVEL=INFO \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e RUN_PLUGIN_TESTS=$(RUN_PLUGIN_TESTS) \
-e SKIP_SIGNAL_HANDLERS=$(SKIP_SIGNAL_HANDLERS) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
Expand All @@ -69,6 +86,8 @@ docker_shell: docker_build
--platform linux/$(DOCKER_ARCH) \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e RUN_PLUGIN_TESTS=$(RUN_PLUGIN_TESTS) \
-e SKIP_SIGNAL_HANDLERS=$(SKIP_SIGNAL_HANDLERS) \
-e LOG_LEVEL=INFO \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
-v $$PWD:/go/src/github.com/pact-foundation/pact-go \
Expand Down Expand Up @@ -134,8 +153,8 @@ pact: clean install docker
go test -v $(RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...
pact_local: clean deps install
@echo "--- 🔨 Running Pact examples"
go test -v $(RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
SKIP_PUBLISH=true go test -v $(RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...
go test -v $(RACE) -tags=consumer$(PLUGIN_TAG) -count=1 github.com/pact-foundation/pact-go/v2/examples/...
SKIP_PUBLISH=true go test -v $(RACE) -timeout=30s -tags=provider$(PLUGIN_TAG) -count=1 github.com/pact-foundation/pact-go/v2/examples/...

publish:
@echo "-- 📃 Publishing pacts"
Expand All @@ -145,11 +164,7 @@ release:
echo "--- 🚀 Releasing it"
"$(CURDIR)/scripts/release.sh"

RACE?=-race

ifeq ($(SKIP_RACE),true)
RACE=
endif

ifeq ($(OS),Windows_NT)
SKIP_TESTS+= --test.skip TestHandleBasedMessageTestsWithBinary
Expand All @@ -161,7 +176,7 @@ test: deps install
@echo "mode: count" > coverage.txt
@for d in $$(go list ./... | grep -v vendor | grep -v examples); \
do \
go test -v $(RACE) -coverprofile=profile.out -covermode=atomic $$d $(SKIP_TESTS); \
go test -v $(RACE) -coverprofile=profile.out -covermode=atomic $$d $(SKIP_TESTS) $(PLUGIN_TAGS); \
if [ $$? != 0 ]; then \
exit 1; \
fi; \
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/ebitengine/purego v0.7.1
github.com/golang/protobuf v1.5.4
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/logutils v1.0.0
github.com/linkedin/goavro/v2 v2.13.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA=
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
Expand Down
13 changes: 9 additions & 4 deletions internal/native/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ static void install_signal_handlers()
#endif
*/
import "C"
import "runtime"
import (
"os"
"runtime"
)

func InstallSignalHandlers() {
if runtime.GOOS != "windows" {
C.install_signal_handlers()
}
if os.Getenv("SKIP_SIGNAL_HANDLERS") != "true" {
if runtime.GOOS != "windows" {
C.install_signal_handlers()
}
}
}

0 comments on commit 88cbb0b

Please sign in to comment.