Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions common.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
8 changes: 7 additions & 1 deletion example/Makefile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand All @@ -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)
Loading