Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 3 | # Copyright 2016-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
| 17 | |
| 18 | $(if $(DEBUG),$(warning ENTER)) |
| 19 | |
| 20 | .DEFAULT_GOAL := help |
| 21 | |
Joey Armstrong | fe2bf57 | 2024-04-29 12:20:35 -0400 | [diff] [blame^] | 22 | $(if $(findstring disabled-joey,$(USER)),\ |
| 23 | $(eval USE_LF_MK := 1)) # special snowflake |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 24 | |
| 25 | ##--------------------## |
| 26 | ##---] INCLUDES [---## |
| 27 | ##--------------------## |
Joey Armstrong | fe2bf57 | 2024-04-29 12:20:35 -0400 | [diff] [blame^] | 28 | ifdef USE_LF_MK |
| 29 | include lf/include.mk |
| 30 | else |
| 31 | include lf/transition.mk |
| 32 | endif # ifdef USE_LF_MK |
| 33 | |
| 34 | |
| 35 | # TOP ?= . |
| 36 | # MAKEDIR ?= $(TOP)/makefiles |
| 37 | # |
| 38 | # $(if $(VERBOSE),$(eval export VERBOSE=$(VERBOSE))) # visible to include(s) |
| 39 | |
| 40 | ##--------------------## |
| 41 | ##---] INCLUDES [---## |
| 42 | ##--------------------## |
| 43 | # include $(MAKEDIR)/include.mk |
| 44 | # ifdef LOCAL_LINT |
| 45 | # include $(MAKEDIR)/lint/golang/sca.mk |
| 46 | # endif |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 47 | |
| 48 | # set default shell |
Joey Armstrong | fe2bf57 | 2024-04-29 12:20:35 -0400 | [diff] [blame^] | 49 | # SHELL = bash -e -o pipefail |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 50 | |
| 51 | # Variables |
| 52 | VERSION ?= $(shell cat ./VERSION) |
| 53 | |
| 54 | DOCKER_LABEL_VCS_DIRTY = false |
| 55 | ifneq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 56 | DOCKER_LABEL_VCS_DIRTY = true |
| 57 | endif |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 58 | |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 59 | ## [TODO] Refactor with repo:onf-make:makefiles/docker/include.mk |
| 60 | |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 61 | ## Docker related |
| 62 | DOCKER_EXTRA_ARGS ?= |
| 63 | DOCKER_REGISTRY ?= |
| 64 | DOCKER_REPOSITORY ?= |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 65 | DOCKER_TAG ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true) |
| 66 | DOCKER_TARGET ?= prod |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 67 | ADAPTER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-openonu-adapter-go:${DOCKER_TAG} |
| 68 | TYPE ?= minimal |
| 69 | |
| 70 | ## Docker labels. Only set ref and commit date if committed |
| 71 | DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote)) |
| 72 | DOCKER_LABEL_VCS_REF = $(shell git rev-parse HEAD) |
| 73 | DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ") |
| 74 | DOCKER_LABEL_COMMIT_DATE = $(shell git show -s --format=%cd --date=iso-strict HEAD) |
| 75 | |
| 76 | DOCKER_BUILD_ARGS ?= \ |
| 77 | ${DOCKER_EXTRA_ARGS} \ |
| 78 | --build-arg org_label_schema_version="${VERSION}" \ |
| 79 | --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \ |
| 80 | --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \ |
| 81 | --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \ |
| 82 | --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \ |
| 83 | --build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}" |
| 84 | |
| 85 | # tool containers |
David K. Bainbridge | d80007b | 2021-04-12 12:22:29 +0000 | [diff] [blame] | 86 | VOLTHA_TOOLS_VERSION ?= 2.4.0 |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 87 | |
| 88 | GO = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go |
| 89 | GO_JUNIT_REPORT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-go-junit-report go-junit-report |
Matteo Scandolo | 761f751 | 2020-11-23 15:52:40 -0800 | [diff] [blame] | 90 | GOCOVER_COBERTURA = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app/src/github.com/opencord/voltha-openonu-adapter-go -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-gocover-cobertura gocover-cobertura |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 91 | GOFMT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang gofmt |
| 92 | GOLANGCI_LINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint |
| 93 | HADOLINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-hadolint hadolint |
| 94 | |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 95 | .PHONY: docker-build local-protos local-lib-go help |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 96 | |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 97 | ## ----------------------------------------------------------------------- |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 98 | ## Local Development Helpers |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 99 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 100 | local-protos: ## Copies a local version of the voltha-protos dependency into the vendor directory |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 101 | ifdef LOCAL_PROTOS |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 102 | rm -rf vendor/github.com/opencord/voltha-protos/v5/go |
| 103 | mkdir -p vendor/github.com/opencord/voltha-protos/v5/go |
| 104 | cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/v5/go |
| 105 | rm -rf vendor/github.com/opencord/voltha-protos/v5/go/vendor |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 106 | endif |
| 107 | |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 108 | ## ----------------------------------------------------------------------- |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 109 | ## Local Development Helpers |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 110 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 111 | local-lib-go: ## Copies a local version of the voltha-lib-go dependency into the vendor directory |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 112 | ifdef LOCAL_LIB_GO |
khenaidoo | 7d3c558 | 2021-08-11 18:09:44 -0400 | [diff] [blame] | 113 | rm -rf vendor/github.com/opencord/voltha-lib-go/v7/pkg |
| 114 | mkdir -p vendor/github.com/opencord/voltha-lib-go/v7/pkg |
| 115 | cp -r ${LOCAL_LIB_GO}/pkg/* vendor/github.com/opencord/voltha-lib-go/v7/pkg/ |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 116 | endif |
| 117 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 118 | ## ----------------------------------------------------------------------- |
| 119 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 120 | build: docker-build ## Alias for 'docker build' |
| 121 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 122 | ## ----------------------------------------------------------------------- |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 123 | ## Docker targets |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 124 | ## ----------------------------------------------------------------------- |
Holger Hildebrandt | 6999fe5 | 2021-02-11 11:49:05 +0000 | [diff] [blame] | 125 | docker-build: local-protos local-lib-go ## Build openonu adapter docker image (set BUILD_PROFILED=true to also build the profiled image) |
David K. Bainbridge | 740ca85 | 2021-04-15 00:23:35 +0000 | [diff] [blame] | 126 | docker build $(DOCKER_BUILD_ARGS) --target=${DOCKER_TARGET} --build-arg CGO_PARAMETER=0 -t ${ADAPTER_IMAGENAME} -f docker/Dockerfile.openonu . |
Holger Hildebrandt | 6999fe5 | 2021-02-11 11:49:05 +0000 | [diff] [blame] | 127 | ifdef BUILD_PROFILED |
David K. Bainbridge | 740ca85 | 2021-04-15 00:23:35 +0000 | [diff] [blame] | 128 | docker build $(DOCKER_BUILD_ARGS) --target=dev --build-arg CGO_PARAMETER=1 --build-arg EXTRA_GO_BUILD_TAGS="-tags profile" -t ${ADAPTER_IMAGENAME}-profile -f docker/Dockerfile.openonu . |
| 129 | endif |
| 130 | ifdef BUILD_RACE |
| 131 | docker build $(DOCKER_BUILD_ARGS) --target=dev --build-arg CGO_PARAMETER=1 --build-arg EXTRA_GO_BUILD_TAGS="-race" -t ${ADAPTER_IMAGENAME}-rd -f docker/Dockerfile.openonu . |
Holger Hildebrandt | 6999fe5 | 2021-02-11 11:49:05 +0000 | [diff] [blame] | 132 | endif |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 133 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 134 | ## ----------------------------------------------------------------------- |
| 135 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 136 | docker-push: ## Push the docker images to an external repository |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 137 | docker push ${ADAPTER_IMAGENAME} |
Holger Hildebrandt | 6999fe5 | 2021-02-11 11:49:05 +0000 | [diff] [blame] | 138 | ifdef BUILD_PROFILED |
| 139 | docker push ${ADAPTER_IMAGENAME}-profile |
| 140 | endif |
David K. Bainbridge | 740ca85 | 2021-04-15 00:23:35 +0000 | [diff] [blame] | 141 | ifdef BUILD_RACE |
| 142 | docker push ${ADAPTER_IMAGENAME}-rd |
| 143 | endif |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 144 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 145 | ## ----------------------------------------------------------------------- |
| 146 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 147 | docker-kind-load: ## Load docker images into a KinD cluster |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 148 | @if [ "`kind get clusters | grep voltha-$(TYPE)`" = '' ]; then echo "no voltha-$(TYPE) cluster found" && exit 1; fi |
| 149 | kind load docker-image ${ADAPTER_IMAGENAME} --name=voltha-$(TYPE) --nodes $(shell kubectl get nodes --template='{{range .items}}{{.metadata.name}},{{end}}' | sed 's/,$$//') |
| 150 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 151 | ## ----------------------------------------------------------------------- |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 152 | ## lint and unit tests |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 153 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 154 | lint-dockerfile: ## Perform static analysis on Dockerfile |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 155 | @echo "Running Dockerfile lint check ..." |
| 156 | @${HADOLINT} $$(find . -name "Dockerfile.*") |
| 157 | @echo "Dockerfile lint check OK" |
| 158 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 159 | ## ----------------------------------------------------------------------- |
| 160 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 161 | lint-style: ## Perform lint style checks on source code |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 162 | @echo "Running style check..." |
| 163 | @gofmt_out="$$(${GOFMT} -l $$(find . -name '*.go' -not -path './vendor/*'))" ;\ |
| 164 | if [ ! -z "$$gofmt_out" ]; then \ |
| 165 | echo "$$gofmt_out" ;\ |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 166 | echo "Style check failed on one or more files ^, run 'go fmt -s -e -w' to fix." ;\ |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 167 | exit 1 ;\ |
| 168 | fi |
| 169 | @echo "Style check OK" |
| 170 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 171 | ## ----------------------------------------------------------------------- |
| 172 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 173 | lint-sanity: ## Perform basic code checks on source |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 174 | @echo "Running sanity check..." |
| 175 | @${GO} vet -mod=vendor ./... |
| 176 | @echo "Sanity check OK" |
| 177 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 178 | ## ----------------------------------------------------------------------- |
| 179 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 180 | lint-mod: ## Verify the Go dependencies |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 181 | $(HIDE)echo "Running dependency check..." |
| 182 | $(HIDE)$(GO) mod verify |
| 183 | $(HIDE)echo "Dependency check OK. Running vendor check..." |
| 184 | $(HIDE)git status > /dev/null |
| 185 | $(HIDE)git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Staged or modified files must be committed before running this test" && echo "`git status`" && exit 1) |
| 186 | |
Joey Armstrong | a75baed | 2023-11-30 09:48:11 -0500 | [diff] [blame] | 187 | $(HIDE)$(MAKE) --no-print-directory detect-local-edits |
| 188 | |
| 189 | $(HIDE)$(MAKE) --no-print-directory mod-update |
| 190 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 191 | $(HIDE)git status > /dev/null |
| 192 | $(HIDE)git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Modified files detected after running go mod tidy / go mod vendor" && echo "`git status`" && exit 1) |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 193 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 194 | $(MAKE) --no-print-directory detect-local-edits |
| 195 | $(HIDE)echo "Vendor check OK." |
| 196 | |
| 197 | ## --------------------------------------------------------------------- |
| 198 | ## Intent: Determine if sandbox contains locally modified files |
| 199 | ## --------------------------------------------------------------------- |
| 200 | clean-tree := git status --porcelain |
| 201 | detect-local-edits: |
| 202 | $(HIDE)[[ `$(clean-tree)` == "" ]] || (echo "ERROR: Untracked files detected, commit or remove to continue" && echo "`git status`" && exit 1) |
| 203 | |
| 204 | ## ----------------------------------------------------------------------- |
| 205 | ## ----------------------------------------------------------------------- |
Joey Armstrong | e8c091f | 2023-01-17 16:56:26 -0500 | [diff] [blame] | 206 | lint: local-lib-go lint-style lint-sanity lint-mod lint-dockerfile |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 207 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 208 | ## ----------------------------------------------------------------------- |
| 209 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 210 | results-dir := ./tests/results |
| 211 | coverage-stem := $(results-dir)/go-test-coverage |
| 212 | results-stem := $(results-dir)/go-test-results |
| 213 | |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 214 | test: lint ## Run unit tests |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 215 | |
| 216 | $(call banner-enter,Target $@) |
| 217 | @mkdir -p $(results-dir) |
| 218 | $(HIDE)$(if $(LOCAL_FIX_PERMS),chmod o+w "$(results-dir)") |
| 219 | |
| 220 | # Running remotely |
| 221 | ${GO} test -mod=vendor -v -coverprofile $(coverage-stem).out -covermode count ./... 2>&1 \ |
| 222 | | tee $(results-stem).out ;\ |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 223 | RETURN=$$? ;\ |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 224 | ${GO_JUNIT_REPORT} < $(results-stem).out > $(results-stem).xml ;\ |
| 225 | ${GOCOVER_COBERTURA} < $(coverage-stem).out > $(coverage-stem).xml ;\ |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 226 | exit $$RETURN |
| 227 | |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 228 | $(HIDE)$(if $(LOCAL_FIX_PERMS),chmod o-w "$(results-dir)") |
| 229 | $(call banner-enter,Target $@) |
| 230 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 231 | ## ----------------------------------------------------------------------- |
| 232 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 233 | sca: ## Runs static code analysis with the golangci-lint tool |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 234 | @mkdir -p ./sca-report |
| 235 | @echo "Running static code analysis..." |
ozgecanetsia | b644196 | 2021-03-10 10:58:48 +0300 | [diff] [blame] | 236 | @${GOLANGCI_LINT} run --deadline=6m --out-format junit-xml ./... | tee ./sca-report/sca-report.xml |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 237 | @echo "Static code analysis OK" |
| 238 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 239 | ## ----------------------------------------------------------------------- |
| 240 | ## ----------------------------------------------------------------------- |
Joey Armstrong | fe2bf57 | 2024-04-29 12:20:35 -0400 | [diff] [blame^] | 241 | clean :: distclean ## Removes any local filesystem artifacts generated by a build |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 242 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 243 | ## ----------------------------------------------------------------------- |
| 244 | ## ----------------------------------------------------------------------- |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 245 | distclean: ## Removes any local filesystem artifacts generated by a build or test run |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 246 | $(RM) -r ./sca-report |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 247 | |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 248 | ## ----------------------------------------------------------------------- |
| 249 | ## ----------------------------------------------------------------------- |
Joey Armstrong | a75baed | 2023-11-30 09:48:11 -0500 | [diff] [blame] | 250 | .PHONY: mod-update |
| 251 | mod-update: mod-tidy mod-vendor |
| 252 | |
| 253 | ## ----------------------------------------------------------------------- |
| 254 | ## ----------------------------------------------------------------------- |
| 255 | .PHONY: mod-tidy |
| 256 | mod-tidy : |
| 257 | $(call banner-enter,Target $@) |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 258 | ${GO} mod tidy |
Joey Armstrong | a75baed | 2023-11-30 09:48:11 -0500 | [diff] [blame] | 259 | $(call banner-leave,Target $@) |
| 260 | |
| 261 | ## ----------------------------------------------------------------------- |
| 262 | ## ----------------------------------------------------------------------- |
| 263 | .PHONY: mod-vendor |
| 264 | mod-vendor : mod-tidy |
| 265 | mod-vendor : |
| 266 | $(call banner-enter,Target $@) |
| 267 | $(if $(LOCAL_FIX_PERMS),chmod o+w $(CURDIR)) |
Holger Hildebrandt | da7758b | 2020-03-16 11:30:03 +0000 | [diff] [blame] | 268 | ${GO} mod vendor |
Joey Armstrong | a75baed | 2023-11-30 09:48:11 -0500 | [diff] [blame] | 269 | $(if $(LOCAL_FIX_PERMS),chmod o-w $(CURDIR)) |
| 270 | $(call banner-leave,Target $@) |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 271 | |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 272 | ## ----------------------------------------------------------------------- |
| 273 | ## For each makefile target, add ## <description> on the target line and it will be listed by 'make help' |
| 274 | ## ----------------------------------------------------------------------- |
| 275 | ## [TODO] Replace with simple printf(s), awk logic confused by double-colons |
| 276 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 277 | help :: ## Print help for each Makefile target |
David K. Bainbridge | ee01bc4 | 2021-04-06 17:38:20 +0000 | [diff] [blame] | 278 | @echo |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 279 | @grep --no-filename '^[[:alpha:]_-]*:.* ##' $(MAKEFILE_LIST) \ |
| 280 | | sort \ |
| 281 | | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s : %s\n", $$1, $$2};' |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 282 | @printf '\n' |
| 283 | @printf ' %-33.33s %s\n' 'mod-update' \ |
Joey Armstrong | fe2bf57 | 2024-04-29 12:20:35 -0400 | [diff] [blame^] | 284 | 'Alias for makefile targets mod-tidy + mod-vendor' |
Joey Armstrong | 1b6902d | 2024-01-02 15:43:57 -0500 | [diff] [blame] | 285 | @printf ' %-33.33s %s\n' 'mod-tidy' \ |
| 286 | 'Refresh packages, update go.mod and go.sum' |
| 287 | @printf ' %-33.33s %s\n' 'mod-vendor' \ |
| 288 | 'Update go package dependencies beneath vendor'. |
Joey Armstrong | 7f9c4df | 2022-12-26 19:39:59 -0500 | [diff] [blame] | 289 | |
| 290 | # [EOF] |