-
Notifications
You must be signed in to change notification settings - Fork 92
/
Makefile
280 lines (220 loc) · 7.44 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#
# Copyright 2020 IBM All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
base_dir := $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
go_dir := $(base_dir)/pkg
node_dir := $(base_dir)/node
java_dir := $(base_dir)/java
scenario_dir := $(base_dir)/scenario
go_bin_dir := $(shell go env GOPATH)/bin
mockery_version := 2.48.0
kernel_name := $(shell uname -s)
machine_hardware := $(shell uname -m)
ifeq ($(machine_hardware), aarch64)
machine_hardware := arm64
endif
export SOFTHSM2_CONF ?= $(base_dir)/softhsm2.conf
TMPDIR ?= /tmp
# These should match names in Docker .env file
export FABRIC_VERSION ?= 2.5
export NODEENV_VERSION ?= 2.5
export CA_VERSION ?= 1.5
.PHONY: default
default:
@echo 'No default target.'
.PHONY: build
build: build-node build-java
.PHONY: build-node
build-node:
cd '$(node_dir)' && \
npm ci && \
npm run build && \
rm -f fabric-gateway-dev.tgz && \
mv $$(npm pack) fabric-gateway-dev.tgz
.PHONY: build-java
build-java:
cd '$(java_dir)' && \
mvn -DskipTests install
.PHONY: unit-test
unit-test: generate lint unit-test-go unit-test-node unit-test-java
.PHONY: unit-test-go
unit-test-go:
cd '$(base_dir)' && \
go test -timeout 10s -race -coverprofile=cover.out '$(go_dir)/...'
.PHONY: unit-test-go-pkcs11
unit-test-go-pkcs11: setup-softhsm
cd '$(base_dir)' && \
go test -tags pkcs11 -timeout 10s -race -coverprofile=cover.out '$(go_dir)/...'
.PHONY: unit-test-node
unit-test-node: build-node
cd '$(node_dir)' && \
npm test
.PHONY: unit-test-java
unit-test-java:
cd '$(java_dir)' && \
mvn test jacoco:report
.PHONY: lint
lint: staticcheck golangci-lint
.PHONY: staticcheck
staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck -f stylish -tags=pkcs11 '$(go_dir)/...' '$(scenario_dir)/go'
.PHONY: install-golangci-lint
install-golangci-lint:
curl --fail --location --show-error --silent \
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b '$(go_bin_dir)'
$(go_bin_dir)/golangci-lint:
$(MAKE) install-golangci-lint
.PHONY: golangci-lint
golangci-lint: $(go_bin_dir)/golangci-lint
golangci-lint run
.PHONY: scan
scan: scan-go scan-node scan-java
.PHONY: scan-go
scan-go: scan-go-govulncheck scan-go-nancy scan-go-osv-scanner
.PHONY: scan-go-govulncheck
scan-go-govulncheck:
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck -tags pkcs11 '$(go_dir)/...'
.PHONY: scan-go-nancy
scan-go-nancy:
go install github.com/sonatype-nexus-community/nancy@latest
go list -json -deps '$(go_dir)/...' | nancy sleuth
.PHONY: scan-go-osv-scanner
scan-go-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
echo "GoVersionOverride = '$$(go env GOVERSION | sed 's/^go//')'" > osv-scanner.toml
osv-scanner scan --lockfile='$(base_dir)/go.mod' || [ \( $$? -gt 1 \) -a \( $$? -lt 127 \) ]
.PHONY: scan-node
scan-node: scan-node-npm-audit scan-node-osv-scanner
.PHONY: scan-node-npm-audit
scan-node-npm-audit:
cd '$(node_dir)' && \
npm install --omit=dev --package-lock-only --no-audit && \
npm audit --omit=dev
.PHONY: scan-node-osv-scanner
scan-node-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
cd '$(node_dir)' && \
npm install --omit=dev --package-lock-only --no-audit && \
npm sbom --omit=dev --package-lock-only --sbom-format cyclonedx > sbom.json && \
osv-scanner scan --sbom=sbom.json
.PHONY: scan-java
scan-java: scan-java-dependency-check scan-java-osv-scanner
.PHONY: scan-java-dependency-check
scan-java-dependency-check:
cd '$(java_dir)' && \
mvn dependency-check:check -P owasp
.PHONY: scan-java-osv-scanner
scan-java-osv-scanner:
go install github.com/google/osv-scanner/cmd/osv-scanner@latest
osv-scanner scan --lockfile='$(java_dir)/pom.xml'
.PHONY: install-mockery
install-mockery:
curl --fail --location --show-error --silent \
'https://github.com/vektra/mockery/releases/download/v$(mockery_version)/mockery_$(mockery_version)_$(kernel_name)_$(machine_hardware).tar.gz' \
| tar -C '$(go_bin_dir)' -xzf - mockery
$(go_bin_dir)/mockery:
$(MAKE) install-mockery
.PHONY: generate
generate: $(go_bin_dir)/mockery clean-generated
cd '$(base_dir)' && mockery
.PHONY: vendor-chaincode
vendor-chaincode:
cd '$(scenario_dir)/fixtures/chaincode/golang/basic' && \
GO111MODULE=on go mod vendor
cd '$(scenario_dir)/fixtures/chaincode/golang/private' && \
GO111MODULE=on go mod vendor
.PHONY: scenario-test-go
scenario-test-go: vendor-chaincode fabric-ca-client setup-softhsm
cd '$(scenario_dir)/go' && \
go test -timeout 20m -tags pkcs11 -v -args '$(scenario_dir)/features/'
.PHONY: scenario-test-go-no-hsm
scenario-test-go-no-hsm: vendor-chaincode
cd '$(scenario_dir)/go' && \
go test -timeout 20m -tags pkcs11 -v --godog.tags='~@hsm' -args '$(scenario_dir)/features/'
.PHONY: scenario-test-node
scenario-test-node: vendor-chaincode build-node fabric-ca-client setup-softhsm
cd '$(scenario_dir)/node' && \
npm ci && \
npm install @hyperledger/fabric-gateway@file:../../node/fabric-gateway-dev.tgz && \
npm test
.PHONY: scenario-test-node-no-hsm
scenario-test-node-no-hsm: vendor-chaincode build-node fabric-ca-client
cd '$(scenario_dir)/node' && \
npm ci && \
npm install @hyperledger/fabric-gateway@file:../../node/fabric-gateway-dev.tgz && \
npm run test:no-hsm
.PHONY: scenario-test-java
scenario-test-java: vendor-chaincode
cd '$(java_dir)' && \
mvn -Dmaven.javadoc.skip=true -DskipUnitTests verify
.PHONY: scenario-test
scenario-test: scenario-test-go scenario-test-node scenario-test-java
.PHONY: scenario-test-no-hsm
scenario-test-no-hsm: scenario-test-go-no-hsm scenario-test-node-no-hsm scenario-test-java
.PHONY: pull-docker-images
pull-docker-images:
for IMAGE in peer orderer baseos ccenv tools; do \
docker pull --quiet "hyperledger/fabric-$${IMAGE}:$(FABRIC_VERSION)"; \
done
docker pull --quiet 'hyperledger/fabric-nodeenv:$(NODEENV_VERSION)'
docker pull --quiet 'hyperledger/fabric-ca:$(CA_VERSION)'
.PHONY: fabric-ca-client
fabric-ca-client:
go install -tags pkcs11 github.com/hyperledger/fabric-ca/cmd/fabric-ca-client@latest
.PHONY: setup-softhsm
setup-softhsm:
mkdir -p '$(TMPDIR)/softhsm'
echo 'directories.tokendir = $(TMPDIR)/softhsm' > '$(SOFTHSM2_CONF)'
softhsm2-util --init-token --slot 0 --label 'ForFabric' --pin 98765432 --so-pin 1234 || true
.PHONY: generate-docs
generate-docs:
pip install --quiet --upgrade --requirement '$(base_dir)/requirements.txt'
cd '$(base_dir)' && TZ=UTC mkdocs build --strict
.PHONY: generate-docs-node
generate-docs-node:
cd '$(node_dir)' && \
npm ci && \
npm run generate-apidoc
.PHONY: generate-docs-java
generate-docs-java:
cd '$(java_dir)' && \
mvn javadoc:javadoc
.PHONY: test
test: shellcheck unit-test scenario-test
.PHONY: all
all: test
.PHONY: clean
clean: clean-generated clean-node clean-java clean-docs
.PHONY: clean-node
clean-node:
cd '$(node_dir)' && rm -rf node_modules
.PHONY: clean-java
clean-java:
cd '$(java_dir)' && mvn clean
.PHONY: clean-generated
clean-generated:
find '$(go_dir)' -name '*_mock_test.go' -delete
.PHONY: clean-docs
clean-docs:
rm -rf '$(base_dir)/site'
rm -rf '$(node_dir)/apidocs'
rm -rf '$(java_dir)/target/reports/apidocs'
.PHONY: shellcheck
shellcheck:
cd '$(base_dir)' && ./scripts/shellcheck.sh
.PHONY: format
format: format-go format-node format-java
.PHONY: format-go
format-go:
cd '$(base_dir)' && gofmt -l -s -w .
.PHONY: format-node
format-node:
cd '$(node_dir)' && npm run format:fix
.PHONY: format-java
format-java:
cd '$(java_dir)' && mvn spotless:apply