export SHELL = /bin/bash
export GITHUB_USER ?=
export GITHUB_TOKEN ?=
export BUILD_HARNESS_ORG ?= open-cluster-management
export BUILD_HARNESS_PROJECT ?= build-harness
export BUILD_HARNESS_BRANCH ?= master
export BUILD_HARNESS_PATH ?= $(shell until [ -d "$(BUILD_HARNESS_PROJECT)" ] || [ "`pwd`" == '/' ]; do cd ..; done; pwd)/$(BUILD_HARNESS_PROJECT)
-include $(BUILD_HARNESS_PATH)/Makefile
export BUILD_HARNESS_EXTENSIONS_ORG ?= open-cluster-management
export BUILD_HARNESS_EXTENSIONS_PROJECT ?= build-harness-extensions
export BUILD_HARNESS_EXTENSIONS_BRANCH ?= master
export BUILD_HARNESS_EXTENSIONS_PATH ?= $(shell until [ -d "$(BUILD_HARNESS_EXTENSIONS_PROJECT)" ] || [ "`pwd`" == '/' ]; do cd ..; done; pwd)/$(BUILD_HARNESS_EXTENSIONS_PROJECT)
-include $(BUILD_HARNESS_EXTENSIONS_PATH)/Makefile

.PHONY : init
## Init build-harness
init::
	@echo $(shell date)
	@curl --retry 5 --fail --silent --retry-delay 1 -H "Accept: application/vnd.github.v3.raw" https://raw.githubusercontent.com/$(BUILD_HARNESS_EXTENSIONS_ORG)/$(BUILD_HARNESS_EXTENSIONS_PROJECT)/$(BUILD_HARNESS_EXTENSIONS_BRANCH)/bin/install.sh | \
		bash -s "$(BUILD_HARNESS_ORG)" "$(BUILD_HARNESS_PROJECT)" "$(BUILD_HARNESS_BRANCH)" "$(GITHUB_USER)" "$(GITHUB_TOKEN)"
	@curl --retry 5 --fail --silent --retry-delay 1 -H "Accept: application/vnd.github.v3.raw" https://raw.githubusercontent.com/$(BUILD_HARNESS_EXTENSIONS_ORG)/$(BUILD_HARNESS_EXTENSIONS_PROJECT)/$(BUILD_HARNESS_EXTENSIONS_BRANCH)/bin/install-extensions.sh | \
		bash -s "$(BUILD_HARNESS_EXTENSIONS_ORG)" "$(BUILD_HARNESS_EXTENSIONS_PROJECT)" "$(BUILD_HARNESS_EXTENSIONS_BRANCH)" "$(GITHUB_USER)" "$(GITHUB_TOKEN)"

.PHONY : clean
## Clean build-harness
clean::
	@[ "$(BUILD_HARNESS_EXTENSIONS_PATH)" == '/' ] || \
	 [ "$(BUILD_HARNESS_EXTENSIONS_PATH)" == '.' ] || \
	   echo rm -rf $(BUILD_HARNESS_EXTENSIONS_PATH)
	@[ "$(BUILD_HARNESS_PATH)" == '/' ] || \
	 [ "$(BUILD_HARNESS_PATH)" == '.' ] || \
	   echo rm -rf $(BUILD_HARNESS_PATH)
