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

Feat/purego #455

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ jobs:
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# ignore the lib.go file as it only contains cgo annotations
args: --skip-files internal/native/lib.go --timeout 2m
args: --timeout 2m

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
40 changes: 32 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
on: [push, pull_request, workflow_dispatch]
on:
push:
pull_request:
workflow_dispatch:
inputs:
log_level:
description: 'Log level'
type: choice
required: true
default: 'INFO'
options:
- 'INFO'
- 'DEBUG'
- 'TRACE'

name: Test

env:
Expand All @@ -7,9 +21,9 @@ 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: ${{ github.event.inputs.log_level || 'INFO' }}
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
Expand All @@ -26,6 +40,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,16 +53,23 @@ 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
if: matrix.os == 'ubuntu-latest'
run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make
- name: Set CGO_LDFLAGS / pact_ffi lib on PATH
- name: Set PACT_LD_LIBRARY_PATH
if: matrix.os == 'windows-latest'
run: |
"CGO_LDFLAGS=-L$env:TMP" >> $env:GITHUB_ENV
"$env:TMP" >> $env:GITHUB_PATH
"PACT_LD_LIBRARY_PATH=$env:TMP" >> $env:GITHUB_ENV
- name: Test (unit)
if: matrix.os != 'ubuntu-latest'
run: make test
Expand All @@ -62,24 +84,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
4 changes: 2 additions & 2 deletions examples/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var requestFilterCalled = false
var stateHandlerCalled = false

func TestV3HTTPProvider(t *testing.T) {
log.SetLogLevel("TRACE")
log.SetLogLevel("INFO")
version.CheckVersion()

// Start provider API in the background
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestV3HTTPProvider(t *testing.T) {
}

func TestV3MessageProvider(t *testing.T) {
log.SetLogLevel("TRACE")
log.SetLogLevel("INFO")
var user *User

verifier := provider.NewVerifier()
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