-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
160 lines (134 loc) · 5.29 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
# There are four main groups of operations provided by this Makefile: build,
# clean, run and tasks.
#
# Build operations will create artefacts from code. This includes things such
# as binaries, mock files, or catalogs of CNF tests.
#
# Clean operations remove the results of the build tasks, or other files not
# considered permanent.
#
# Run operations provide shortcuts to execute built binaries in common
# configurations or with default options. They are part convenience and part
# documentation.
#
# Tasks provide shortcuts to common operations that occur frequently during
# development. This includes running configured linters and executing unit
# tests.
GO_PACKAGES=$(shell go list ./... | grep -v vendor)
# Default values
REGISTRY_LOCAL?=localhost
REGISTRY?=quay.io
CERTSUITE_IMAGE_NAME?=redhat-best-practices-for-k8s/certsuite
CERTSUITE_IMAGE_NAME_LEGACY?=testnetworkfunction/certsuite
IMAGE_TAG?=localtest
.PHONY: all clean test build
.PHONY: \
build-certsuite-tool \
build-certsuite-tool-debug \
coverage-html \
generate \
install-moq \
lint \
update-rhcos-versions \
vet
# Gets default value of $GOBIN if not explicitly set
GO_PATH=$(shell go env GOPATH)
ifeq (,$(shell go env GOBIN))
GOBIN=${GO_PATH}/bin
else
GOBIN=$(shell go env GOBIN)
endif
COMMON_GO_ARGS=-race
GIT_COMMIT=$(shell script/create-version-files.sh)
GIT_RELEASE=$(shell script/get-git-release.sh)
GIT_PREVIOUS_RELEASE=$(shell script/get-git-previous-release.sh)
CLAIM_FORMAT_VERSION=$(shell script/get-claim-version.sh)
GOLANGCI_VERSION=v1.62.2
LINKER_CERTSUITE_RELEASE_FLAGS=-X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.GitCommit=${GIT_COMMIT}
LINKER_CERTSUITE_RELEASE_FLAGS+= -X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.GitRelease=${GIT_RELEASE}
LINKER_CERTSUITE_RELEASE_FLAGS+= -X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.GitPreviousRelease=${GIT_PREVIOUS_RELEASE}
LINKER_CERTSUITE_RELEASE_FLAGS+= -X github.com/redhat-best-practices-for-k8s/certsuite/pkg/versions.ClaimFormatVersion=${CLAIM_FORMAT_VERSION}
BASH_SCRIPTS=$(shell find . -name "*.sh" -not -path "./.git/*")
PARSER_RELEASE=$(shell jq -r .parserTag version.json)
RESULTS_HTML_URL=https://raw.githubusercontent.com/redhat-best-practices-for-k8s/parser/${PARSER_RELEASE}/html/results.html
all: build
build: build-certsuite-tool
build-certsuite-tool: results-html
PATH="${PATH}:${GOBIN}" go build -ldflags "${LINKER_CERTSUITE_RELEASE_FLAGS}" -o certsuite -v cmd/certsuite/main.go
git restore internal/results/html/results.html
build-darwin-arm64: results-html
PATH="${PATH}:${GOBIN}" GOOS=darwin GOARCH=arm64 go build -ldflags "${LINKER_CERTSUITE_RELEASE_FLAGS}" -o certsuite -v cmd/certsuite/main.go
git restore internal/results/html/results.html
# Cleans up auto-generated and report files
clean:
go clean && rm -f all-releases.txt cover.out claim.json certsuite/claim.json \
certsuite/claimjson.js certsuite/certsuites_junit.xml \
certsuite/results.html jsontest-cli latest-release-tag.txt \
release-tag.txt test-out.json certsuite
# Runs configured linters
lint:
checkmake --config=.checkmake Makefile
golangci-lint run --timeout 10m0s
hadolint Dockerfile
shfmt -d script
typos
markdownlint '**/*.md'
yamllint --no-warnings .
shellcheck --format=gcc ${BASH_SCRIPTS}
# Builds and runs unit tests
test: coverage-qe
./script/create-missing-test-files.sh
go build ${COMMON_GO_ARGS} ./...
UNIT_TEST=true go test -coverprofile=cover.out.tmp ./...
coverage-html: test
cat cover.out.tmp | grep -v _moq.go >cover.out
go tool cover -html cover.out
coverage-qe: build-certsuite-tool
./certsuite generate qe-coverage-report
# Generates the test catalog in Markdown
build-catalog-md: build-certsuite-tool
./certsuite generate catalog markdown >CATALOG.md
# Builds the Certsuite binary with debug flags
build-certsuite-tool-debug: results-html
PATH="${PATH}:${GOBIN}" go build -gcflags "all=-N -l" -ldflags "${LINKER_CERTSUITE_RELEASE_FLAGS} -extldflags '-z relro -z now'" -o certsuite -v cmd/certsuite/main.go
git restore internal/results/html/results.html
install-mac-brew-tools:
brew install \
checkmake \
golangci-lint \
hadolint \
shfmt
# Installs linters
install-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_VERSION}
install-shfmt:
go install mvdan.cc/sh/v3/cmd/shfmt@latest
vet:
go vet ${GO_PACKAGES}
install-moq:
go install github.com/matryer/moq@latest
generate: install-moq
find . | grep _moq.go | xargs rm
go generate ./...
update-rhcos-versions:
./script/rhcos_versions.sh
OCT_IMAGE=quay.io/redhat-best-practices-for-k8s/oct:latest
REPO_DIR=$(shell pwd)
get-db:
mkdir -p ${REPO_DIR}/offline-db
docker pull ${OCT_IMAGE}
docker run -v ${REPO_DIR}/offline-db:/tmp/dump:Z --user $(shell id -u):$(shell id -g) --env OCT_DUMP_ONLY=true ${OCT_IMAGE}
delete-db:
rm -rf ${REPO_DIR}/offline-db
# Runs against whatever architecture the host is
build-image-local:
docker build --pull --no-cache \
-t ${REGISTRY_LOCAL}/${CERTSUITE_IMAGE_NAME}:${IMAGE_TAG} \
-t ${REGISTRY}/${CERTSUITE_IMAGE_NAME}:${IMAGE_TAG} \
-t ${REGISTRY_LOCAL}/${CERTSUITE_IMAGE_NAME_LEGACY}:${IMAGE_TAG} \
-t ${REGISTRY}/${CERTSUITE_IMAGE_NAME_LEGACY}:${IMAGE_TAG} \
-f Dockerfile .
results-html:
curl -s -O --output-dir internal/results/html ${RESULTS_HTML_URL}
check-results:
./certsuite check results