-
Notifications
You must be signed in to change notification settings - Fork 305
/
Makefile
77 lines (56 loc) · 2.28 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
ROOT_DIR := ../..
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
BIN_EXTENSION :=
ifeq ($(OS), windows)
BIN_EXTENSION := .exe
endif
BIN := conftest$(BIN_EXTENSION)
IMAGE := openpolicyagent/conftest
DOCKER := DOCKER_BUILDKIT=1 docker
DOCKER_PLATFORMS := linux/amd64,linux/arm64
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
## All of the directories that contain tests to be executed
## e.g. echo $(TEST_DIRS) prints tests/foo tests/bar
TEST_DIRS := $(patsubst tests/%/, tests/%, $(dir $(wildcard tests/**/.)))
#
##@ Development
#
.PHONY: build
build: ## Builds Conftest.
@go build -ldflags="-X github.com/open-policy-agent/conftest/internal/commands.version=${GIT_VERSION}"
.PHONY: test
test: ## Tests Conftest.
@go test -v ./...
.PHONY: test-examples
test-examples: build ## Runs the tests for the examples.
@bats acceptance.bats
.PHONY: test-acceptance
test-acceptance: build ## Runs the tests in the test folder.
@for testdir in $(TEST_DIRS) ; do \
cd $(CURDIR)/$$testdir && CONFTEST=$(ROOT_DIR)/$(BIN) bats test.bats || exit 1; \
done
.PHONY: test-oci
test-oci: ## Runs the OCI integration test for push and pull.
@./scripts/push-pull-e2e.sh
.PHONY: lint
lint: ## Lints Conftest.
@golangci-lint run --fix
.PHONY: all
all: lint build test test-examples test-acceptance ## Runs all linting and tests.
help:
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
#
##@ Releases
#
.PHONY: image
image: ## Builds a Docker image for Conftest.
@$(DOCKER) build . -t $(IMAGE):latest
.PHONY: examples
examples: ## Builds the examples Docker image.
@$(DOCKER) build . --target examples -t $(IMAGE):examples
.PHONY: push
push: ## Pushes the examples and Conftest image to DockerHub. Requires `TAG` parameter.
@test -n "$(TAG)" || (echo "TAG parameter not set." && exit 1)
@$(DOCKER) buildx build . --push --build-arg VERSION="$(TAG)" -t $(IMAGE):$(TAG) --platform $(DOCKER_PLATFORMS)
@$(DOCKER) buildx build . --push --build-arg VERSION="$(TAG)" -t $(IMAGE):latest --platform $(DOCKER_PLATFORMS)
@$(DOCKER) buildx build . --push --target examples -t $(IMAGE):examples --platform $(DOCKER_PLATFORMS)