From a0d9245afaa9e7350c93c7d16c70b3cfe80ff081 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 14:47:07 +0100 Subject: [PATCH 01/19] x-plat go versions - linux arm64 / macos amd64 + arm64 - golang 1.20.x / 1.21.x / 1.22.x --- .github/workflows/test.yml | 67 ++++++++++++++++--- .gitignore | 5 +- DEVELOPER.md | 52 ++++++++++++++- Dockerfile | 11 ++-- Dockerfile-deb | 9 +++ Makefile | 129 ++++++++++++++++++++++++++++++++++--- docker-compose.yml | 4 +- installer/installer.go | 2 +- make/config.mk | 6 +- scripts/install-cli.sh | 4 ++ scripts/pact.ps1 | 51 ++++++++------- 11 files changed, 284 insertions(+), 56 deletions(-) create mode 100644 Dockerfile-deb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bde9f7c4a..74ad5b34a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,12 +4,11 @@ name: Test 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 + LOG_LEVEL: info COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: @@ -19,11 +18,18 @@ jobs: go-version: [ # https://endoflife.date/go # 1.17.x, # Ended 02 Aug 2022 # 1.18.x, # Ended 01 Feb 2023 - 1.19.x, - 1.20.x, + # 1.19.x, # Ended 8 Aug 2023 + 1.20.x, # Ended 06 Feb 2024 1.21.x + 1.22.x ] - os: [ubuntu-latest] + os: [ + ubuntu-latest, + # windows-latest, + macos-12, + macos-14 + ] + fail-fast: false runs-on: ${{ matrix.os }} steps: - name: Checkout code @@ -36,15 +42,38 @@ jobs: with: distribution: 'zulu' java-version: '17' - - name: Test - run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make + - run: brew install protobuf + if: matrix.os == 'macos-14' + - name: Unit Test + run: make ci_unit + # - name: Examples with Docker + # if: runner.os == 'Linux' + # run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make ci_examples + - name: Examples with Standalone + run: | + make install-pact-ruby-standalone + APP_BRANCH=${APP_REF:11} PACT_TOOL=standalone make ci_hosted_examples + + # - name: Unit Test + # if: runner.os != 'Linux' + # run: make ci_no_docker + # env: + # SKIP_PLUGIN_AVRO: true + # - name: Unit Test + # if: runner.os == 'Windows' + # run: make test + # env: + # SKIP_PLUGIN_AVRO: true + # LD_LIBRARY_PATH: /tmp - name: Install goveralls run: go install github.com/mattn/goveralls@latest + if: runner.os == 'Linux' - name: Send coverage run: goveralls -coverprofile=coverage.txt -service=github -parallel + if: runner.os == 'Linux' - uses: actions/upload-artifact@v4 with: - name: logs-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.go-version }}.zip + name: logs-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.go-version }}-${{ matrix.os }}.zip path: ~/.pact/plugins/**/plugin.log if: ${{ always() }} @@ -57,3 +86,25 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true + + # test-other-os: + # strategy: + # matrix: + # go-version: [ # https://endoflife.date/go + # 1.19.x, + # 1.20.x, + # 1.21.x + # ] + # os: [macos-latest,windows-latest] + # fail-fast: false + # runs-on: ${{ matrix.os }} + # steps: + # - name: Checkout code + # uses: actions/checkout@v2 + # - name: Install Go + # uses: actions/setup-go@v4 + # with: + # go-version: ${{ matrix.go-version }} + # - run: make test + # env: + # SKIP_PLUGIN_AVRO: true \ No newline at end of file diff --git a/.gitignore b/.gitignore index dddbec92a..86e47afb8 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,7 @@ coverage.txt .vscode # Dependencies -pact \ No newline at end of file +pact + +# pact files +examples/pacts/* \ No newline at end of file diff --git a/DEVELOPER.md b/DEVELOPER.md index a83d7faf7..057196457 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -13,4 +13,54 @@ The previous major version. Only bug fixes and security updates will be consider ### `master` -The `2.x.x` release line. Current major version. \ No newline at end of file +The `2.x.x` release line. Current major version. + + +## Windows on ARM + +WoA is not supported by Pact FFI atm. + +Build errors + +```ps1 +PS W:\> go build -o build/pact-go.exe +error obtaining VCS status: exit status 128 + Use -buildvcs=false to disable VCS stamping. + +``` + +Install ffi + +```ps1 +PS W:\> .\build\pact-go.exe -l DEBUG install --libDir /tmp +2023/10/03 19:02:08 [INFO] set lib dir target to /tmp +2023/10/03 19:02:08 [INFO] package libpact_ffi not found +2023/10/03 19:02:08 [INFO] downloading library from https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v0.4.5/pact_ffi-windows-x86_64.dll.gz to /tmp/pact_ffi.dll +&{} +2023/10/03 19:02:12 [DEBUG] obtaining hash for file /tmp/pact_ffi.dll +2023/10/03 19:02:12 [DEBUG] writing config {map[libpact_ffi:{libpact_ffi 0.4.5 f03507c43328add6e02215740c044988}]} +2023/10/03 19:02:12 [DEBUG] writing yaml config to file libraries: + libpact_ffi: + libname: libpact_ffi + version: 0.4.5 + hash: f03507c43328add6e02215740c044988 + +2023/10/03 19:02:12 [INFO] package libpact_ffi found +2023/10/03 19:02:12 [INFO] checking version 0.4.5 of libpact_ffi against semver constraint >= 0.4.0, < 1.0.0 +2023/10/03 19:02:12 [DEBUG] 0.4.5 satisfies constraints 0.4.5 >= 0.4.0, < 1.0.0 +2023/10/03 19:02:12 [INFO] package libpact_ffi is correctly installed +2023/10/03 19:02:12 [DEBUG] skip checking ffi version() call because FFI not loaded. This is expected when running the 'pact-go' command. +``` + +Some WIP steps + +```ps1 +scoop install go +$env:GOARCH=amd64 +go mod tidy +go build -o build/pact-go.exe -buildvcs=false +.\build\pact-go.exe -l DEBUG install --libDir /tmp +scoop install grep +go list -buildvcs=false ./... | grep -v vendor | grep -v examples +go test -v github.com/pact-foundation/pact-go/v2/installer +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fe6940005..9d275b897 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,9 @@ -FROM golang:1.22.3 +FROM golang:alpine -# Install pact ruby standalone binaries -RUN curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v2.0.3/pact-2.0.3-linux-x86_64.tar.gz; \ - tar -C /usr/local -xzf pact-2.0.3-linux-x86_64.tar.gz; \ - rm pact-2.0.3-linux-x86_64.tar.gz - -ENV PATH /usr/local/pact/bin:$PATH +RUN apk add --no-cache curl gcc musl-dev gzip openjdk17-jre bash protoc protobuf-dev make file COPY . /go/src/github.com/pact-foundation/pact-go WORKDIR /go/src/github.com/pact-foundation/pact-go + +CMD ["make", "test"] \ No newline at end of file diff --git a/Dockerfile-deb b/Dockerfile-deb new file mode 100644 index 000000000..881108f14 --- /dev/null +++ b/Dockerfile-deb @@ -0,0 +1,9 @@ +FROM golang:latest + +RUN apt-get update && apt-get install -y openjdk-17-jre file + +COPY . /go/src/github.com/pact-foundation/pact-go + +WORKDIR /go/src/github.com/pact-foundation/pact-go + +CMD ["make", "test"] \ No newline at end of file diff --git a/Makefile b/Makefile index f604fc0be..ebc3b8317 100755 --- a/Makefile +++ b/Makefile @@ -3,9 +3,15 @@ include make/config.mk TEST?=./... .DEFAULT_GOAL := ci DOCKER_HOST_HTTP?="http://host.docker.internal" -PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli" +# PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli" +ifeq ($(OS),Windows_NT) + EXT=.exe +endif ci:: docker deps clean bin test pact +ci_unit:: deps clean bin test +ci_examples:: docker pact +ci_hosted_examples:: pact # Run the ci target from a developer machine with the environment variables # set as if it was on Travis CI. @@ -39,14 +45,43 @@ deps: download_plugins cd /tmp; \ go install github.com/mitchellh/gox@latest; \ cd - +PLUGIN_PACT_PROTOBUF_VERSION=0.3.13 +PLUGIN_PACT_CSV_VERSION=0.0.1 +PLUGIN_PACT_MATT_VERSION=0.0.9 +PLUGIN_PACT_AVRO_VERSION=0.0.3 download_plugins: @echo "--- 🐿 Installing plugins"; \ - ./scripts/install-cli.sh - ~/.pact/bin/pact-plugin-cli -y install https://github.com/pactflow/pact-protobuf-plugin/releases/tag/v-0.3.13 - ~/.pact/bin/pact-plugin-cli -y install https://github.com/pact-foundation/pact-plugins/releases/tag/csv-plugin-0.0.1 - ~/.pact/bin/pact-plugin-cli -y install https://github.com/mefellows/pact-matt-plugin/releases/tag/v0.0.9 - ~/.pact/bin/pact-plugin-cli -y install https://github.com/austek/pact-avro-plugin/releases/tag/v0.0.3 + if [ -z $$SKIP_PLUGINS ]; then\ + if [ ! -f ~/.pact/bin/pact-plugin-cli ]; then \ + ./scripts/install-cli.sh; \ + else \ + echo "--- 🐿 Pact CLI already installed"; \ + fi; \ + if [ ! -f ~/.pact/plugins/protobuf-$(PLUGIN_PACT_PROTOBUF_VERSION)/pact-protobuf-plugin ]; then \ + ~/.pact/bin/pact-plugin-cli -y install https://github.com/pactflow/pact-protobuf-plugin/releases/tag/v-$(PLUGIN_PACT_PROTOBUF_VERSION); \ + else \ + echo "--- 🐿 Pact protobuf-$(PLUGIN_PACT_PROTOBUF_VERSION) already installed"; \ + fi; \ + if [ ! -f ~/.pact/plugins/csv-$(PLUGIN_PACT_CSV_VERSION)/pact-csv-plugin ]; then \ + ~/.pact/bin/pact-plugin-cli -y install https://github.com/pact-foundation/pact-plugins/releases/tag/csv-plugin-$(PLUGIN_PACT_CSV_VERSION); \ + else \ + echo "--- 🐿 Pact csv-$(PLUGIN_PACT_CSV_VERSION) already installed"; \ + fi; \ + if [ ! -f ~/.pact/plugins/matt-$(PLUGIN_PACT_MATT_VERSION)/matt ]; then \ + ~/.pact/bin/pact-plugin-cli -y install https://github.com/mefellows/pact-matt-plugin/releases/tag/v$(PLUGIN_PACT_MATT_VERSION); \ + else \ + echo "--- 🐿 Pact matt-$(PLUGIN_PACT_MATT_VERSION) already installed"; \ + fi; \ + if [ -z $$SKIP_PLUGIN_AVRO ]; then\ + if [ ! -f ~/.pact/plugins/avro-$(PLUGIN_PACT_AVRO_VERSION)/bin/pact-avro-plugin ]; then \ + ~/.pact/bin/pact-plugin-cli -y install https://github.com/austek/pact-avro-plugin/releases/tag/v$(PLUGIN_PACT_AVRO_VERSION); \ + else \ + echo "--- 🐿 Pact avro-$(PLUGIN_PACT_AVRO_VERSION) already installed"; \ + fi; \ + fi; \ + fi + cli: @if [ ! -d pact/bin ]; then\ @@ -56,9 +91,9 @@ cli: install: bin echo "--- 🐿 Installing Pact FFI dependencies" - ./build/pact-go -l DEBUG install --libDir /tmp + ./build/pact-go -l DEBUG install --libDir /tmp -pact: clean install docker +pact: clean install @echo "--- 🔨 Running Pact examples" go test -v -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/... make publish @@ -66,12 +101,14 @@ pact: clean install docker publish: @echo "-- 📃 Publishing pacts" - @"${PACT_CLI}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod + @"${PACT_BROKER_COMMAND}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod --branch ${APP_BRANCH} release: echo "--- 🚀 Releasing it" "$(CURDIR)/scripts/release.sh" +# @for d in $$(go list -buildvcs=false ./... | grep -v vendor | grep -v examples); + test: deps install @echo "--- ✅ Running tests" @if [ -f coverage.txt ]; then rm coverage.txt; fi; @@ -111,3 +148,77 @@ 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 + +## ===================== +## Multi-platform detection and support +## Pact CLI install/uninstall tasks +## ===================== +SHELL := /bin/bash +PACT_TOOL?=docker +PACT_CLI_DOCKER_VERSION?=latest +PACT_CLI_VERSION?=latest +PACT_CLI_STANDALONE_VERSION?=2.4.1 +PACT_CLI_DOCKER_RUN_COMMAND?=docker run --rm -v /${PWD}:/${PWD} -w ${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:${PACT_CLI_DOCKER_VERSION} +PACT_BROKER_COMMAND=pact-broker +PACTFLOW_CLI_COMMAND=pactflow + +ifeq '$(findstring ;,$(PATH))' ';' + detected_OS := Windows +else + detected_OS := $(shell uname -sm 2>/dev/null || echo Unknown) + detected_OS := $(patsubst CYGWIN%,Cygwin,$(detected_OS)) + detected_OS := $(patsubst MSYS%,MSYS,$(detected_OS)) + detected_OS := $(patsubst MINGW%,MSYS,$(detected_OS)) +endif + +ifeq ($(PACT_TOOL),ruby_standalone) +# add path to standalone, and add bat if windows + ifneq ($(filter $(detected_OS),Windows MSYS),) + PACT_BROKER_COMMAND:="./pact/bin/${PACT_BROKER_COMMAND}.bat" + PACTFLOW_CLI_COMMAND:="./pact/bin/${PACTFLOW_CLI_COMMAND}.bat" + else + PACT_BROKER_COMMAND:="./pact/bin/${PACT_BROKER_COMMAND}" + PACTFLOW_CLI_COMMAND:="./pact/bin/${PACTFLOW_CLI_COMMAND}" + endif +endif + +ifeq ($(PACT_TOOL),docker) +# add docker run command path + PACT_BROKER_COMMAND:=${PACT_CLI_DOCKER_RUN_COMMAND} ${PACT_BROKER_COMMAND} + PACTFLOW_CLI_COMMAND:=${PACT_CLI_DOCKER_RUN_COMMAND} ${PACTFLOW_CLI_COMMAND} +endif + + +install-pact-ruby-cli: + case "${PACT_CLI_VERSION}" in \ + latest) gem install pact_broker-client;; \ + "") gem install pact_broker-client;; \ + *) gem install pact_broker-client -v ${PACT_CLI_VERSION} ;; \ + esac + +uninstall-pact-ruby-cli: + gem uninstall -aIx pact_broker-client + +install-pact-ruby-standalone: + case "${detected_OS}" in \ + Windows|MSYS) curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_CLI_STANDALONE_VERSION}/pact-${PACT_CLI_STANDALONE_VERSION}-windows-x86_64.zip && \ + unzip pact-${PACT_CLI_STANDALONE_VERSION}-windows-x86_64.zip && \ + rm pact-${PACT_CLI_STANDALONE_VERSION}-windows-x86_64.zip && \ + ./pact/bin/pact-broker.bat help;; \ + "Darwin arm64") curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_CLI_STANDALONE_VERSION}/pact-${PACT_CLI_STANDALONE_VERSION}-osx-arm64.tar.gz && \ + tar xzf pact-${PACT_CLI_STANDALONE_VERSION}-osx-arm64.tar.gz && \ + rm pact-${PACT_CLI_STANDALONE_VERSION}-osx-arm64.tar.gz && \ + ./pact/bin/pact-broker help;; \ + "Darwin x86_64") curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_CLI_STANDALONE_VERSION}/pact-${PACT_CLI_STANDALONE_VERSION}-osx-x86_64.tar.gz && \ + tar xzf pact-${PACT_CLI_STANDALONE_VERSION}-osx-x86_64.tar.gz && \ + rm pact-${PACT_CLI_STANDALONE_VERSION}-osx-x86_64.tar.gz && \ + ./pact/bin/pact-broker help;; \ + "Linux aarch64") curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_CLI_STANDALONE_VERSION}/pact-${PACT_CLI_STANDALONE_VERSION}-linux-arm64.tar.gz && \ + tar xzf pact-${PACT_CLI_STANDALONE_VERSION}-linux-arm64.tar.gz && \ + rm pact-${PACT_CLI_STANDALONE_VERSION}-linux-arm64.tar.gz && \ + ./pact/bin/pact-broker help;; \ + "Linux x86_64") curl -LO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v${PACT_CLI_STANDALONE_VERSION}/pact-${PACT_CLI_STANDALONE_VERSION}-linux-x86_64.tar.gz && \ + tar xzf pact-${PACT_CLI_STANDALONE_VERSION}-linux-x86_64.tar.gz && \ + rm pact-${PACT_CLI_STANDALONE_VERSION}-linux-x86_64.tar.gz && \ + ./pact/bin/pact-broker help;; \ + esac \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a8a3cbb8b..e2999c7ac 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: httpbin: - image: kennethreitz/httpbin + image: kong/httpbin # https://github.com/Kong/httpbin ports: - "8000:80" @@ -18,7 +18,7 @@ services: POSTGRES_DB: postgres broker_app: - image: pactfoundation/pact-broker:latest-multi + image: pactfoundation/pact-broker:latest links: - postgres ports: diff --git a/installer/installer.go b/installer/installer.go index b7d07c5a7..90cd51691 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -392,7 +392,7 @@ const ( var packages = map[string]packageInfo{ FFIPackage: { libName: "libpact_ffi", - version: "0.4.20", + version: "0.4.19", semverRange: ">= 0.4.0, < 1.0.0", }, } diff --git a/make/config.mk b/make/config.mk index 56de93908..815d04b3b 100644 --- a/make/config.mk +++ b/make/config.mk @@ -1,5 +1,5 @@ export PATH := $(PWD)/pact/bin:$(PATH) export PATH -export PACT_BROKER_BASE_URL=http://127.0.0.1 -export PACT_BROKER_USERNAME=pact_workshop -export PACT_BROKER_PASSWORD=pact_workshop \ No newline at end of file +# export PACT_BROKER_BASE_URL=http://127.0.0.1 +# export PACT_BROKER_USERNAME=pact_workshop +# export PACT_BROKER_PASSWORD=pact_workshop \ No newline at end of file diff --git a/scripts/install-cli.sh b/scripts/install-cli.sh index 2ae7f9f1e..4bade0482 100755 --- a/scripts/install-cli.sh +++ b/scripts/install-cli.sh @@ -9,6 +9,10 @@ set -e # Needed for Windows bash, which doesn't read the shebang function detect_osarch() { case $(uname -sm) in + 'Linux aarch64') + os='linux' + arch='aarch64' + ;; 'Linux x86_64') os='linux' arch='x86_64' diff --git a/scripts/pact.ps1 b/scripts/pact.ps1 index 8f0fd43e7..a2679eff7 100644 --- a/scripts/pact.ps1 +++ b/scripts/pact.ps1 @@ -1,4 +1,4 @@ -$pactDir = "$env:APPVEYOR_BUILD_FOLDER\pact" +$pactDir = ($pwd).path + "pact" $exitCode = 0 # Set environment @@ -25,7 +25,7 @@ $latestRelease = Invoke-WebRequest https://github.com/pact-foundation/pact-ruby- $json = $latestRelease.Content | ConvertFrom-Json $tag = $json.tag_name $latestVersion = $tag.Substring(1) -$url = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/$tag/pact-$latestVersion-win32.zip" +$url = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/$tag/pact-$latestVersion-windows-x86.zip" Write-Host "Downloading $url" $zip = "$downloadDir\pact.zip" @@ -38,22 +38,25 @@ $downloader.DownloadFile($url, $zip) Write-Host "Extracting $zip" Add-Type -AssemblyName System.IO.Compression.FileSystem -[System.IO.Compression.ZipFile]::ExtractToDirectory("$zip", $pactDir) +[System.IO.Compression.ZipFile]::ExtractToDirectory("$zip", "$pactDir") Write-Host "Moving binaries into position" Get-ChildItem $pactDir\pact Write-Host "--> Adding pact binaries to path" $pactBinariesPath = "$pactDir\pact\bin" -$env:PATH += ";$pactBinariesPath" -Write-Host $env:PATH -Get-ChildItem $pactBinariesPath -pact-broker version +if !(Test-Path -Path $pactBinariesPath) { + $env:PATH += ";$pactBinariesPath" + Write-Host $env:PATH + Get-ChildItem $pactBinariesPath +} +pact-broker version # Run tests Write-Host "--> Running tests" $packages = go list github.com/pact-foundation/pact-go/... | where {$_ -inotmatch 'vendor'} | where {$_ -inotmatch 'examples'} +# $packages = go list -buildvcs=false github.com/pact-foundation/pact-go/... | where {$_ -inotmatch 'vendor'} | where {$_ -inotmatch 'examples'} $curDir=$pwd foreach ($package in $packages) { @@ -67,23 +70,23 @@ foreach ($package in $packages) { # Run integration tests -Write-Host "--> Testing E2E examples" -Write-Host "Running consumer tests" -docker-compose up -d -go test -tags=consumer -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample -if ($LastExitCode -ne 0) { - Write-Host "ERROR: Test failed, logging failure" - $exitCode=1 -} - -Write-Host "Running provider tests" -go test -tags=provider -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample -if ($LastExitCode -ne 0) { - Write-Host "ERROR: Test failed, logging failure" - $exitCode=1 -} - -# Shutdown +# Write-Host "--> Testing E2E examples" +# Write-Host "Running consumer tests" +# docker-compose up -d +# go test -tags=consumer -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample +# if ($LastExitCode -ne 0) { +# Write-Host "ERROR: Test failed, logging failure" +# $exitCode=1 +# } + +# Write-Host "Running provider tests" +# go test -tags=provider -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample +# if ($LastExitCode -ne 0) { +# Write-Host "ERROR: Test failed, logging failure" +# $exitCode=1 +# } + +Shutdown Write-Host "Shutting down any remaining pact processes :)" Stop-Process -Name ruby From 166dc0a45ede2580af2163a2e81cd4552b796441 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 14:47:39 +0100 Subject: [PATCH 02/19] x-plat go versions - linux arm64 / macos amd64 + arm64 - golang 1.20.x / 1.21.x / 1.22.x --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 74ad5b34a..f71285e51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: # 1.18.x, # Ended 01 Feb 2023 # 1.19.x, # Ended 8 Aug 2023 1.20.x, # Ended 06 Feb 2024 - 1.21.x + 1.21.x, 1.22.x ] os: [ From 815617cf38520910801955ba7db05aaeac84cb52 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 15:29:46 +0100 Subject: [PATCH 03/19] update plugins, add arm64 docker --- .github/workflows/test.yml | 54 +++++++++++++------ Dockerfile-deb | 4 +- Makefile | 6 +-- consumer/http_v4_test.go | 2 +- examples/grpc/grpc_consumer_test.go | 6 +-- examples/plugin/consumer_plugin_test.go | 4 +- .../protobuf_consumer_test.go | 2 +- internal/native/message_server_test.go | 10 ++-- internal/native/mock_server_test.go | 2 +- message/v4/asynchronous_message_test.go | 2 +- message/v4/synchronous_message_test.go | 4 +- 11 files changed, 59 insertions(+), 37 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f71285e51..2a4f15966 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,7 @@ jobs: 1.22.x ] os: [ + ubuntu-22.04, ubuntu-latest, # windows-latest, macos-12, @@ -35,47 +36,68 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - name: Install Go + if: matrix.os != 'ubuntu-22.04' uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - uses: actions/setup-java@v4 # Needed for the Avro example + if: matrix.os != 'ubuntu-22.04' with: distribution: 'zulu' java-version: '17' - run: brew install protobuf if: matrix.os == 'macos-14' - name: Unit Test - run: make ci_unit + if: matrix.os != 'ubuntu-22.04' + run: make ci_unit in docker + - name: Set up QEMU + if: matrix.os == 'ubuntu-22.04' + uses: docker/setup-qemu-action@v3 + - name: Build arm64 dockerfile + if: matrix.os == 'ubuntu-22.04' + run: | + docker build \ + --platform linux/arm64 \ + -f Dockerfile-deb \ + -t pactfoundation/pact-go-test . + - name: Unit Test (arm64 docker) + if: matrix.os == 'ubuntu-22.04' + run: | + docker run \ + --platform linux/arm64 \ + --rm pactfoundation/pact-go-test + - name: Examples with Standalone (arm64 docker) + if: matrix.os == 'ubuntu-22.04' + run: | + docker run \ + --platform linux/arm64 + -e PACT_BROKER_BASE_URL \ + -e PACT_BROKER_TOKEN \ + -e LOG_LEVEL \ + -e APP_SHA \ + -e APP_BRANCH=${APP_REF:11} \ + --rm \ + pactfoundation/pact-go-test \ + /bin/sh -c "make download_plugins && make install-pact-ruby-standalone && PACT_TOOL=standalone make pact" # - name: Examples with Docker # if: runner.os == 'Linux' # run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make ci_examples - name: Examples with Standalone + if: matrix.os != 'ubuntu-22.04' run: | make install-pact-ruby-standalone APP_BRANCH=${APP_REF:11} PACT_TOOL=standalone make ci_hosted_examples - - # - name: Unit Test - # if: runner.os != 'Linux' - # run: make ci_no_docker - # env: - # SKIP_PLUGIN_AVRO: true - # - name: Unit Test - # if: runner.os == 'Windows' - # run: make test - # env: - # SKIP_PLUGIN_AVRO: true - # LD_LIBRARY_PATH: /tmp - name: Install goveralls run: go install github.com/mattn/goveralls@latest - if: runner.os == 'Linux' + if: runner.os == 'Linux' && matrix.os != 'ubuntu-22.04' - name: Send coverage run: goveralls -coverprofile=coverage.txt -service=github -parallel - if: runner.os == 'Linux' + if: runner.os == 'Linux' && matrix.os != 'ubuntu-22.04' - uses: actions/upload-artifact@v4 with: name: logs-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.go-version }}-${{ matrix.os }}.zip path: ~/.pact/plugins/**/plugin.log - if: ${{ always() }} + if: ${{ always() }} && matrix.os != 'ubuntu-22.04' finish: needs: test diff --git a/Dockerfile-deb b/Dockerfile-deb index 881108f14..272e1aeb8 100644 --- a/Dockerfile-deb +++ b/Dockerfile-deb @@ -1,7 +1,7 @@ FROM golang:latest -RUN apt-get update && apt-get install -y openjdk-17-jre file - +RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler +# RUN mkdir -p /root/.pact/plugins COPY . /go/src/github.com/pact-foundation/pact-go WORKDIR /go/src/github.com/pact-foundation/pact-go diff --git a/Makefile b/Makefile index ebc3b8317..abc3cb8d5 100755 --- a/Makefile +++ b/Makefile @@ -45,9 +45,9 @@ deps: download_plugins cd /tmp; \ go install github.com/mitchellh/gox@latest; \ cd - -PLUGIN_PACT_PROTOBUF_VERSION=0.3.13 -PLUGIN_PACT_CSV_VERSION=0.0.1 -PLUGIN_PACT_MATT_VERSION=0.0.9 +PLUGIN_PACT_PROTOBUF_VERSION=0.3.14 +PLUGIN_PACT_CSV_VERSION=0.0.5 +PLUGIN_PACT_MATT_VERSION=0.1.1 PLUGIN_PACT_AVRO_VERSION=0.0.3 download_plugins: diff --git a/consumer/http_v4_test.go b/consumer/http_v4_test.go index b2505bbeb..2d73cbf0a 100644 --- a/consumer/http_v4_test.go +++ b/consumer/http_v4_test.go @@ -58,7 +58,7 @@ func TestHttpV4TypeSystem(t *testing.T) { UponReceiving("some scenario"). UsingPlugin(PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithRequest("GET", "/"). // WithRequest("GET", "/", func(b *V4InteractionWithPluginRequestBuilder) { diff --git a/examples/grpc/grpc_consumer_test.go b/examples/grpc/grpc_consumer_test.go index 44fdd8640..5f627b9c8 100644 --- a/examples/grpc/grpc_consumer_test.go +++ b/examples/grpc/grpc_consumer_test.go @@ -52,7 +52,7 @@ func TestGetFeatureSuccess(t *testing.T) { Given("feature 'Big Tree' exists"). UsingPlugin(message.PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithContents(grpcInteraction, "application/protobuf"). StartTransport("grpc", "127.0.0.1", nil). // For plugin tests, we can't assume if a transport is needed, so this is optional @@ -122,7 +122,7 @@ func TestGetFeatureError(t *testing.T) { Given("feature does not exist at -1, -1"). UsingPlugin(message.PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithContents(grpcInteraction, "application/protobuf"). StartTransport("grpc", "127.0.0.1", nil). // For plugin tests, we can't assume if a transport is needed, so this is optional @@ -193,7 +193,7 @@ func TestSaveFeature(t *testing.T) { Given("feature does not exist at -1, -1"). UsingPlugin(message.PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithContents(grpcInteraction, "application/protobuf"). StartTransport("grpc", "127.0.0.1", nil). // For plugin tests, we can't assume if a transport is needed, so this is optional diff --git a/examples/plugin/consumer_plugin_test.go b/examples/plugin/consumer_plugin_test.go index edb3b8d44..5177f67ea 100644 --- a/examples/plugin/consumer_plugin_test.go +++ b/examples/plugin/consumer_plugin_test.go @@ -42,7 +42,7 @@ func TestHTTPPlugin(t *testing.T) { UponReceiving("A request to do a matt"). UsingPlugin(consumer.PluginConfig{ Plugin: "matt", - Version: "0.0.9", + Version: "0.1.1", }). WithRequest("POST", "/matt", func(req *consumer.V4InteractionWithPluginRequestBuilder) { req.PluginContents("application/matt", mattRequest) @@ -74,7 +74,7 @@ func TestTCPPlugin(t *testing.T) { Given("the world exists"). UsingPlugin(message.PluginConfig{ Plugin: "matt", - Version: "0.0.9", + Version: "0.1.1", }). WithContents(mattMessage, "application/matt"). StartTransport("matt", "127.0.0.1", nil). // For plugin tests, we can't assume if a transport is needed, so this is optional diff --git a/examples/protobuf-message/protobuf_consumer_test.go b/examples/protobuf-message/protobuf_consumer_test.go index a7226acfe..747d00377 100644 --- a/examples/protobuf-message/protobuf_consumer_test.go +++ b/examples/protobuf-message/protobuf_consumer_test.go @@ -42,7 +42,7 @@ func TestPluginMessageConsumer(t *testing.T) { ExpectsToReceive("feature message"). UsingPlugin(message.PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithContents(protoMessage, "application/protobuf"). ExecuteTest(t, func(m message.AsynchronousMessage) error { diff --git a/internal/native/message_server_test.go b/internal/native/message_server_test.go index 3c39cb607..a11527694 100644 --- a/internal/native/message_server_test.go +++ b/internal/native/message_server_test.go @@ -211,7 +211,7 @@ func TestGetPluginSyncMessageContentsAsBytes(t *testing.T) { m := NewMessageServer("test-message-consumer", "test-message-provider") // Protobuf plugin test - err := m.UsingPlugin("protobuf", "0.3.13") + err := m.UsingPlugin("protobuf", "0.3.14") assert.NoError(t, err) i := m.NewSyncMessageInteraction("grpc interaction") @@ -268,7 +268,7 @@ func TestGetPluginSyncMessageContentsAsBytes_EmptyResponse(t *testing.T) { m := NewMessageServer("test-message-consumer", "test-message-provider") // Protobuf plugin test - err := m.UsingPlugin("protobuf", "0.3.13") + err := m.UsingPlugin("protobuf", "0.3.14") assert.NoError(t, err) i := m.NewSyncMessageInteraction("grpc interaction") @@ -314,7 +314,7 @@ func TestGetPluginAsyncMessageContentsAsBytes(t *testing.T) { m := NewMessageServer("test-message-consumer", "test-message-provider") // Protobuf plugin test - _ = m.UsingPlugin("protobuf", "0.3.13") + _ = m.UsingPlugin("protobuf", "0.3.14") i := m.NewAsyncMessageInteraction("grpc interaction") @@ -354,7 +354,7 @@ func TestGrpcPluginInteraction(t *testing.T) { m := NewMessageServer("test-message-consumer", "test-message-provider") // Protobuf plugin test - _ = m.UsingPlugin("protobuf", "0.3.13") + _ = m.UsingPlugin("protobuf", "0.3.14") i := m.NewSyncMessageInteraction("grpc interaction") @@ -431,7 +431,7 @@ func TestGrpcPluginInteraction_ErrorResponse(t *testing.T) { m := NewMessageServer("test-message-consumer", "test-message-provider") // Protobuf plugin test - _ = m.UsingPlugin("protobuf", "0.3.13") + _ = m.UsingPlugin("protobuf", "0.3.14") i := m.NewSyncMessageInteraction("grpc interaction") diff --git a/internal/native/mock_server_test.go b/internal/native/mock_server_test.go index bb3e595c2..bb3303acc 100644 --- a/internal/native/mock_server_test.go +++ b/internal/native/mock_server_test.go @@ -172,7 +172,7 @@ func TestPluginInteraction(t *testing.T) { m := NewHTTPPact("test-plugin-consumer", "test-plugin-provider") // Protobuf plugin test - _ = m.UsingPlugin("protobuf", "0.0.3") + _ = m.UsingPlugin("protobuf", "0.3.14") m.WithSpecificationVersion(SPECIFICATION_VERSION_V4) i := m.NewInteraction("some plugin interaction") diff --git a/message/v4/asynchronous_message_test.go b/message/v4/asynchronous_message_test.go index e8706627f..97777f3b9 100644 --- a/message/v4/asynchronous_message_test.go +++ b/message/v4/asynchronous_message_test.go @@ -64,7 +64,7 @@ func TestAsyncTypeSystem(t *testing.T) { ExpectsToReceive("some csv content"). UsingPlugin(PluginConfig{ Plugin: "csv", - Version: "0.0.3", + Version: "0.0.5", }). WithContents(csvInteraction, "text/csv"). // StartTransport("notarealtransport", "127.0.0.1", nil). diff --git a/message/v4/synchronous_message_test.go b/message/v4/synchronous_message_test.go index 0b546f022..3765dfca3 100644 --- a/message/v4/synchronous_message_test.go +++ b/message/v4/synchronous_message_test.go @@ -105,7 +105,7 @@ func TestSyncTypeSystem(t *testing.T) { Given("some state"). UsingPlugin(PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithContents(grpcInteraction, "application/protobuf"). StartTransport("grpc", "127.0.0.1", nil). // For plugin tests, we can't assume if a transport is needed, so this is optional @@ -128,7 +128,7 @@ func TestSyncTypeSystem(t *testing.T) { Given("some state"). UsingPlugin(PluginConfig{ Plugin: "protobuf", - Version: "0.3.13", + Version: "0.3.14", }). WithContents(grpcInteraction, "application/protobuf"). StartTransport("grpc", "127.0.0.1", nil). // For plugin tests, we can't assume if a transport is needed, so this is optional From 871f10fee4ca3b51a5c027143cc0cf814cd02436 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 16:55:02 +0100 Subject: [PATCH 04/19] test dockerfile debian arm64 wf --- .github/workflows/test.yml | 21 +++++++++++---------- Dockerfile-deb | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a4f15966..8002139f6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,16 +19,16 @@ jobs: # 1.17.x, # Ended 02 Aug 2022 # 1.18.x, # Ended 01 Feb 2023 # 1.19.x, # Ended 8 Aug 2023 - 1.20.x, # Ended 06 Feb 2024 - 1.21.x, - 1.22.x + 1.20, # Ended 06 Feb 2024 + 1.21, + 1.22 ] os: [ ubuntu-22.04, - ubuntu-latest, + # ubuntu-latest, # windows-latest, - macos-12, - macos-14 + # macos-12, + # macos-14 ] fail-fast: false runs-on: ${{ matrix.os }} @@ -49,7 +49,7 @@ jobs: if: matrix.os == 'macos-14' - name: Unit Test if: matrix.os != 'ubuntu-22.04' - run: make ci_unit in docker + run: make ci_unit - name: Set up QEMU if: matrix.os == 'ubuntu-22.04' uses: docker/setup-qemu-action@v3 @@ -58,14 +58,15 @@ jobs: run: | docker build \ --platform linux/arm64 \ + --build-arg ${{ matrix.go-version }} \ -f Dockerfile-deb \ - -t pactfoundation/pact-go-test . + -t pactfoundation/pact-go-test-${{ matrix.go-version }} . - name: Unit Test (arm64 docker) if: matrix.os == 'ubuntu-22.04' run: | docker run \ --platform linux/arm64 \ - --rm pactfoundation/pact-go-test + --rm pactfoundation/pact-go-test-${{ matrix.go-version }} - name: Examples with Standalone (arm64 docker) if: matrix.os == 'ubuntu-22.04' run: | @@ -77,7 +78,7 @@ jobs: -e APP_SHA \ -e APP_BRANCH=${APP_REF:11} \ --rm \ - pactfoundation/pact-go-test \ + pactfoundation/pact-go-test-${{ matrix.go-version }} \ /bin/sh -c "make download_plugins && make install-pact-ruby-standalone && PACT_TOOL=standalone make pact" # - name: Examples with Docker # if: runner.os == 'Linux' diff --git a/Dockerfile-deb b/Dockerfile-deb index 272e1aeb8..e7804490a 100644 --- a/Dockerfile-deb +++ b/Dockerfile-deb @@ -1,4 +1,5 @@ -FROM golang:latest +ARG VERSION=latest +FROM golang:${VERSION} RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler # RUN mkdir -p /root/.pact/plugins From 7762a9dd902d8612e7fdaee86bf80ac4fc247225 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 16:58:45 +0100 Subject: [PATCH 05/19] pass in VERSION to docker build --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8002139f6..6384e8c23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,7 +58,7 @@ jobs: run: | docker build \ --platform linux/arm64 \ - --build-arg ${{ matrix.go-version }} \ + --build-arg VERSION=${{ matrix.go-version }} \ -f Dockerfile-deb \ -t pactfoundation/pact-go-test-${{ matrix.go-version }} . - name: Unit Test (arm64 docker) From c1ed615c7f33f3b4c2c4eebab3d9206b9251ca16 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 17:11:32 +0100 Subject: [PATCH 06/19] no race under qemu --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index abc3cb8d5..8df1b06cc 100755 --- a/Makefile +++ b/Makefile @@ -115,7 +115,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 -coverprofile=profile.out -covermode=atomic $$d; \ if [ $$? != 0 ]; then \ exit 1; \ fi; \ From 23e37d7451abcf058de21811b38db8da3add6c57 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 17:24:39 +0100 Subject: [PATCH 07/19] set SKIP_RACE val in gha --- .github/workflows/test.yml | 10 ++++++---- Makefile | 31 ++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6384e8c23..6d581e061 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,9 +19,9 @@ jobs: # 1.17.x, # Ended 02 Aug 2022 # 1.18.x, # Ended 01 Feb 2023 # 1.19.x, # Ended 8 Aug 2023 - 1.20, # Ended 06 Feb 2024 - 1.21, - 1.22 + '1.20', # Ended 06 Feb 2024 + '1.21', + '1.22' ] os: [ ubuntu-22.04, @@ -66,17 +66,19 @@ jobs: run: | docker run \ --platform linux/arm64 \ + -e SKIP_RACE=true \ --rm pactfoundation/pact-go-test-${{ matrix.go-version }} - name: Examples with Standalone (arm64 docker) if: matrix.os == 'ubuntu-22.04' run: | docker run \ - --platform linux/arm64 + --platform linux/arm64 \ -e PACT_BROKER_BASE_URL \ -e PACT_BROKER_TOKEN \ -e LOG_LEVEL \ -e APP_SHA \ -e APP_BRANCH=${APP_REF:11} \ + -e SKIP_RACE=true \ --rm \ pactfoundation/pact-go-test-${{ matrix.go-version }} \ /bin/sh -c "make download_plugins && make install-pact-ruby-standalone && PACT_TOOL=standalone make pact" diff --git a/Makefile b/Makefile index 8df1b06cc..f510ee398 100755 --- a/Makefile +++ b/Makefile @@ -109,13 +109,19 @@ release: # @for d in $$(go list -buildvcs=false ./... | grep -v vendor | grep -v examples); +RACE?='-race' + +ifdef SKIP_RACE + RACE= +endif + test: deps install @echo "--- ✅ Running tests" @if [ -f coverage.txt ]; then rm coverage.txt; fi; @echo "mode: count" > coverage.txt @for d in $$(go list ./... | grep -v vendor | grep -v examples); \ do \ - go test -v -coverprofile=profile.out -covermode=atomic $$d; \ + go test -v $(RACE) -coverprofile=profile.out -covermode=atomic $$d; \ if [ $$? != 0 ]; then \ exit 1; \ fi; \ @@ -133,6 +139,29 @@ testrace: updatedeps: go get -d -v -p 2 ./... +docker_build: + docker build -f Dockerfile-deb --build-arg VERSION=1.21 -t pactfoundation/pact-go-test . +docker_run_test: + docker run \ + -e PACT_BROKER_BASE_URL \ + -e PACT_BROKER_TOKEN \ + -e LOG_LEVEL=info \ + -e APP_SHA=foo \ + --rm \ + -it \ + pactfoundation/pact-go-test \ + /bin/sh -c "make test" +docker_run_examples: + docker run \ + -e PACT_BROKER_BASE_URL \ + -e PACT_BROKER_TOKEN \ + -e LOG_LEVEL=info \ + -e APP_SHA=foo \ + --rm \ + -it \ + pactfoundation/pact-go-test \ + /bin/sh -c "make download_plugins && make install-pact-ruby-standalone && PACT_TOOL=standalone make pact" + .PHONY: install bin default dev test pact updatedeps clean release PROTOC ?= $(shell which protoc) From 4fe9261989fb921fa59407f29e598f36e7cd9234 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 17:42:54 +0100 Subject: [PATCH 08/19] use ruby pact_broker-client due to qemu-aarch64 errors --- .github/workflows/test.yml | 2 +- Dockerfile-deb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d581e061..eab9b2d2e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,7 +81,7 @@ jobs: -e SKIP_RACE=true \ --rm \ pactfoundation/pact-go-test-${{ matrix.go-version }} \ - /bin/sh -c "make download_plugins && make install-pact-ruby-standalone && PACT_TOOL=standalone make pact" + /bin/sh -c "make download_plugins && make install-pact-ruby-cli && PACT_TOOL=ruby make pact" # - name: Examples with Docker # if: runner.os == 'Linux' # run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make ci_examples diff --git a/Dockerfile-deb b/Dockerfile-deb index e7804490a..0408524ac 100644 --- a/Dockerfile-deb +++ b/Dockerfile-deb @@ -1,8 +1,7 @@ ARG VERSION=latest FROM golang:${VERSION} -RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler -# RUN mkdir -p /root/.pact/plugins +RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler ruby ruby-dev ruby-bundler COPY . /go/src/github.com/pact-foundation/pact-go WORKDIR /go/src/github.com/pact-foundation/pact-go From 35cf01c3c4389181b5af66f922ceb4b8a431faf3 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 17:50:10 +0100 Subject: [PATCH 09/19] ci: test win --- .github/workflows/test.yml | 4 ++-- internal/native/lib.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eab9b2d2e..8d2c3c084 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,9 +24,9 @@ jobs: '1.22' ] os: [ - ubuntu-22.04, + # ubuntu-22.04, # ubuntu-latest, - # windows-latest, + windows-latest, # macos-12, # macos-14 ] diff --git a/internal/native/lib.go b/internal/native/lib.go index d4324ff52..13ba90fa1 100644 --- a/internal/native/lib.go +++ b/internal/native/lib.go @@ -4,7 +4,7 @@ package native /* #cgo darwin,arm64 LDFLAGS: -L/tmp -L/usr/local/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi #cgo darwin,amd64 LDFLAGS: -L/tmp -L/usr/local/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi -#cgo windows,amd64 LDFLAGS: -lpact_ffi +#cgo windows,amd64 LDFLAGS: -L/tmp -lpact_ffi #cgo linux,amd64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi #cgo linux,arm64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi */ From 16ab8855ae0785e6a9b0f79c7967e5da68bb5205 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 17:56:40 +0100 Subject: [PATCH 10/19] ci: test win --- .github/workflows/test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8d2c3c084..43db08498 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,6 +45,12 @@ jobs: with: distribution: 'zulu' java-version: '17' + + - name: Set SKIP_AVRO for Windows + if: matrix.os == 'windows-latest' + run: echo "SKIP_AVRO=true" >> $GITHUB_ENV + # TODO - work out why plugin wont start on windows + - run: brew install protobuf if: matrix.os == 'macos-14' - name: Unit Test From 7a20cb9cccd3e0be277149ef20a7820c2e28cfc5 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 17:58:53 +0100 Subject: [PATCH 11/19] ci: test win - SKIP_PLUGIN_AVRO --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43db08498..e6f5b6708 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,9 +46,9 @@ jobs: distribution: 'zulu' java-version: '17' - - name: Set SKIP_AVRO for Windows + - name: Set SKIP_PLUGIN_AVRO for Windows if: matrix.os == 'windows-latest' - run: echo "SKIP_AVRO=true" >> $GITHUB_ENV + run: echo "SKIP_PLUGIN_AVRO=true" >> $GITHUB_ENV # TODO - work out why plugin wont start on windows - run: brew install protobuf From 48afa99c910661499803496d0ef81c695d509416 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 18:03:42 +0100 Subject: [PATCH 12/19] ci: test win - SKIP_PLUGIN_AVRO --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e6f5b6708..6ad60fde1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,6 +49,7 @@ jobs: - name: Set SKIP_PLUGIN_AVRO for Windows if: matrix.os == 'windows-latest' run: echo "SKIP_PLUGIN_AVRO=true" >> $GITHUB_ENV + shell: bash # TODO - work out why plugin wont start on windows - run: brew install protobuf From 70fd79d20957d041e113a34e574961a63c94b0f9 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 3 May 2024 19:13:42 +0100 Subject: [PATCH 13/19] test linux/macos inc docker --- .github/workflows/test.yml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ad60fde1..b8c73e37e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,11 +24,11 @@ jobs: '1.22' ] os: [ - # ubuntu-22.04, - # ubuntu-latest, - windows-latest, - # macos-12, - # macos-14 + ubuntu-22.04, + ubuntu-latest, + # windows-latest, + macos-12, + macos-14 ] fail-fast: false runs-on: ${{ matrix.os }} @@ -46,40 +46,40 @@ jobs: distribution: 'zulu' java-version: '17' - - name: Set SKIP_PLUGIN_AVRO for Windows - if: matrix.os == 'windows-latest' - run: echo "SKIP_PLUGIN_AVRO=true" >> $GITHUB_ENV - shell: bash - # TODO - work out why plugin wont start on windows + # - name: Set SKIP_PLUGIN_AVRO for Windows + # if: matrix.os == 'windows-latest' + # run: echo "SKIP_PLUGIN_AVRO=true" >> $GITHUB_ENV + # shell: bash + # # TODO - work out why plugin wont start on windows - run: brew install protobuf if: matrix.os == 'macos-14' - name: Unit Test if: matrix.os != 'ubuntu-22.04' run: make ci_unit - - name: Set up QEMU - if: matrix.os == 'ubuntu-22.04' - uses: docker/setup-qemu-action@v3 - - name: Build arm64 dockerfile + # - name: Set up QEMU + # if: matrix.os == 'ubuntu-22.04' + # uses: docker/setup-qemu-action@v3 + - name: Build amd64 dockerfile if: matrix.os == 'ubuntu-22.04' run: | docker build \ - --platform linux/arm64 \ + --platform linux/amd64 \ --build-arg VERSION=${{ matrix.go-version }} \ -f Dockerfile-deb \ -t pactfoundation/pact-go-test-${{ matrix.go-version }} . - - name: Unit Test (arm64 docker) + - name: Unit Test (amd64 docker) if: matrix.os == 'ubuntu-22.04' run: | docker run \ - --platform linux/arm64 \ + --platform linux/amd64 \ -e SKIP_RACE=true \ --rm pactfoundation/pact-go-test-${{ matrix.go-version }} - - name: Examples with Standalone (arm64 docker) + - name: Examples with Standalone (amd64 docker) if: matrix.os == 'ubuntu-22.04' run: | docker run \ - --platform linux/arm64 \ + --platform linux/amd64 \ -e PACT_BROKER_BASE_URL \ -e PACT_BROKER_TOKEN \ -e LOG_LEVEL \ From 99b185be1ad34d1d80c6657a6a6b15f14bbe7c6e Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 7 May 2024 15:21:26 +0100 Subject: [PATCH 14/19] ci: experimental 1.22 on linux --- .github/workflows/test.yml | 53 ++++++++++---------------------------- DEVELOPER.md | 50 ----------------------------------- scripts/pact.ps1 | 51 +++++++++++++++++------------------- 3 files changed, 38 insertions(+), 116 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8c73e37e..44442b8bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,12 +24,24 @@ jobs: '1.22' ] os: [ - ubuntu-22.04, + ubuntu-22.04, # We use this OS to run a build against our docker image ubuntu-latest, # windows-latest, macos-12, macos-14 ] + exclude: + - go-version: '1.22' + os: ubuntu-latest + - go-version: '1.22' + os: ubuntu-22.04 + include: + - go-version: '1.22' + os: ubuntu-latest + experimental: true + - go-version: '1.22' + os: ubuntu-22.04 + experimental: true fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -45,21 +57,11 @@ jobs: with: distribution: 'zulu' java-version: '17' - - # - name: Set SKIP_PLUGIN_AVRO for Windows - # if: matrix.os == 'windows-latest' - # run: echo "SKIP_PLUGIN_AVRO=true" >> $GITHUB_ENV - # shell: bash - # # TODO - work out why plugin wont start on windows - - run: brew install protobuf if: matrix.os == 'macos-14' - name: Unit Test if: matrix.os != 'ubuntu-22.04' run: make ci_unit - # - name: Set up QEMU - # if: matrix.os == 'ubuntu-22.04' - # uses: docker/setup-qemu-action@v3 - name: Build amd64 dockerfile if: matrix.os == 'ubuntu-22.04' run: | @@ -73,7 +75,6 @@ jobs: run: | docker run \ --platform linux/amd64 \ - -e SKIP_RACE=true \ --rm pactfoundation/pact-go-test-${{ matrix.go-version }} - name: Examples with Standalone (amd64 docker) if: matrix.os == 'ubuntu-22.04' @@ -85,13 +86,9 @@ jobs: -e LOG_LEVEL \ -e APP_SHA \ -e APP_BRANCH=${APP_REF:11} \ - -e SKIP_RACE=true \ --rm \ pactfoundation/pact-go-test-${{ matrix.go-version }} \ /bin/sh -c "make download_plugins && make install-pact-ruby-cli && PACT_TOOL=ruby make pact" - # - name: Examples with Docker - # if: runner.os == 'Linux' - # run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make ci_examples - name: Examples with Standalone if: matrix.os != 'ubuntu-22.04' run: | @@ -117,26 +114,4 @@ jobs: uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true - - # test-other-os: - # strategy: - # matrix: - # go-version: [ # https://endoflife.date/go - # 1.19.x, - # 1.20.x, - # 1.21.x - # ] - # os: [macos-latest,windows-latest] - # fail-fast: false - # runs-on: ${{ matrix.os }} - # steps: - # - name: Checkout code - # uses: actions/checkout@v2 - # - name: Install Go - # uses: actions/setup-go@v4 - # with: - # go-version: ${{ matrix.go-version }} - # - run: make test - # env: - # SKIP_PLUGIN_AVRO: true \ No newline at end of file + parallel-finished: true \ No newline at end of file diff --git a/DEVELOPER.md b/DEVELOPER.md index 057196457..dc7b96608 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -14,53 +14,3 @@ The previous major version. Only bug fixes and security updates will be consider ### `master` The `2.x.x` release line. Current major version. - - -## Windows on ARM - -WoA is not supported by Pact FFI atm. - -Build errors - -```ps1 -PS W:\> go build -o build/pact-go.exe -error obtaining VCS status: exit status 128 - Use -buildvcs=false to disable VCS stamping. - -``` - -Install ffi - -```ps1 -PS W:\> .\build\pact-go.exe -l DEBUG install --libDir /tmp -2023/10/03 19:02:08 [INFO] set lib dir target to /tmp -2023/10/03 19:02:08 [INFO] package libpact_ffi not found -2023/10/03 19:02:08 [INFO] downloading library from https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v0.4.5/pact_ffi-windows-x86_64.dll.gz to /tmp/pact_ffi.dll -&{} -2023/10/03 19:02:12 [DEBUG] obtaining hash for file /tmp/pact_ffi.dll -2023/10/03 19:02:12 [DEBUG] writing config {map[libpact_ffi:{libpact_ffi 0.4.5 f03507c43328add6e02215740c044988}]} -2023/10/03 19:02:12 [DEBUG] writing yaml config to file libraries: - libpact_ffi: - libname: libpact_ffi - version: 0.4.5 - hash: f03507c43328add6e02215740c044988 - -2023/10/03 19:02:12 [INFO] package libpact_ffi found -2023/10/03 19:02:12 [INFO] checking version 0.4.5 of libpact_ffi against semver constraint >= 0.4.0, < 1.0.0 -2023/10/03 19:02:12 [DEBUG] 0.4.5 satisfies constraints 0.4.5 >= 0.4.0, < 1.0.0 -2023/10/03 19:02:12 [INFO] package libpact_ffi is correctly installed -2023/10/03 19:02:12 [DEBUG] skip checking ffi version() call because FFI not loaded. This is expected when running the 'pact-go' command. -``` - -Some WIP steps - -```ps1 -scoop install go -$env:GOARCH=amd64 -go mod tidy -go build -o build/pact-go.exe -buildvcs=false -.\build\pact-go.exe -l DEBUG install --libDir /tmp -scoop install grep -go list -buildvcs=false ./... | grep -v vendor | grep -v examples -go test -v github.com/pact-foundation/pact-go/v2/installer -``` \ No newline at end of file diff --git a/scripts/pact.ps1 b/scripts/pact.ps1 index a2679eff7..8f0fd43e7 100644 --- a/scripts/pact.ps1 +++ b/scripts/pact.ps1 @@ -1,4 +1,4 @@ -$pactDir = ($pwd).path + "pact" +$pactDir = "$env:APPVEYOR_BUILD_FOLDER\pact" $exitCode = 0 # Set environment @@ -25,7 +25,7 @@ $latestRelease = Invoke-WebRequest https://github.com/pact-foundation/pact-ruby- $json = $latestRelease.Content | ConvertFrom-Json $tag = $json.tag_name $latestVersion = $tag.Substring(1) -$url = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/$tag/pact-$latestVersion-windows-x86.zip" +$url = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/$tag/pact-$latestVersion-win32.zip" Write-Host "Downloading $url" $zip = "$downloadDir\pact.zip" @@ -38,25 +38,22 @@ $downloader.DownloadFile($url, $zip) Write-Host "Extracting $zip" Add-Type -AssemblyName System.IO.Compression.FileSystem -[System.IO.Compression.ZipFile]::ExtractToDirectory("$zip", "$pactDir") +[System.IO.Compression.ZipFile]::ExtractToDirectory("$zip", $pactDir) Write-Host "Moving binaries into position" Get-ChildItem $pactDir\pact Write-Host "--> Adding pact binaries to path" $pactBinariesPath = "$pactDir\pact\bin" -if !(Test-Path -Path $pactBinariesPath) { - $env:PATH += ";$pactBinariesPath" - Write-Host $env:PATH - Get-ChildItem $pactBinariesPath -} - +$env:PATH += ";$pactBinariesPath" +Write-Host $env:PATH +Get-ChildItem $pactBinariesPath pact-broker version + # Run tests Write-Host "--> Running tests" $packages = go list github.com/pact-foundation/pact-go/... | where {$_ -inotmatch 'vendor'} | where {$_ -inotmatch 'examples'} -# $packages = go list -buildvcs=false github.com/pact-foundation/pact-go/... | where {$_ -inotmatch 'vendor'} | where {$_ -inotmatch 'examples'} $curDir=$pwd foreach ($package in $packages) { @@ -70,23 +67,23 @@ foreach ($package in $packages) { # Run integration tests -# Write-Host "--> Testing E2E examples" -# Write-Host "Running consumer tests" -# docker-compose up -d -# go test -tags=consumer -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample -# if ($LastExitCode -ne 0) { -# Write-Host "ERROR: Test failed, logging failure" -# $exitCode=1 -# } - -# Write-Host "Running provider tests" -# go test -tags=provider -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample -# if ($LastExitCode -ne 0) { -# Write-Host "ERROR: Test failed, logging failure" -# $exitCode=1 -# } - -Shutdown +Write-Host "--> Testing E2E examples" +Write-Host "Running consumer tests" +docker-compose up -d +go test -tags=consumer -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample +if ($LastExitCode -ne 0) { + Write-Host "ERROR: Test failed, logging failure" + $exitCode=1 +} + +Write-Host "Running provider tests" +go test -tags=provider -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample +if ($LastExitCode -ne 0) { + Write-Host "ERROR: Test failed, logging failure" + $exitCode=1 +} + +# Shutdown Write-Host "Shutting down any remaining pact processes :)" Stop-Process -Name ruby From a95d4fceb3763395b57e8de5420beecd514a0c0d Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 7 May 2024 15:41:32 +0100 Subject: [PATCH 15/19] ci: experimental 1.22 on macos-12 plus rename wf --- .github/workflows/test.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 44442b8bd..74a29441c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,6 +35,8 @@ jobs: os: ubuntu-latest - go-version: '1.22' os: ubuntu-22.04 + - go-version: '1.22' + os: macos-12 include: - go-version: '1.22' os: ubuntu-latest @@ -42,8 +44,17 @@ jobs: - go-version: '1.22' os: ubuntu-22.04 experimental: true + - go-version: '1.22' + os: macos-12 + experimental: true fail-fast: false runs-on: ${{ matrix.os }} + name: >- + if [[ ${{ matrix.os }} == 'ubuntu-22.04' ]]; then + docker-${{ matrix.go-version }} + else + ${{ matrix.os }}-${{ matrix.go-version }} + fi steps: - name: Checkout code uses: actions/checkout@v4 From 0d09749567b0a59e4be8b3b8b415afcaa6a5fdf3 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 7 May 2024 16:16:38 +0100 Subject: [PATCH 16/19] ci: continue on experimental error --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 74a29441c..bbada6040 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,7 @@ jobs: macos-12, macos-14 ] + experimental: [false] exclude: - go-version: '1.22' os: ubuntu-latest @@ -49,6 +50,7 @@ jobs: experimental: true fail-fast: false runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.experimental }} name: >- if [[ ${{ matrix.os }} == 'ubuntu-22.04' ]]; then docker-${{ matrix.go-version }} From 7f5696987e1f7b881fc38244fd3d27383fd44c2a Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 7 May 2024 18:52:41 +0100 Subject: [PATCH 17/19] chore: set wf name --- .github/workflows/test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bbada6040..70f7b2f0c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,12 +51,7 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} - name: >- - if [[ ${{ matrix.os }} == 'ubuntu-22.04' ]]; then - docker-${{ matrix.go-version }} - else - ${{ matrix.os }}-${{ matrix.go-version }} - fi + name: ${{ matrix.os == 'ubuntu-22.04' && 'linux-docker' || matrix.os }}-${{ matrix.go-version }} steps: - name: Checkout code uses: actions/checkout@v4 From 32a9a7462141f54817152fb8d700bddb250b567e Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 7 May 2024 19:44:45 +0100 Subject: [PATCH 18/19] chore: support for hosted/local brokers --- .github/workflows/test.yml | 4 +- DEVELOPER.md | 91 +++++++++++++++++++++++++++++ Dockerfile | 6 +- Dockerfile-deb => Dockerfile.alpine | 5 +- Makefile | 19 +++--- internal/native/lib.go | 2 +- make/config.mk | 6 +- 7 files changed, 112 insertions(+), 21 deletions(-) rename Dockerfile-deb => Dockerfile.alpine (52%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70f7b2f0c..95f659d96 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ env: APP_REF: ${{ github.ref }} LD_LIBRARY_PATH: /tmp PACT_GO_LIB_DOWNLOAD_PATH: /tmp - LOG_LEVEL: info + LOG_LEVEL: debug COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: @@ -76,7 +76,7 @@ jobs: docker build \ --platform linux/amd64 \ --build-arg VERSION=${{ matrix.go-version }} \ - -f Dockerfile-deb \ + -f Dockerfile \ -t pactfoundation/pact-go-test-${{ matrix.go-version }} . - name: Unit Test (amd64 docker) if: matrix.os == 'ubuntu-22.04' diff --git a/DEVELOPER.md b/DEVELOPER.md index dc7b96608..ba6e632f3 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -14,3 +14,94 @@ The previous major version. Only bug fixes and security updates will be consider ### `master` The `2.x.x` release line. Current major version. + + +## Running locally + +### Pre-reqs + +- GoLang + +### Unit tests + +```sh +make ci_unit +``` + +### E2E Examples + +#### E2E Pre-reqs + +- Pact CLI tools (for examples). Available via + - Docker + - Ruby + - Standalone package + - +- Pact Broker + - Locally via Docker + - Hosted (OSS or PactFlow) +- Java + - For Avro example +- Protobuf Compiler + - For gRPC / Protobuf examples + +#### Running + +With Docker + +```sh +APP_SHA=foo make ci_examples +``` + +Without Docker + +```sh +APP_SHA=foo make ci_hosted_examples +``` + +You will need to use a Pact Broker to run the examples. + +You can either use an OSS Pact Broker and set the following env vars + +- `PACT_BROKER_BASE_URL` +- `PACT_BROKER_USERNAME` +- `PACT_BROKER_PASSWORD` + +Or a PactFlow Broker + +- `PACT_BROKER_BASE_URL` +- `PACT_BROKER_TOKEN` + +To use the different cli tools, use + +- `PACT_TOOL=standalone make ci_examples` + - Install it `make install-pact-ruby-standalone` + - https://github.com/pact-foundation/pact-ruby-standalone +- `PACT_TOOL=ruby make ci_examples` + - Install it `make install-pact-ruby-cli` + - Requires ruby + - https://github.com/pact-foundation/pact_broker-client +- `PACT_TOOL=docker make ci_examples` + - Requires docker + - https://github.com/pact-foundation/pact-ruby-cli +You will want to install them first + +### Docker + +Build an image from the repo + +```sh +make docker_build +``` + +Run the repo's unit test + +``` +make docker_run_test +``` + +Run the repo's examples + +``` +make docker_run_examples +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9d275b897..0408524ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM golang:alpine - -RUN apk add --no-cache curl gcc musl-dev gzip openjdk17-jre bash protoc protobuf-dev make file +ARG VERSION=latest +FROM golang:${VERSION} +RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler ruby ruby-dev ruby-bundler COPY . /go/src/github.com/pact-foundation/pact-go WORKDIR /go/src/github.com/pact-foundation/pact-go diff --git a/Dockerfile-deb b/Dockerfile.alpine similarity index 52% rename from Dockerfile-deb rename to Dockerfile.alpine index 0408524ac..98a6db74b 100644 --- a/Dockerfile-deb +++ b/Dockerfile.alpine @@ -1,7 +1,8 @@ ARG VERSION=latest -FROM golang:${VERSION} +FROM golang:${VERSION}-alpine + +RUN apk add --no-cache curl gcc musl-dev gzip openjdk17-jre bash protoc protobuf-dev make file -RUN apt-get update && apt-get install -y openjdk-17-jre file protobuf-compiler ruby ruby-dev ruby-bundler COPY . /go/src/github.com/pact-foundation/pact-go WORKDIR /go/src/github.com/pact-foundation/pact-go diff --git a/Makefile b/Makefile index f510ee398..bbb645970 100755 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ include make/config.mk TEST?=./... .DEFAULT_GOAL := ci DOCKER_HOST_HTTP?="http://host.docker.internal" -# PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli" ifeq ($(OS),Windows_NT) EXT=.exe endif @@ -11,8 +10,10 @@ endif ci:: docker deps clean bin test pact ci_unit:: deps clean bin test ci_examples:: docker pact -ci_hosted_examples:: pact +ci_hosted_examples:: run_ci_hosted_examples +run_ci_hosted_examples: + DOCKER_HOST_HTTP=$(PACT_BROKER_BASE_URL) make pact # 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. @@ -101,14 +102,12 @@ pact: clean install publish: @echo "-- 📃 Publishing pacts" - @"${PACT_BROKER_COMMAND}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod --branch ${APP_BRANCH} + @${PACT_BROKER_COMMAND} publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod --branch ${APP_BRANCH} release: echo "--- 🚀 Releasing it" "$(CURDIR)/scripts/release.sh" -# @for d in $$(go list -buildvcs=false ./... | grep -v vendor | grep -v examples); - RACE?='-race' ifdef SKIP_RACE @@ -140,11 +139,9 @@ updatedeps: go get -d -v -p 2 ./... docker_build: - docker build -f Dockerfile-deb --build-arg VERSION=1.21 -t pactfoundation/pact-go-test . + docker build -f Dockerfile --build-arg VERSION=1.21 -t pactfoundation/pact-go-test . docker_run_test: docker run \ - -e PACT_BROKER_BASE_URL \ - -e PACT_BROKER_TOKEN \ -e LOG_LEVEL=info \ -e APP_SHA=foo \ --rm \ @@ -153,8 +150,10 @@ docker_run_test: /bin/sh -c "make test" docker_run_examples: docker run \ - -e PACT_BROKER_BASE_URL \ + -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) \ -e PACT_BROKER_TOKEN \ + -e PACT_BROKER_USERNAME \ + -e PACT_BROKER_PASSWORD \ -e LOG_LEVEL=info \ -e APP_SHA=foo \ --rm \ @@ -187,7 +186,7 @@ PACT_TOOL?=docker PACT_CLI_DOCKER_VERSION?=latest PACT_CLI_VERSION?=latest PACT_CLI_STANDALONE_VERSION?=2.4.1 -PACT_CLI_DOCKER_RUN_COMMAND?=docker run --rm -v /${PWD}:/${PWD} -w ${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:${PACT_CLI_DOCKER_VERSION} +PACT_CLI_DOCKER_RUN_COMMAND?=docker run --rm -v /${PWD}:/${PWD} -w ${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST_HTTP) -e PACT_BROKER_TOKEN -e PACT_BROKER_USERNAME -e PACT_BROKER_PASSWORD pactfoundation/pact-cli:${PACT_CLI_DOCKER_VERSION} PACT_BROKER_COMMAND=pact-broker PACTFLOW_CLI_COMMAND=pactflow diff --git a/internal/native/lib.go b/internal/native/lib.go index 13ba90fa1..d4324ff52 100644 --- a/internal/native/lib.go +++ b/internal/native/lib.go @@ -4,7 +4,7 @@ package native /* #cgo darwin,arm64 LDFLAGS: -L/tmp -L/usr/local/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi #cgo darwin,amd64 LDFLAGS: -L/tmp -L/usr/local/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi -#cgo windows,amd64 LDFLAGS: -L/tmp -lpact_ffi +#cgo windows,amd64 LDFLAGS: -lpact_ffi #cgo linux,amd64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi #cgo linux,arm64 LDFLAGS: -L/tmp -L/opt/pact/lib -L/usr/local/lib -Wl,-rpath -Wl,/opt/pact/lib -Wl,-rpath -Wl,/tmp -Wl,-rpath -Wl,/usr/local/lib -lpact_ffi */ diff --git a/make/config.mk b/make/config.mk index 815d04b3b..b84bef4d2 100644 --- a/make/config.mk +++ b/make/config.mk @@ -1,5 +1,5 @@ export PATH := $(PWD)/pact/bin:$(PATH) export PATH -# export PACT_BROKER_BASE_URL=http://127.0.0.1 -# export PACT_BROKER_USERNAME=pact_workshop -# export PACT_BROKER_PASSWORD=pact_workshop \ No newline at end of file +export PACT_BROKER_BASE_URL?=http://127.0.0.1 +export PACT_BROKER_USERNAME?=pact_workshop +export PACT_BROKER_PASSWORD?=pact_workshop \ No newline at end of file From 5930cb8604ef1cda0f6f4ebbfa78aaddcbc18b58 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 7 May 2024 20:06:43 +0100 Subject: [PATCH 19/19] unset PACT_BROKER_USERNAME/PASSWORD if TOKEN is set --- .github/workflows/test.yml | 2 +- examples/consumer_v2_test.go | 6 +++--- examples/consumer_v3_test.go | 4 ++-- examples/consumer_v4_test.go | 2 +- examples/grpc/grpc_provider_test.go | 2 +- examples/protobuf-message/protobuf_provider_test.go | 2 +- examples/provider_test.go | 4 ++-- internal/native/message_server_test.go | 4 ++-- internal/native/mock_server_test.go | 2 +- internal/native/verifier_test.go | 2 +- make/config.mk | 7 +++++-- message/v4/asynchronous_message_test.go | 2 +- message/v4/synchronous_message_test.go | 2 +- 13 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95f659d96..99dbeabb0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ env: APP_REF: ${{ github.ref }} LD_LIBRARY_PATH: /tmp PACT_GO_LIB_DOWNLOAD_PATH: /tmp - LOG_LEVEL: debug + LOG_LEVEL: info COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: diff --git a/examples/consumer_v2_test.go b/examples/consumer_v2_test.go index 0c5ae0871..63b5437e6 100644 --- a/examples/consumer_v2_test.go +++ b/examples/consumer_v2_test.go @@ -35,7 +35,7 @@ var ArrayMinLike = matchers.ArrayMinLike type Map = matchers.MapMatcher func TestConsumerV2(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{ Consumer: "PactGoV2Consumer", @@ -79,7 +79,7 @@ func TestConsumerV2(t *testing.T) { } func TestConsumerV2_Match(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{ Consumer: "PactGoV2ConsumerMatch", @@ -111,7 +111,7 @@ func TestConsumerV2_Match(t *testing.T) { } func TestConsumerV2AllInOne(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") mockProvider, err := consumer.NewV2Pact(consumer.MockHTTPProviderConfig{ Consumer: "PactGoV2ConsumerAllInOne", diff --git a/examples/consumer_v3_test.go b/examples/consumer_v3_test.go index ff828aafd..f9d818197 100644 --- a/examples/consumer_v3_test.go +++ b/examples/consumer_v3_test.go @@ -30,7 +30,7 @@ var TimeGenerated = matchers.TimeGenerated var DateTimeGenerated = matchers.DateTimeGenerated func TestConsumerV3(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") mockProvider, err := consumer.NewV3Pact(consumer.MockHTTPProviderConfig{ Consumer: "PactGoV3Consumer", @@ -90,7 +90,7 @@ func TestConsumerV3(t *testing.T) { assert.NoError(t, err) } func TestMessagePact(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") provider, err := message.NewMessagePact(message.Config{ Consumer: "PactGoV3MessageConsumer", diff --git a/examples/consumer_v4_test.go b/examples/consumer_v4_test.go index cbc036193..f4483ae41 100644 --- a/examples/consumer_v4_test.go +++ b/examples/consumer_v4_test.go @@ -14,7 +14,7 @@ import ( ) func TestConsumerV4(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") mockProvider, err := consumer.NewV4Pact(consumer.MockHTTPProviderConfig{ Consumer: "PactGoV4Consumer", diff --git a/examples/grpc/grpc_provider_test.go b/examples/grpc/grpc_provider_test.go index 3ee67607a..f0dc42d4d 100644 --- a/examples/grpc/grpc_provider_test.go +++ b/examples/grpc/grpc_provider_test.go @@ -21,7 +21,7 @@ import ( func TestGrpcProvider(t *testing.T) { go startProvider() - l.SetLogLevel("TRACE") + l.SetLogLevel("INFO") verifier := provider.NewVerifier() diff --git a/examples/protobuf-message/protobuf_provider_test.go b/examples/protobuf-message/protobuf_provider_test.go index 94770cf51..bec3eb217 100644 --- a/examples/protobuf-message/protobuf_provider_test.go +++ b/examples/protobuf-message/protobuf_provider_test.go @@ -23,7 +23,7 @@ func TestPluginMessageProvider(t *testing.T) { var dir, _ = os.Getwd() var pactDir = fmt.Sprintf("%s/../pacts", dir) - err := pactlog.SetLogLevel("TRACE") + err := pactlog.SetLogLevel("INFO") assert.NoError(t, err) pactversion.CheckVersion() diff --git a/examples/provider_test.go b/examples/provider_test.go index 852cfd411..f00610264 100644 --- a/examples/provider_test.go +++ b/examples/provider_test.go @@ -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 @@ -101,7 +101,7 @@ func TestV3HTTPProvider(t *testing.T) { } func TestV3MessageProvider(t *testing.T) { - log.SetLogLevel("TRACE") + log.SetLogLevel("INFO") var user *User verifier := provider.NewVerifier() diff --git a/internal/native/message_server_test.go b/internal/native/message_server_test.go index a11527694..d67987127 100644 --- a/internal/native/message_server_test.go +++ b/internal/native/message_server_test.go @@ -349,7 +349,7 @@ func TestGetPluginAsyncMessageContentsAsBytes(t *testing.T) { func TestGrpcPluginInteraction(t *testing.T) { tmpPactFolder, err := os.MkdirTemp("", "pact-go") assert.NoError(t, err) - _ = log.SetLogLevel("TRACE") + _ = log.SetLogLevel("INFO") m := NewMessageServer("test-message-consumer", "test-message-provider") @@ -426,7 +426,7 @@ func TestGrpcPluginInteraction(t *testing.T) { func TestGrpcPluginInteraction_ErrorResponse(t *testing.T) { tmpPactFolder, err := os.MkdirTemp("", "pact-go") assert.NoError(t, err) - _ = log.SetLogLevel("TRACE") + _ = log.SetLogLevel("INFO") m := NewMessageServer("test-message-consumer", "test-message-provider") diff --git a/internal/native/mock_server_test.go b/internal/native/mock_server_test.go index bb3303acc..6ff46cac4 100644 --- a/internal/native/mock_server_test.go +++ b/internal/native/mock_server_test.go @@ -167,7 +167,7 @@ func TestHandleBasedHTTPTests(t *testing.T) { func TestPluginInteraction(t *testing.T) { tmpPactFolder, err := os.MkdirTemp("", "pact-go") assert.NoError(t, err) - _ = log.SetLogLevel("trace") + _ = log.SetLogLevel("INFO") m := NewHTTPPact("test-plugin-consumer", "test-plugin-provider") diff --git a/internal/native/verifier_test.go b/internal/native/verifier_test.go index 665b839ac..6105bc93a 100644 --- a/internal/native/verifier_test.go +++ b/internal/native/verifier_test.go @@ -29,7 +29,7 @@ func TestVerifier_Verify(t *testing.T) { "--state-change-url", "http://localhost:55827/__setup/", "--loglevel", - "trace", + "info", } res := v.Verify(args) diff --git a/make/config.mk b/make/config.mk index b84bef4d2..127121cd7 100644 --- a/make/config.mk +++ b/make/config.mk @@ -1,5 +1,8 @@ export PATH := $(PWD)/pact/bin:$(PATH) export PATH export PACT_BROKER_BASE_URL?=http://127.0.0.1 -export PACT_BROKER_USERNAME?=pact_workshop -export PACT_BROKER_PASSWORD?=pact_workshop \ No newline at end of file + +ifndef PACT_BROKER_TOKEN + export PACT_BROKER_USERNAME?=pact_workshop + export PACT_BROKER_PASSWORD?=pact_workshop +endif \ No newline at end of file diff --git a/message/v4/asynchronous_message_test.go b/message/v4/asynchronous_message_test.go index 97777f3b9..f7b1a6626 100644 --- a/message/v4/asynchronous_message_test.go +++ b/message/v4/asynchronous_message_test.go @@ -14,7 +14,7 @@ func TestAsyncTypeSystem(t *testing.T) { Provider: "asyncprovider", PactDir: "/tmp/", }) - _ = log.SetLogLevel("TRACE") + _ = log.SetLogLevel("INFO") type foo struct { Foo string `json:"foo"` diff --git a/message/v4/synchronous_message_test.go b/message/v4/synchronous_message_test.go index 3765dfca3..fc8031f23 100644 --- a/message/v4/synchronous_message_test.go +++ b/message/v4/synchronous_message_test.go @@ -16,7 +16,7 @@ func TestSyncTypeSystem(t *testing.T) { Provider: "provider", PactDir: "/tmp/", }) - _ = log.SetLogLevel("TRACE") + _ = log.SetLogLevel("INFO") dir, _ := os.Getwd() path := fmt.Sprintf("%s/../../internal/native/pact_plugin.proto", dir)