Skip to content

Commit

Permalink
ci(test): test with CGO_ENABLED 0/1
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jun 30, 2024
1 parent f38b855 commit 8346848
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 298 deletions.
68 changes: 44 additions & 24 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
1.22.x,
]
os: [ubuntu-latest, macos-12, macos-14, windows-latest]
cgo: [0,1]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand All @@ -38,6 +39,9 @@ jobs:
with:
distribution: 'zulu'
java-version: '17'
- name: "Set CGO_ENABLED: ${{ matrix.cgo }}"
run: |
"CGO_ENABLED=${{ matrix.cgo }}" >> $env:GITHUB_ENV
- if: matrix.os == 'macos-14'
run: brew install protobuf
- name: Test
Expand Down Expand Up @@ -85,6 +89,7 @@ jobs:
variant:
- debian
- alpine
cgo: [0,1]
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
Expand All @@ -93,32 +98,47 @@ jobs:
with:
platforms: ${{ matrix.arch }}

- name: Build ${{ matrix.arch }} dockerfile
run: |
docker build \
--platform ${{ matrix.arch }} \
--build-arg VERSION=${{ matrix.go-version }} \
-f Dockerfile.${{ matrix.variant }} \
-t pactfoundation/pact-go-test-${{ matrix.go-version }} .
- name: Test (unit)
run: make docker_test
env:
DOCKER_ARCH: ${{ matrix.arch }}
GO_VERSION: ${{ matrix.go-version }}
VARIANT: ${{ matrix.variant }}
CGO_ENABLED: ${{ matrix.cgo }}
- name: Test (pact)
run: make docker_pact
env:
DOCKER_ARCH: ${{ matrix.arch }}
GO_VERSION: ${{ matrix.go-version }}
VARIANT: ${{ matrix.variant }}
CGO_ENABLED: ${{ matrix.cgo }}

# - name: Build ${{ matrix.arch }} dockerfile
# run: |
# docker build \
# --platform ${{ matrix.arch }} \
# --build-arg VERSION=${{ matrix.go-version }} \
# -f Dockerfile.${{ matrix.variant }} \
# -t pactfoundation/pact-go-test-${{ matrix.go-version }} .

- name: Test - ${{ matrix.arch }}
if: matrix.arch == 'amd64'
run: |
docker run \
--platform linux/${{ matrix.arch }} \
-e LOG_LEVEL=${{ env.LOG_LEVEL }} \
-e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \
--rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local'
# - name: Test - ${{ matrix.arch }}
# if: matrix.arch == 'amd64'
# run: |
# docker run \
# --platform linux/${{ matrix.arch }} \
# -e LOG_LEVEL=${{ env.LOG_LEVEL }} \
# -e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \
# --rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local'

- name: Test - ${{ matrix.arch }}
if: matrix.arch == 'arm64'
run: |
docker run \
--platform linux/${{ matrix.arch }} \
-e LOG_LEVEL=${{ env.LOG_LEVEL }} \
-e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \
-e SKIP_RACE=true \
--rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local'
# - name: Test - ${{ matrix.arch }}
# if: matrix.arch == 'arm64'
# run: |
# docker run \
# --platform linux/${{ matrix.arch }} \
# -e LOG_LEVEL=${{ env.LOG_LEVEL }} \
# -e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \
# -e SKIP_RACE=true \
# --rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local'

finish:
needs: [test,test-containers]
Expand Down
30 changes: 22 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ PACT_DOWNLOAD_DIR=/tmp
ifeq ($(OS),Windows_NT)
PACT_DOWNLOAD_DIR=$$TMP
endif

CGO_ENABLED?=1
ifeq ($(CGO_ENABLED),0)
SKIP_RACE=true
endif
SKIP_RACE?=false
DOCKER_ARCH?=arm64
# 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 All @@ -41,22 +46,31 @@ docker_build:

docker_test: docker_build
docker run \
--platform linux/$(DOCKER_ARCH) \
-e LOG_LEVEL=INFO \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
-it \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
/bin/sh -c "make test"
docker_pact: docker_build
docker run \
--platform linux/$(DOCKER_ARCH) \
-e LOG_LEVEL=INFO \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
-it \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
/bin/sh -c "make pact_local"
docker_shell: docker_build
docker run \
--platform linux/$(DOCKER_ARCH) \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
-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 @@ -117,13 +131,13 @@ install: bin

pact: clean install docker
@echo "--- 🔨 Running Pact examples"
go test -v $(SKIP_RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
go test -v $(RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
make publish
go test -v $(SKIP_RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...
pact_local: clean download_plugins install
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 $(SKIP_RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
SKIP_PUBLISH=true go test -v $(SKIP_RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/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/...

publish:
@echo "-- 📃 Publishing pacts"
Expand All @@ -133,9 +147,9 @@ release:
echo "--- 🚀 Releasing it"
"$(CURDIR)/scripts/release.sh"

RACE?='-race'
RACE?=-race

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

Expand Down
Loading

0 comments on commit 8346848

Please sign in to comment.