forked from pact-foundation/pact-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·165 lines (142 loc) · 5.38 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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"
PLUGIN_PACT_PROTOBUF_VERSION=0.3.15
PLUGIN_PACT_CSV_VERSION=0.0.6
PLUGIN_PACT_MATT_VERSION=0.1.1
PLUGIN_PACT_AVRO_VERSION=0.0.6
GO_VERSION?=1.22
ci:: docker deps clean bin test pact
PACT_DOWNLOAD_DIR=/tmp
ifeq ($(OS),Windows_NT)
PACT_DOWNLOAD_DIR=$$TMP
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.
fake_ci:
@CI=true \
APP_SHA=`git rev-parse --short HEAD`+`date +%s` \
APP_BRANCH=`git rev-parse --abbrev-ref HEAD` \
make ci
# same as above, but just for pact
fake_pact:
@CI=true \
APP_SHA=`git rev-parse --short HEAD`+`date +%s` \
APP_BRANCH=`git rev-parse --abbrev-ref HEAD` \
make pact
docker:
@echo "--- 🛠 Starting docker"
docker compose up -d
docker_build:
docker build -f Dockerfile --build-arg GO_VERSION=${GO_VERSION} -t pactfoundation/pact-go-test .
docker_test: docker_build
docker run \
-e LOG_LEVEL=INFO \
--rm \
pactfoundation/pact-go-test \
/bin/sh -c "make test"
docker_pact: docker_build
docker run \
-e LOG_LEVEL=INFO \
--rm \
pactfoundation/pact-go-test \
/bin/sh -c "make pact_local"
docker_test_all: docker_build
docker run \
-e LOG_LEVEL=INFO \
--rm \
pactfoundation/pact-go-test \
/bin/sh -c "make test && make pact_local"
bin:
go build -o build/pact-go
clean:
mkdir -p ./examples/pacts
rm -rf build output dist examples/pacts
deps: download_plugins
download_plugins:
@echo "--- 🐿 Installing plugins"; \
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 [ ! -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
cli:
@if [ ! -d pact/bin ]; then\
echo "--- 🐿 Installing Pact CLI dependencies"; \
curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | bash -x; \
fi
install: bin
echo "--- 🐿 Installing Pact FFI dependencies"
./build/pact-go -l DEBUG install --libDir $(PACT_DOWNLOAD_DIR)
pact: clean install docker
@echo "--- 🔨 Running Pact examples"
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/...
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/...
SKIP_PUBLISH=true go test -v -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/...
publish:
@echo "-- 📃 Publishing pacts"
@"${PACT_CLI}" publish ${PWD}/examples/pacts --consumer-app-version ${APP_SHA} --tag ${APP_BRANCH} --tag prod
release:
echo "--- 🚀 Releasing it"
"$(CURDIR)/scripts/release.sh"
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 -race -coverprofile=profile.out -covermode=atomic $$d; \
if [ $$? != 0 ]; then \
exit 1; \
fi; \
if [ -f profile.out ]; then \
cat profile.out | tail -n +2 >> coverage.txt; \
rm profile.out; \
fi; \
done; \
go tool cover -func coverage.txt
testrace:
go test -race $(TEST) $(TESTARGS)
updatedeps:
go get -d -v -p 2 ./...
.PHONY: install bin default dev test pact updatedeps clean release
PROTOC ?= $(shell which protoc)
.PHONY: protos
protos:
@echo "--- 🛠 Compiling Protobufs"
cd ./examples/grpc/routeguide && $(PROTOC) --go_out=paths=source_relative:. \
--go-grpc_out=paths=source_relative:. ./route_guide.proto
.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