diff --git a/common.mk b/common.mk index 3f16252..058de66 100644 --- a/common.mk +++ b/common.mk @@ -1,4 +1,3 @@ - # Setting SHELL to bash allows bash commands to be executed by recipes. # Options are set to exit when a recipe line exits non-zero or a piped command fails. SHELL = /usr/bin/env bash -o pipefail @@ -66,26 +65,20 @@ help: ## Display this help. clean: rm -rf $(LOCALBIN) -.PHONY: mod -mod: ## Do go mod tidy, download, verify - @$(GO) mod tidy - @$(GO) mod download - @$(GO) mod verify - -## Common linting tasks -.PHONY: golangci-lint -golangci-lint: $(GOLANGCI_LINT) ## run golangci-lint - $(GOLANGCI_LINT) run -v - .PHONY: shellcheck shellcheck: ## run shellcheck - $(SHELLCHECK) $$(git ls-files | grep '.*.sh$$') + $(SHELLCHECK) $$(git ls-files '*\.sh') OSV_SCANNER_CONFIG ?= ./.osv-scanner.toml .PHONY: scan scan: $(OSV_SCANNER) ## scan for vulnerabilities $(OSV_SCANNER) scan --config $(OSV_SCANNER_CONFIG) -r . +.PHONY: addlicense +addlicense: $(ADDLICENSE) ## Add License headers containing of `license` and `comment` to files matched by `pattern`. + @test -n "$(license)" && test -n "$(comment)" && test -n "$(pattern)" \ + git ls-files '$(pattern)' | xargs -r $(ADDLICENSE) -c '$(comment)' -l '$(license)' -s=only + # Local dev environment .PHONY: setup-local-cluster setup-local-cluster: ## Set up a Kind cluster for local development if it does not exist @@ -101,6 +94,17 @@ setup-local-cluster: ## Set up a Kind cluster for local development if it does n $(KIND) create cluster --name $(KIND_CLUSTER) ;; \ esac +##@ Common golang targets +.PHONY: mod +mod: ## run go mod tidy, download, verify + @$(GO) mod tidy + @$(GO) mod download + @$(GO) mod verify + +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## run golangci-lint + $(GOLANGCI_LINT) run -v + # Install local tools TOOL_LOCK := $(BUILD_PATH)/tools.lock @@ -114,7 +118,7 @@ $(LOCALGOBIN)/%: $(LOCALGOBIN) $(TOOL_LOCK) # ocm cli (sdk v1) cannot be installed with go install because of replace directives in go.mod $(LOCALGOBIN)/ocm: $(LOCALGOBIN) $(TOOL_LOCK) - module=$$(awk "/^ocm / {print \$$2}" $(TOOL_LOCK)); \ + @module=$$(awk "/^ocm / {print \$$2}" $(TOOL_LOCK)); \ version=$$(cut -d@ -f2 <<< $$module); \ test -s $@ && grep -q "$$version" $(LOCALGOBIN)/.ocm-version 2>/dev/null || \ curl -s https://ocm.software/install.sh | VERSION_OCM=$$version bash -s -- $(LOCALGOBIN) && echo $$version > $(LOCALGOBIN)/.ocm-version diff --git a/example/Makefile b/example/Makefile index 1e264f1..df8b07f 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,5 +1,7 @@ # Include ODC common make targets -DEV_KIT_VERSION := v1.0.2 +# FIXME(user): replace with a static dev-kit release (https://github.com/opendefensecloud/dev-kit/releases) +DEV_KIT_VERSION := refs/heads/main + -include common.mk common.mk: curl --fail -sSL https://raw.githubusercontent.com/opendefensecloud/dev-kit/$(DEV_KIT_VERSION)/common.mk -o common.mk.download && \ @@ -16,3 +18,7 @@ cobra: $(COBRA) scan: echo hello + +fmt: # FIXME(user): Implement the fmt target or disable the pre-commit hook for it (flake.nix) + +lint: # FIXME(user): Implement the lint target or disable the pre-commit hook for it (flake.nix)