Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | help: |
David Bainbridge | c4029aa | 2019-09-26 18:56:39 +0000 | [diff] [blame] | 2 | @echo "release - build binaries using cross compliing for the support architectures" |
| 3 | @echo "build - build the binary as a local executable" |
| 4 | @echo "install - build and install the binary into \$$GOPATH/bin" |
| 5 | @echo "run - runs voltctl using the command specified as \$$CMD" |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 6 | @echo "lint-style - Verify code is properly gofmt-ed" |
| 7 | @echo "lint-sanity - Verify that 'go vet' doesn't report any issues" |
| 8 | @echo "lint-mod - Verify the integrity of the 'mod' files" |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 9 | @echo "lint - run static code analysis" |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 10 | @echo "sca - Runs various SCA through golangci-lint tool" |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 11 | @echo "test - run unity tests" |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 12 | @echo "check - runs targets that should be run before a commit" |
David Bainbridge | c4029aa | 2019-09-26 18:56:39 +0000 | [diff] [blame] | 13 | @echo "clean - remove temporary and generated files" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 14 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 15 | SHELL=bash -e -o pipefail |
| 16 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 17 | VERSION=$(shell cat ./VERSION) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 18 | GITCOMMIT=$(shell git rev-parse HEAD) |
| 19 | ifeq ($(shell git ls-files --others --modified --exclude-standard 2>/dev/null | wc -l | sed -e 's/ //g'),0) |
| 20 | GITDIRTY=false |
| 21 | else |
| 22 | GITDIRTY=true |
| 23 | endif |
| 24 | GOVERSION=$(shell go version 2>&1 | sed -E 's/.*(go[0-9]+\.[0-9]+\.[0-9]+).*/\1/g') |
| 25 | HOST_OS=$(shell uname -s | tr A-Z a-z) |
| 26 | ifeq ($(shell uname -m),x86_64) |
| 27 | HOST_ARCH ?= amd64 |
| 28 | else |
| 29 | HOST_ARCH ?= $(shell uname -m) |
| 30 | endif |
| 31 | BUILDTIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 32 | |
| 33 | LDFLAGS=-ldflags \ |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 34 | "-X \"github.com/opencord/voltctl/internal/pkg/cli/version.Version=$(VERSION)\" \ |
| 35 | -X \"github.com/opencord/voltctl/internal/pkg/cli/version.VcsRef=$(GITCOMMIT)\" \ |
| 36 | -X \"github.com/opencord/voltctl/internal/pkg/cli/version.VcsDirty=$(GITDIRTY)\" \ |
| 37 | -X \"github.com/opencord/voltctl/internal/pkg/cli/version.GoVersion=$(GOVERSION)\" \ |
| 38 | -X \"github.com/opencord/voltctl/internal/pkg/cli/version.Os=$(HOST_OS)\" \ |
| 39 | -X \"github.com/opencord/voltctl/internal/pkg/cli/version.Arch=$(HOST_ARCH)\" \ |
| 40 | -X \"github.com/opencord/voltctl/internal/pkg/cli/version.BuildTime=$(BUILDTIME)\"" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 41 | |
| 42 | # Release related items |
| 43 | # Generates binaries in $RELEASE_DIR with name $RELEASE_NAME-$RELEASE_OS_ARCH |
| 44 | # Inspired by: https://github.com/kubernetes/minikube/releases |
| 45 | RELEASE_DIR ?= release |
| 46 | RELEASE_NAME ?= voltctl |
Ciprian Barbu | 72bdf89 | 2020-01-29 13:42:48 +0200 | [diff] [blame] | 47 | RELEASE_OS_ARCH ?= linux-amd64 linux-arm64 windows-amd64 darwin-amd64 |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 48 | |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 49 | # tool containers |
David K. Bainbridge | 3e83a5b | 2021-04-09 16:18:04 +0000 | [diff] [blame^] | 50 | VOLTHA_TOOLS_VERSION ?= 2.4.0 |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 51 | |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 52 | 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 |
| 53 | GO_SH = 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 sh -c |
| 54 | GO_JUNIT_REPORT = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/appecho -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-go-junit-report go-junit-report |
| 55 | GOCOVER_COBERTURA = docker run --rm --user $$(id -u):$$(id -g) -v ${CURDIR}:/app -i voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-gocover-cobertura gocover-cobertura |
| 56 | 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 -e GOGC=10 voltha/voltha-ci-tools:${VOLTHA_TOOLS_VERSION}-golangci-lint golangci-lint |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 57 | |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 58 | release: |
| 59 | @mkdir -p $(RELEASE_DIR) |
| 60 | @${GO_SH} ' \ |
| 61 | set -e -o pipefail; \ |
| 62 | for x in ${RELEASE_OS_ARCH}; do \ |
| 63 | OUT_PATH="$(RELEASE_DIR)/$(RELEASE_NAME)-$(subst -dev,_dev,$(VERSION))-$$x"; \ |
| 64 | echo "$$OUT_PATH"; \ |
| 65 | GOOS=$${x%-*} GOARCH=$${x#*-} go build -mod=vendor -v $(LDFLAGS) -o "$$OUT_PATH" cmd/voltctl/voltctl.go; \ |
| 66 | done' |
divyadesai | d331731 | 2020-04-08 09:43:11 +0000 | [diff] [blame] | 67 | ## Local Development Helpers |
| 68 | local-lib-go: |
| 69 | ifdef LOCAL_LIB_GO |
David K. Bainbridge | 1d94644 | 2021-03-19 16:45:52 +0000 | [diff] [blame] | 70 | rm -rf vendor/github.com/opencord/voltha-lib-go/v4/pkg |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 71 | mkdir -p vendor/github.com/opencord/voltha-lib-go/v4/pkg |
| 72 | cp -r ${LOCAL_LIB_GO}/pkg/* vendor/github.com/opencord/voltha-lib-go/v4/pkg/ |
divyadesai | d331731 | 2020-04-08 09:43:11 +0000 | [diff] [blame] | 73 | endif |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 74 | |
divyadesai | d331731 | 2020-04-08 09:43:11 +0000 | [diff] [blame] | 75 | build: local-lib-go |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 76 | go build -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 77 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 78 | install: |
| 79 | go install -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 80 | |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 81 | run: |
| 82 | go run -mod=vendor $(LDFLAGS) cmd/voltctl/voltctl.go $(CMD) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 83 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 84 | lint-mod: |
Scott Baker | 4a35a70 | 2019-11-26 08:17:33 -0800 | [diff] [blame] | 85 | @echo "Running dependency check..." |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 86 | @${GO} mod verify |
Scott Baker | 4a35a70 | 2019-11-26 08:17:33 -0800 | [diff] [blame] | 87 | @echo "Dependency check OK. Running vendor check..." |
| 88 | @git status > /dev/null |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 89 | @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) |
| 90 | @[[ `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) |
| 91 | ${GO} mod tidy |
| 92 | ${GO} mod vendor |
Scott Baker | 4a35a70 | 2019-11-26 08:17:33 -0800 | [diff] [blame] | 93 | @git status > /dev/null |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 94 | @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) |
| 95 | @[[ `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 | 4a35a70 | 2019-11-26 08:17:33 -0800 | [diff] [blame] | 96 | @echo "Vendor check OK." |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 97 | |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 98 | lint: lint-mod |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 99 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 100 | sca: |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 101 | @rm -rf ./sca-report |
| 102 | @mkdir -p ./sca-report |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 103 | @echo "Running static code analysis..." |
| 104 | @${GOLANGCI_LINT} run --deadline=20m --out-format junit-xml ./... | tee ./sca-report/sca-report.xml |
| 105 | @echo "" |
| 106 | @echo "Static code analysis OK" |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 107 | |
| 108 | test: |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 109 | @mkdir -p ./tests/results |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 110 | @${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 | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 111 | RETURN=$$? ;\ |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 112 | ${GO_JUNIT_REPORT} < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\ |
| 113 | ${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\ |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 114 | exit $$RETURN |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 115 | |
| 116 | view-coverage: |
David Bainbridge | 8697152 | 2019-09-26 22:09:39 +0000 | [diff] [blame] | 117 | go tool cover -html ./tests/results/go-test-coverage.out |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 118 | |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 119 | check: lint sca test |
| 120 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 121 | clean: |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 122 | rm -rf voltctl voltctl.cp release sca-report |
Kent Hagerman | 813cb90 | 2020-02-20 10:01:38 -0500 | [diff] [blame] | 123 | |
| 124 | mod-update: |
| 125 | ${GO} mod tidy |
| 126 | ${GO} mod vendor |