Skip to content

Commit

Permalink
feat: support CGO_ENABLED=0 - see notes
Browse files Browse the repository at this point in the history
users now required to set PACT_LD_LIBRARY_PATH env var with
location of download pact ffi lib.

It can exist anywhere on the filesystem
  • Loading branch information
YOU54F committed Sep 5, 2024
1 parent a1e63fc commit 110e625
Show file tree
Hide file tree
Showing 11 changed files with 825 additions and 409 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ env:
REACT_APP_API_BASE_URL: http://localhost:8080
APP_SHA: ${{ github.sha }}
APP_REF: ${{ github.ref }}
LD_LIBRARY_PATH: /tmp
PACT_GO_LIB_DOWNLOAD_PATH: /tmp
LOG_LEVEL: debug
PACT_LD_LIBRARY_PATH: /tmp
LOG_LEVEL: DEBUG
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
Expand All @@ -26,6 +25,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 +38,14 @@ jobs:
with:
distribution: 'zulu'
java-version: '17'
- name: "Set CGO_ENABLED: ${{ matrix.cgo }}"
if: matrix.os == 'windows-latest'
run: |
"CGO_ENABLED=${{ matrix.cgo }}" >> $env:GITHUB_ENV
- name: "Set CGO_ENABLED: ${{ matrix.cgo }}"
if: matrix.os != 'windows-latest'
run: |
echo "CGO_ENABLED=${{ matrix.cgo }}" >> $GITHUB_ENV
- if: matrix.os == 'macos-14'
run: brew install protobuf
- name: Test
Expand All @@ -62,24 +70,26 @@ jobs:
run: goveralls -coverprofile=coverage.txt -service=github -parallel
- uses: actions/upload-artifact@v4
with:
name: logs-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.go-version }}-${{ matrix.os }}.zip
name: logs-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.go-version }}-${{ matrix.os }}-${{matrix.cgo}}.zip
path: ~/.pact/plugins/**/plugin.log
if: ${{ always() }}

test-containers:
runs-on: ubuntu-latest
name: ${{ matrix.go-version }}-test-container
name: ${{ matrix.go-version }}-test-container-cgo-${{ matrix.cgo }}
strategy:
fail-fast: false
matrix:
go-version: ["1.21", "1.22"]
cgo: [0,1]
steps:
- uses: actions/checkout@v4

- name: Test dockerfile
run: make docker_test_all
env:
GO_VERSION: ${{ matrix.go-version }}
CGO_ENABLED: ${{ matrix.cgo }}

finish:
needs: [test,test-containers]
Expand Down
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ ifeq ($(OS),Windows_NT)
PACT_DOWNLOAD_DIR=$$TMP
endif

CGO_ENABLED?=1
ifeq ($(CGO_ENABLED),0)
SKIP_RACE=true
endif
SKIP_RACE?=false
RACE?=-race
SKIP_SIGNAL_HANDLERS?=false
ifeq ($(SKIP_RACE),true)
RACE=
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 All @@ -41,18 +51,24 @@ docker_build:
docker_test: docker_build
docker run \
-e LOG_LEVEL=INFO \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
pactfoundation/pact-go-test \
/bin/sh -c "make test"
docker_pact: docker_build
docker run \
-e LOG_LEVEL=INFO \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
pactfoundation/pact-go-test \
/bin/sh -c "make pact_local"
docker_test_all: docker_build
docker run \
-e LOG_LEVEL=INFO \
-e CGO_ENABLED=$(CGO_ENABLED) \
-e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \
--rm \
pactfoundation/pact-go-test \
/bin/sh -c "make test && make pact_local"
Expand Down Expand Up @@ -130,7 +146,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; \
go test -v $(RACE) -coverprofile=profile.out -covermode=atomic $$d; \
if [ $$? != 0 ]; then \
exit 1; \
fi; \
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ module github.com/pact-foundation/pact-go/v2
go 1.21

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
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.21.0
google.golang.org/grpc v1.66.0
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -24,7 +26,6 @@ require (
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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=
Expand Down
2 changes: 1 addition & 1 deletion installer/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestNativeLibPath(t *testing.T) {
libFilePath := filepath.Join(lib, "lib.go")
file, err := os.ReadFile(libFilePath)
assert.NoError(t, err)
assert.Contains(t, string(file), "-lpact_ffi")
assert.Contains(t, string(file), "libpact_ffi")
}

// 1. Be able to specify the path of the binary in advance
Expand Down
Loading

0 comments on commit 110e625

Please sign in to comment.