github.com/observiq/bindplane-agent@v1.51.0/Makefile (about) 1 # All source code and documents, used when checking for misspellings 2 ALLDOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \ 3 -type f | sort) 4 ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort ) 5 ALL_MDATAGEN_MODULES := $(shell find . -type f -name "metadata.yaml" -exec dirname {} \; | sort ) 6 7 # All source code files 8 ALL_SRC := $(shell find . -name '*.go' -o -name '*.sh' -o -name 'Dockerfile*' -type f | sort) 9 10 OUTDIR=./dist 11 GOOS ?= $(shell go env GOOS) 12 GOARCH ?= $(shell go env GOARCH) 13 14 INTEGRATION_TEST_ARGS?=-tags integration 15 16 ifeq ($(GOOS), windows) 17 EXT?=.exe 18 else 19 EXT?= 20 endif 21 22 PREVIOUS_TAG := $(shell git tag --sort=v:refname --no-contains HEAD | grep -E "[0-9]+\.[0-9]+\.[0-9]+$$" | tail -n1) 23 CURRENT_TAG := $(shell git tag --sort=v:refname --points-at HEAD | grep -E "v[0-9]+\.[0-9]+\.[0-9]+$$" | tail -n1) 24 # Version will be the tag pointing to the current commit, or the previous version tag if there is no such tag 25 VERSION ?= $(if $(CURRENT_TAG),$(CURRENT_TAG),$(PREVIOUS_TAG)) 26 27 # Build binaries for current GOOS/GOARCH by default 28 .DEFAULT_GOAL := build-binaries 29 30 # Builds just the agent for current GOOS/GOARCH pair 31 .PHONY: agent 32 agent: 33 go build -ldflags "-s -w -X github.com/observiq/bindplane-agent/internal/version.version=$(VERSION)" -o $(OUTDIR)/collector_$(GOOS)_$(GOARCH)$(EXT) ./cmd/collector 34 35 # Builds just the updater for current GOOS/GOARCH pair 36 .PHONY: updater 37 updater: 38 cd ./updater/; go build -ldflags "-s -w -X github.com/observiq/bindplane-agent/internal/version.version=$(VERSION)" -o ../$(OUTDIR)/updater_$(GOOS)_$(GOARCH)$(EXT) ./cmd/updater 39 40 # Builds the updater + agent for current GOOS/GOARCH pair 41 .PHONY: build-binaries 42 build-binaries: agent updater 43 44 .PHONY: build-all 45 build-all: build-linux build-darwin build-windows 46 47 .PHONY: build-linux 48 build-linux: build-linux-amd64 build-linux-arm64 build-linux-arm build-linux-ppc64 build-linux-ppc64le 49 50 .PHONY: build-darwin 51 build-darwin: build-darwin-amd64 build-darwin-arm64 52 53 .PHONY: build-windows 54 build-windows: build-windows-amd64 55 56 .PHONY: build-linux-ppc64 57 build-linux-ppc64: 58 GOOS=linux GOARCH=ppc64 $(MAKE) build-binaries -j2 59 60 .PHONY: build-linux-ppc64le 61 build-linux-ppc64le: 62 GOOS=linux GOARCH=ppc64le $(MAKE) build-binaries -j2 63 64 .PHONY: build-linux-amd64 65 build-linux-amd64: 66 GOOS=linux GOARCH=amd64 $(MAKE) build-binaries -j2 67 68 .PHONY: build-linux-arm64 69 build-linux-arm64: 70 GOOS=linux GOARCH=arm64 $(MAKE) build-binaries -j2 71 72 .PHONY: build-linux-arm 73 build-linux-arm: 74 GOOS=linux GOARCH=arm $(MAKE) build-binaries -j2 75 76 .PHONY: build-darwin-amd64 77 build-darwin-amd64: 78 GOOS=darwin GOARCH=amd64 $(MAKE) build-binaries -j2 79 80 .PHONY: build-darwin-arm64 81 build-darwin-arm64: 82 GOOS=darwin GOARCH=arm64 $(MAKE) build-binaries -j2 83 84 .PHONY: build-windows-amd64 85 build-windows-amd64: 86 GOOS=windows GOARCH=amd64 $(MAKE) build-binaries -j2 87 88 # tool-related commands 89 .PHONY: install-tools 90 install-tools: 91 go install github.com/client9/misspell/cmd/misspell@v0.3.4 92 go install github.com/google/addlicense@v1.1.1 93 go install github.com/mgechev/revive@v1.3.7 94 go install github.com/open-telemetry/opentelemetry-collector-contrib/cmd/mdatagen@v0.96.0 95 go install github.com/securego/gosec/v2/cmd/gosec@v2.18.2 96 # update cosign in release.yml when updating this version 97 # update cosign in docs/verify-signature.md when updating this version 98 go install github.com/sigstore/cosign/cmd/cosign@v1.13.1 99 go install github.com/uw-labs/lichen@v0.1.7 100 go install github.com/vektra/mockery/v2@v2.42.0 101 go install golang.org/x/tools/cmd/goimports@latest 102 go install github.com/goreleaser/goreleaser@v1.22.1 103 104 .PHONY: lint 105 lint: 106 revive -config revive/config.toml -formatter friendly ./... 107 108 .PHONY: misspell 109 misspell: 110 misspell -error $(ALLDOC) 111 112 .PHONY: misspell-fix 113 misspell-fix: 114 misspell -w $(ALLDOC) 115 116 .PHONY: test 117 test: 118 $(MAKE) for-all CMD="go test -race ./..." 119 120 .PHONY: test-with-cover 121 test-with-cover: 122 $(MAKE) for-all CMD="go test -coverprofile=cover.out ./..." 123 $(MAKE) for-all CMD="go tool cover -html=cover.out -o cover.html" 124 125 .PHONY: test-updater-integration 126 test-updater-integration: 127 cd updater; go test $(INTEGRATION_TEST_ARGS) -race ./... 128 129 .PHONY: bench 130 bench: 131 $(MAKE) for-all CMD="go test -benchmem -run=^$$ -bench ^* ./..." 132 133 .PHONY: check-fmt 134 check-fmt: 135 goimports -d ./ | diff -u /dev/null - 136 137 .PHONY: fmt 138 fmt: 139 goimports -w . 140 141 .PHONY: tidy 142 tidy: 143 $(MAKE) for-all CMD="go mod tidy -compat=1.21" 144 145 .PHONY: gosec 146 gosec: 147 gosec \ 148 -exclude-dir=updater \ 149 -exclude-dir=receiver/sapnetweaverreceiver \ 150 -exclude-dir=extension/bindplaneextension \ 151 ./... 152 # exclude the testdata dir; it contains a go program for testing. 153 cd updater; gosec -exclude-dir internal/service/testdata ./... 154 cd extension/bindplaneextension; gosec ./... 155 156 # This target performs all checks that CI will do (excluding the build itself) 157 .PHONY: ci-checks 158 ci-checks: check-fmt check-license misspell lint gosec test 159 160 # This target checks that license copyright header is on every source file 161 .PHONY: check-license 162 check-license: 163 @ADDLICENSEOUT=`addlicense -check $(ALL_SRC) 2>&1`; \ 164 if [ "$$ADDLICENSEOUT" ]; then \ 165 echo "addlicense FAILED => add License errors:\n"; \ 166 echo "$$ADDLICENSEOUT\n"; \ 167 echo "Use 'make add-license' to fix this."; \ 168 exit 1; \ 169 else \ 170 echo "Check License finished successfully"; \ 171 fi 172 173 # This target adds a license copyright header is on every source file that is missing one 174 .PHONY: add-license 175 add-license: 176 @ADDLICENSEOUT=`addlicense -y "" -c "observIQ, Inc." $(ALL_SRC) 2>&1`; \ 177 if [ "$$ADDLICENSEOUT" ]; then \ 178 echo "addlicense FAILED => add License errors:\n"; \ 179 echo "$$ADDLICENSEOUT\n"; \ 180 exit 1; \ 181 else \ 182 echo "Add License finished successfully"; \ 183 fi 184 185 # update-otel attempts to update otel dependencies in go.mods, 186 # and update the otel versions in the docs. 187 # Usage: make update-otel OTEL_VERSION=vx.x.x CONTRIB_VERSION=vx.x.x PDATA_VERSION=vx.x.x-rcx 188 .PHONY: update-otel 189 update-otel: 190 ./scripts/update-otel.sh "$(OTEL_VERSION)" "$(CONTRIB_VERSION)" "$(PDATA_VERSION)" 191 ./scripts/update-docs.sh "$(OTEL_VERSION)" "$(CONTRIB_VERSION)" 192 $(MAKE) tidy 193 194 # update-modules updates all submodules to be the new version. 195 # Usage: make update-modules NEW_VERSION=vx.x.x 196 .PHONY: update-modules 197 update-modules: 198 ./scripts/update-module-version.sh "$(NEW_VERSION)" 199 $(MAKE) tidy 200 201 # Downloads and setups dependencies that are packaged with binary 202 .PHONY: release-prep 203 release-prep: 204 @rm -rf release_deps 205 @mkdir release_deps 206 @echo 'v$(CURR_VERSION)' > release_deps/VERSION.txt 207 ./buildscripts/download-dependencies.sh release_deps 208 @cp -r ./plugins release_deps/ 209 @cp config/example.yaml release_deps/config.yaml 210 @cp config/logging.yaml release_deps/logging.yaml 211 @cp service/com.observiq.collector.plist release_deps/com.observiq.collector.plist 212 @jq ".files[] | select(.service != null)" windows/wix.json >> release_deps/windows_service.json 213 @cp service/observiq-otel-collector.service release_deps/observiq-otel-collector.service 214 @cp service/observiq-otel-collector release_deps/observiq-otel-collector 215 @cp -r ./service/sysconfig release_deps/ 216 217 # Build and sign, skip release and ignore dirty git tree 218 .PHONY: release-test 219 release-test: 220 GORELEASER_CURRENT_TAG=$(shell git tag | grep -E -i '^v[0-9]+\.[0-9]+\.[0-9]+' | sort -r --version-sort | head -n1) goreleaser release --parallelism 4 --skip=publish --skip=validate --skip=sign --clean --snapshot 221 222 .PHONY: for-all 223 for-all: 224 @echo "running $${CMD} in root" 225 @$${CMD} 226 @set -e; for dir in $(ALL_MODULES); do \ 227 (cd "$${dir}" && \ 228 echo "running $${CMD} in $${dir}" && \ 229 $${CMD} ); \ 230 done 231 232 # Release a new version of the agent. This will also tag all submodules 233 .PHONY: release 234 release: 235 @if [ -z "$(version)" ]; then \ 236 echo "version was not set"; \ 237 exit 1; \ 238 fi 239 240 @if ! [[ "$(version)" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$$ ]]; then \ 241 echo "version $(version) is invalid semver"; \ 242 exit 1; \ 243 fi 244 245 @git tag $(version) 246 @git push --tags 247 248 @set -e; for dir in $(ALL_MODULES); do \ 249 if [ $${dir} == \. ]; then \ 250 continue; \ 251 else \ 252 echo "$${dir}" | sed -e "s+^./++" -e 's+$$+/$(version)+' | awk '{print $1}' | git tag $$(cat) ; \ 253 fi; \ 254 done 255 256 @git push --tags 257 258 .PHONY: clean 259 clean: 260 rm -rf $(OUTDIR) 261 262 .PHONY: scan-licenses 263 scan-licenses: 264 lichen --config=./license.yaml $$(find dist/collector_* dist/updater_*) 265 266 .PHONY: generate 267 generate: 268 $(MAKE) for-all CMD="go generate ./..." 269 270 .PHONY: create-plugin-docs 271 create-plugin-docs: 272 cd cmd/plugindocgen; go run .