Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 1 | # -*- makefile -*- |
| 2 | # ----------------------------------------------------------------------- |
| 3 | # Copyright 2016-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [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 | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 16 | # ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 17 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 18 | .DEFAULT_GOAL := help |
| 19 | |
| 20 | ##-------------------## |
| 21 | ##---] GLOBALS [---## |
| 22 | ##-------------------## |
| 23 | TOP ?= . |
| 24 | MAKEDIR ?= $(TOP)/makefiles |
| 25 | |
| 26 | NO-LINT-MAKEFILE := true # cleanup needed |
| 27 | NO-LINT-PYTHON := true # cleanup needed |
| 28 | NO-LINT-SHELL := true # cleanup needed |
| 29 | |
| 30 | export SHELL := bash -e -o pipefail |
| 31 | |
| 32 | ##--------------------## |
| 33 | ##---] INCLUDES [---## |
| 34 | ##--------------------## |
| 35 | include $(MAKEDIR)/include.mk |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 36 | |
| 37 | # Variables |
| 38 | VERSION ?= $(shell cat ./VERSION) |
| 39 | |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 40 | # tool containers |
David K. Bainbridge | c50d88c | 2021-04-08 15:47:03 +0000 | [diff] [blame] | 41 | VOLTHA_TOOLS_VERSION ?= 2.4.0 |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 42 | |
Kent Hagerman | 08d15ab | 2020-02-14 14:54:52 -0500 | [diff] [blame] | 43 | GO = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golang go |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 44 | 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 |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 45 | GOCOVER_COBERTURA = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app/src/github.com/opencord/voltha-lib-go/v7 -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-gocover-cobertura gocover-cobertura |
Kent Hagerman | 08d15ab | 2020-02-14 14:54:52 -0500 | [diff] [blame] | 46 | GOLANGCI_LINT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app $(shell test -t 0 && echo "-it") -v gocache:/.cache -v gocache-${VOLTHA_TOOLS_VERSION}:/go/pkg voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 47 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 48 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 49 | ## ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 50 | ## Local Development Helpers |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 51 | ## ----------------------------------------------------------------------- |
| 52 | .PHONY: local-protos |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 53 | local-protos: |
| 54 | @mkdir -p python/local_imports |
| 55 | ifdef LOCAL_PROTOS |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 56 | $(RM) -r vendor/github.com/opencord/voltha-protos |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 57 | mkdir -p vendor/github.com/opencord/voltha-protos/v5/go |
| 58 | cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/v5/go |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 59 | $(RM) -r python/local_imports/voltha-protos |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 60 | mkdir -p python/local_imports/voltha-protos/dist |
Scott Baker | f1b096c | 2019-11-01 12:36:30 -0700 | [diff] [blame] | 61 | cp ${LOCAL_PROTOS}/dist/*.tar.gz python/local_imports/voltha-protos/dist/ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 62 | endif |
| 63 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 64 | ## ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 65 | ## build the library |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 66 | ## ----------------------------------------------------------------------- |
Scott Baker | f1b096c | 2019-11-01 12:36:30 -0700 | [diff] [blame] | 67 | build: local-protos |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 68 | ## ${GO} build -mod=vendor ./... |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 69 | ${GO} build -mod=vendor ./... |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 70 | |
| 71 | ## lint and unit tests |
| 72 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 73 | ## ----------------------------------------------------------------------- |
| 74 | ## ----------------------------------------------------------------------- |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 75 | lint-mod: |
| 76 | @echo "Running dependency check..." |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 77 | @${GO} mod verify |
Scott Baker | a36b498 | 2019-11-26 08:09:23 -0800 | [diff] [blame] | 78 | @echo "Dependency check OK. Running vendor check..." |
| 79 | @git status > /dev/null |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 80 | @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Staged or modified files must be committed before running this test" && git status -- go.mod go.sum vendor && exit 1) |
| 81 | @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files must be cleaned up before running this test" && git status -- go.mod go.sum vendor && exit 1) |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 82 | ${GO} mod tidy |
| 83 | ${GO} mod vendor |
Scott Baker | a36b498 | 2019-11-26 08:09:23 -0800 | [diff] [blame] | 84 | @git status > /dev/null |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 85 | @git diff-index --quiet HEAD -- go.mod go.sum vendor || (echo "ERROR: Modified files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1) |
| 86 | @[[ `git ls-files --exclude-standard --others go.mod go.sum vendor` == "" ]] || (echo "ERROR: Untracked files detected after running go mod tidy / go mod vendor" && git status -- go.mod go.sum vendor && git checkout -- go.mod go.sum vendor && exit 1) |
Scott Baker | a36b498 | 2019-11-26 08:09:23 -0800 | [diff] [blame] | 87 | @echo "Vendor check OK." |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 88 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 89 | ## ----------------------------------------------------------------------- |
| 90 | ## ----------------------------------------------------------------------- |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 91 | lint: lint-mod |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 92 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 93 | ## ----------------------------------------------------------------------- |
| 94 | ## ----------------------------------------------------------------------- |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 95 | sca: |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 96 | @$(RM) -r ./sca-report |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 97 | @mkdir -p ./sca-report |
Kent Hagerman | 3da1fd0 | 2020-02-26 10:54:07 -0500 | [diff] [blame] | 98 | @echo "Running static code analysis..." |
| 99 | @${GOLANGCI_LINT} run --deadline=4m --out-format junit-xml ./... | tee ./sca-report/sca-report.xml |
| 100 | @echo "" |
| 101 | @echo "Static code analysis OK" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 102 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 103 | ## ----------------------------------------------------------------------- |
| 104 | ## ----------------------------------------------------------------------- |
Matteo Scandolo | d58eaef | 2020-03-30 12:30:02 -0700 | [diff] [blame] | 105 | test: local-protos |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 106 | @mkdir -p ./tests/results |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 107 | @${GO} test -mod=vendor -v -coverprofile ./tests/results/go-test-coverage.out -covermode count ./... 2>&1 | tee ./tests/results/go-test-results.out ;\ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 108 | RETURN=$$? ;\ |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 109 | ${GO_JUNIT_REPORT} < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 110 | ${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 111 | exit $$RETURN |
| 112 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 113 | ## ----------------------------------------------------------------------- |
| 114 | ## ----------------------------------------------------------------------- |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 115 | clean: distclean |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 116 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 117 | ## ----------------------------------------------------------------------- |
| 118 | ## ----------------------------------------------------------------------- |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 119 | distclean sterile: |
| 120 | $(RM) -r ./sca-report ./tests |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 121 | |
Joey Armstrong | b085c50 | 2023-01-17 13:56:24 -0500 | [diff] [blame] | 122 | ## ----------------------------------------------------------------------- |
| 123 | ## ----------------------------------------------------------------------- |
Kent Hagerman | fac11d4 | 2020-01-28 12:18:55 -0500 | [diff] [blame] | 124 | mod-update: |
| 125 | ${GO} mod tidy |
| 126 | ${GO} mod vendor |
Joey Armstrong | 26245a3 | 2022-12-17 21:49:06 -0500 | [diff] [blame] | 127 | |
| 128 | # [EOF] |