VERSION ?= 2.13
TARGET ?= 3scale-amp-$(VERSION)-rhel-8-candidate

GIT_BRANCH = $(shell git symbolic-ref --short HEAD)

COMPONENT = apicast
TAG ?= $(shell cut -f 2 -d ' ' source-repos)
SOURCE ?= $(TAG).tar.gz

BUILD_TYPE ?= local

$(COMPONENT)-$(SOURCE):
	rhpkg sources

build: $(COMPONENT)-$(SOURCE) $(BUILD_TYPE).repo
	docker build . --build-arg BUILD_TYPE=$(BUILD_TYPE)

local: BUILD_TYPE=local
local: build

test:
ifeq ($(BUILD_TYPE),puddle)
	rhpkg container-build --scratch --target=$(TARGET) --repo-url $(PUDDLE_REPOS)
else
	rhpkg container-build --scratch --target=$(TARGET) --signing-intent $(firstword $(SIGNING_INTENT) unsigned)
endif

clean:
	rm -rf apicast-3scale-* *.rpm
	rm -rf puddle puddle.repo

brew:
ifneq (,$(findstring private-,$(GIT_BRANCH)))
	$(error can't build from private branch $(GIT_BRANCH))
else
ifeq ($(BUILD_TYPE),puddle)
	rhpkg container-build --target=$(TARGET) --repo-url $(PUDDLE_REPOS)
else
	rhpkg container-build --target=$(TARGET)
endif
endif

smoke:
	echo "TODO..."