Skip to content
Open
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
8 changes: 1 addition & 7 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ jobs:
fail-fast: false
matrix:
go-version: [
# 1.19.x, # Ended 06 Sep 2023
# 1.20.x, # Ended 06 Feb 2024
# 1.21.x, # Ended 13 Aug 2024
# 1.22.x, # Ended 11 Feb 2025
1.23.x,
1.24.x,
1.25.x,
]
Expand All @@ -41,8 +36,7 @@ jobs:
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# ignore the lib.go file as it only contains cgo annotations
args: --exclude-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
59 changes: 31 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ on:
description: 'Skip alpine provider tests'
required: false
default: 'false'

log_level:
description: 'Log level'
type: choice
required: true
default: 'INFO'
options:
- 'INFO'
- 'DEBUG'
- 'TRACE'
env:
PACT_BROKER_BASE_URL: https://testdemo.pactflow.io
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
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_GO_LIB_DOWNLOAD_PATH: /tmp
# PACT_LD_LIBRARY_PATH: /tmp
LOG_LEVEL: ${{ github.event.inputs.log_level || 'INFO' }}
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
Expand All @@ -31,17 +39,11 @@ jobs:
fail-fast: false
matrix:
go-version: [ # https://endoflife.date/go
# 1.17.x, # Ended 02 Aug 2022
# 1.18.x, # Ended 01 Feb 2023
# 1.19.x, # Ended 06 Sep 2023
# 1.20.x, # Ended 06 Feb 2024
# 1.21.x, # Ended 13 Aug 2024
# 1.22.x, # Ended 11 Feb 2025
1.23.x,
1.24.x,
1.25.x,
]
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
os: [ubuntu-latest, macos-15, macos-15-intel, windows-latest]
cgo: [0,1]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand All @@ -54,16 +56,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
if: matrix.os == 'windows-latest'
run: |
"CGO_LDFLAGS=-L$env:TMP" >> $env:GITHUB_ENV
"$env:TMP" >> $env:GITHUB_PATH
# - name: Set PACT_LD_LIBRARY_PATH
# if: matrix.os == 'windows-latest'
# run: |
# "PACT_LD_LIBRARY_PATH=$env:TMP" >> $env:GITHUB_ENV
- name: Test (unit)
if: matrix.os != 'ubuntu-latest'
run: make test
Expand All @@ -78,26 +87,23 @@ jobs:
run: goveralls -coverprofile=coverage.txt -service=github -parallel
- uses: actions/upload-artifact@v5
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:
continue-on-error: ${{ matrix.experimental }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}-${{ matrix.variant }}-${{ matrix.go-version }}-test-container
name: ${{ matrix.os }}-${{ matrix.variant }}-${{ matrix.go-version }}-test-container-cgo-${{ matrix.cgo }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm]
go-version: ["1.23", "1.24", "1.25"]
go-version: ["1.24", "1.25"]
variant: [debian]
experimental: [false]
cgo: [0,1]
include:
- variant: alpine
go-version: 1.23
experimental: true
os: ubuntu-latest
- variant: alpine
go-version: 1.24
experimental: true
Expand All @@ -106,10 +112,6 @@ jobs:
go-version: 1.25
experimental: true
os: ubuntu-latest
- variant: alpine
go-version: 1.23
experimental: true
os: ubuntu-24.04-arm
- variant: alpine
go-version: 1.24
experimental: true
Expand All @@ -133,6 +135,7 @@ jobs:
env:
GO_VERSION: ${{ matrix.go-version }}
IMAGE_VARIANT: ${{ matrix.variant }}
CGO_ENABLED: ${{ matrix.cgo }}

finish:
needs: [test,test-containers]
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG VERSION=1.23
FROM golang:${VERSION}-alpine
ARG GO_VERSION=1.24
FROM golang:${GO_VERSION}-alpine

RUN apk add --no-cache curl gcc musl-dev gzip openjdk17-jre bash protoc protobuf-dev make file

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG VERSION=latest
FROM golang:${VERSION}
ARG GO_VERSION=latest
FROM golang:${GO_VERSION}

RUN apt-get update && apt-get install -y openjdk-21-jre file protobuf-compiler
COPY . /go/src/github.com/pact-foundation/pact-go
Expand Down
35 changes: 22 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ PLUGIN_PACT_CSV_VERSION=0.0.6
PLUGIN_PACT_MATT_VERSION=0.1.1
PLUGIN_PACT_AVRO_VERSION=0.0.6

GO_VERSION?=1.23
GO_VERSION?=1.24
IMAGE_VARIANT?=debian
ci:: docker deps clean bin test pact
PACT_DOWNLOAD_DIR=/tmp
ifeq ($(OS),Windows_NT)
PACT_DOWNLOAD_DIR=$$TMP
# 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
RACE?=-race
SKIP_SIGNAL_HANDLERS?=false
ifeq ($(SKIP_RACE),true)
RACE=
endif
Expand Down Expand Up @@ -49,6 +55,7 @@ docker_test: docker_build
-e LOG_LEVEL=INFO \
-e SKIP_PROVIDER_TESTS=$(SKIP_PROVIDER_TESTS) \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
--rm \
-it \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
Expand All @@ -58,6 +65,7 @@ docker_pact: docker_build
-e LOG_LEVEL=INFO \
-e SKIP_PROVIDER_TESTS=$(SKIP_PROVIDER_TESTS) \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
--rm \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
/bin/sh -c "make pact_local"
Expand All @@ -66,6 +74,7 @@ docker_test_all: docker_build
-e LOG_LEVEL=INFO \
-e SKIP_PROVIDER_TESTS=$(SKIP_PROVIDER_TESTS) \
-e SKIP_RACE=$(SKIP_RACE) \
-e CGO_ENABLED=$(CGO_ENABLED) \
--rm \
pactfoundation/pact-go-test-$(IMAGE_VARIANT) \
/bin/sh -c "make test && make pact_local"
Expand Down Expand Up @@ -117,18 +126,18 @@ cli:

install: bin
echo "--- 🐿 Installing Pact FFI dependencies"
./build/pact-go -l DEBUG install --libDir $(PACT_DOWNLOAD_DIR)
./build/pact-go -l DEBUG install

pact: clean install docker
@echo "--- 🔨 Running Pact examples"
go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
./build/pact-go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
make publish
go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...
./build/pact-go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...
pact_local: clean download_plugins install
@echo "--- 🔨 Running Pact examples"
go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
./build/pact-go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/...
if [ "$(SKIP_PROVIDER_TESTS)" != "true" ]; then \
SKIP_PUBLISH=true go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...; \
SKIP_PUBLISH=true ./build/pact-go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...; \
fi

publish:
Expand All @@ -151,7 +160,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 $(PROVIDER_TEST_TAGS) -covermode=atomic $$d; \
./build/pact-go test -v $(RACE) -coverprofile=profile.out $(PROVIDER_TEST_TAGS) -covermode=atomic $$d; \
if [ $$? != 0 ]; then \
exit 1; \
fi; \
Expand All @@ -164,7 +173,7 @@ test: deps install


testrace:
go test $(RACE) $(TEST) $(TESTARGS)
./build/pact-go test $(RACE) $(TEST) $(TESTARGS)

updatedeps:
go get -d -v -p 2 ./...
Expand All @@ -182,5 +191,5 @@ protos:
.PHONY: grpc-test
grpc-test:
rm -rf ./examples/pacts
go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/grpc
go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/grpc
./build/pact-go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/grpc
./build/pact-go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/grpc
53 changes: 6 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ go install github.com/pact-foundation/pact-go/v2
pact-go -l DEBUG install

# 🚀 now write some tests!
pact-go test
# pact-go test is a wrapper around go test, and sets the PACT_LD_LIBRARY_PATH environment variable to the pact required libraries
```

If the `pact-go` command above is not found, make sure that `$GOPATH/bin` is in your path. I.e.,
Expand All @@ -100,56 +102,14 @@ export PATH=$PATH:$GOPATH/bin

You can also keep the library versions up to date by running the `version.CheckVersion()` function.

Set `PACT_GO_LIB_DOWNLOAD_PATH` env var if you have installed the library in a non-standard location.

<details><summary>Pre-Requisites</summary>

### Pre-Requisites

- `cgo`
- Pact relies on C shared libraries compiled from Rust
- `CGO_ENABLED=1` (check with `go env`)

#### Linux

- Install `gcc` package

#### MacOS

- Install the Xcode Command line tools

By default, pact-go install will attempt to install in `/usr/local/lib`.

Note this is not user-writable, so `pact-go install` must be run with `sudo`.

An alternative is to install to `/tmp` via `pact-go -l DEBUG install --libDir /tmp`

#### Windows

- Install `gcc`
- `choco install mingw`
- `scoop install mingw`

- Add location of the pact-go installed shared library to
- `PATH`
- `CGO_LDFLAGS`

##### Powershell

- `$env:Path += ";$env:TMP"`
- `$env:CGO_LDFLAGS = "-L$env:TMP"`

- Command Prompt
- `set PATH="%PATH%;%TMP%"`
- `set CGO_LDFLAGS="-L%TMP%"`

</details>
- Set `PACT_GO_LIB_DOWNLOAD_PATH` env var if you have installed the library in a non-standard location.
- Set `PACT_LD_LIBRARY_PATH` env var if you have installed the library in a non-standard location and are running `go test` directly without the `pact-go test` wrapper.

<details><summary>Manual Installation Instructions</summary>

### Manual

Download the latest `Pact FFI Library` [library] for your OS, and install onto a standard library search path (we suggest: `/usr/local/lib` on MacOS/Linux):
Download the latest `Pact FFI Library` [library] for your OS.

Ensure you have the correct extension for your OS:

Expand All @@ -160,13 +120,12 @@ Ensure you have the correct extension for your OS:
```sh
wget https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v0.4.21/libpact_ffi-macos-x86_64.dylib.gz
gunzip libpact_ffi-macos-x86_64.dylib.gz
mv libpact_ffi-macos-x86_64.dylib /usr/local/lib/libpact_ffi.dylib
```

Test the installation:

```sh
pact-go help
PACT_LD_LIBRARY_PATH=${PATH_TO_LIB} pact-go check
```

</details>
Expand Down
2 changes: 1 addition & 1 deletion command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var checkCmd = &cobra.Command{
log.Println("[INFO] set lib dir target to", libDir)
i.SetLibDir(libDir)
}

if err = i.CheckPackageInstall(); err != nil {
log.Println("[DEBUG] error from CheckPackageInstall:", err)
log.Println("[ERROR] Your Pact library installation is out of date. Run `pact-go install` to correct")
Expand Down
2 changes: 2 additions & 0 deletions command/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var installCmd = &cobra.Command{
log.Println("[ERROR] Your Pact library installation is out of date and we were unable to download a newer one for you:", err)
os.Exit(1)
}

i.SetConfigLibDir(i.GetActualLibDir())
},
}

Expand Down
Loading